1require 'compass'
2# require 'sassy-math'
3
4# This tells Compass what your Compass extension is called, and where to find
5#  its files
6# Replace 'extension' with the name of your extension. Spaces allowed.
7extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8Compass::Frameworks.register('modular-scale', :path => extension_path)
9
10# Version and date of version for your Compass extension.
11# Replace Extension with the name of your extension
12#  Letters, numbers, and underscores only
13#  Version is a number. If a version contains alphas, it will be created as
14#    a prerelease version
15#  Date is in the form of YYYY-MM-DD
16module ModularScale
17  VERSION = "1.0.6"
18  DATE = "2012-08-13"
19end
20
21# This is where any custom SassScript should be placed. The functions will be
22#  available on require of your extension without the need for users to import
23#  any partials. Uncomment below.
24
25# Modular Scale Sass Script
26module Sass::Script
27  class Number < Literal
28    # Comparison
29    def <=>(other)
30      value <=> other.value
31    end
32  end
33end
34
35module Sass::Script::Functions
36  # Modular Scale
37  def double_octave
38    value = 4 / 1.0
39    Sass::Script::Number.new(value)
40  end
41  def major_twelfth
42    value = 3 / 1.0
43    Sass::Script::Number.new(value)
44  end
45  def major_eleventh
46    value = 8 / 3.0
47    Sass::Script::Number.new(value)
48  end
49  def major_tenth
50    value = 5 / 2.0
51    Sass::Script::Number.new(value)
52  end
53  def octave
54    value = 2 / 1.0
55    Sass::Script::Number.new(value)
56  end
57  def major_seventh
58    value = 15 / 8.0
59    Sass::Script::Number.new(value)
60  end
61  def minor_seventh
62    value = 16 /9.0
63    Sass::Script::Number.new(value)
64  end
65  def major_sixth
66    value = 5 / 3.0
67    Sass::Script::Number.new(value)
68  end
69  def minor_sixth
70    value = 8 / 5.0
71    Sass::Script::Number.new(value)
72  end
73  def fifth
74    value = 3 / 2.0
75    Sass::Script::Number.new(value)
76  end
77  def augmented_fourth
78    value = Math.sqrt(2) / 1.0
79    Sass::Script::Number.new(value)
80  end
81  def fourth
82    value = 4 / 3.0
83    Sass::Script::Number.new(value)
84  end
85  def major_third
86    value = 5 / 4.0
87    Sass::Script::Number.new(value)
88  end
89  def minor_third
90    value = 6 / 5.0
91    Sass::Script::Number.new(value)
92  end
93  def major_second
94    value = 9 / 8.0
95    Sass::Script::Number.new(value)
96  end
97  def minor_second
98    value = 16 / 15.0
99    Sass::Script::Number.new(value)
100  end
101
102  # Lists
103  def sort_list(list)
104    sep = list.separator if list.is_a?(Sass::Script::List)
105    list = list.to_a.sort
106    Sass::Script::List.new(list, sep)
107  end
108  def reverse_list(list)
109    sep = list.separator if list.is_a?(Sass::Script::List)
110    list = list.to_a.reverse
111    Sass::Script::List.new(list, sep)
112  end
113  def trim_list(list, threshold, ascending)
114    # remove list items above or below a threshold
115    sep = list.separator if list.is_a?(Sass::Script::List)
116    list = list.to_a
117    if ascending.value
118      list = list.delete_if {
119        |x| x.value <= threshold.value
120      }
121    else
122      list = list.delete_if {
123        |x| x.value >= threshold.value
124      }
125    end
126    Sass::Script::List.new(list, sep)
127  end
128end
129