compass-core 1.0.0.alpha.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/VERSION +1 -0
  4. data/data/caniuse.json +1 -0
  5. data/data/caniuse_extras/css-placeholder.json +171 -0
  6. data/lib/compass-core.rb +1 -0
  7. data/lib/compass/browser_support.rb +62 -0
  8. data/lib/compass/configuration.rb +168 -0
  9. data/lib/compass/configuration/data.rb +178 -0
  10. data/lib/compass/configuration/defaults.rb +197 -0
  11. data/lib/compass/configuration/inheritance.rb +304 -0
  12. data/lib/compass/configuration/paths.rb +19 -0
  13. data/lib/compass/core.rb +64 -0
  14. data/lib/compass/core/caniuse.rb +282 -0
  15. data/lib/compass/core/sass_extensions.rb +10 -0
  16. data/lib/compass/core/sass_extensions/functions.rb +39 -0
  17. data/lib/compass/core/sass_extensions/functions/colors.rb +67 -0
  18. data/lib/compass/core/sass_extensions/functions/configuration.rb +162 -0
  19. data/lib/compass/core/sass_extensions/functions/constants.rb +74 -0
  20. data/lib/compass/core/sass_extensions/functions/cross_browser_support.rb +269 -0
  21. data/lib/compass/core/sass_extensions/functions/display.rb +32 -0
  22. data/lib/compass/core/sass_extensions/functions/enumerate.rb +7 -0
  23. data/lib/compass/core/sass_extensions/functions/env.rb +60 -0
  24. data/lib/compass/core/sass_extensions/functions/font_files.rb +41 -0
  25. data/lib/compass/core/sass_extensions/functions/gradient_support.rb +616 -0
  26. data/lib/compass/core/sass_extensions/functions/image_size.rb +117 -0
  27. data/lib/compass/core/sass_extensions/functions/inline_image.rb +64 -0
  28. data/lib/compass/core/sass_extensions/functions/lists.rb +101 -0
  29. data/lib/compass/core/sass_extensions/functions/math.rb +92 -0
  30. data/lib/compass/core/sass_extensions/functions/selectors.rb +64 -0
  31. data/lib/compass/core/sass_extensions/functions/urls.rb +297 -0
  32. data/lib/compass/core/sass_extensions/monkey_patches.rb +3 -0
  33. data/lib/compass/core/sass_extensions/monkey_patches/browser_support.rb +118 -0
  34. data/lib/compass/core/sass_extensions/monkey_patches/traversal.rb +23 -0
  35. data/lib/compass/core/version.rb +5 -0
  36. data/lib/compass/error.rb +5 -0
  37. data/stylesheets/_compass.scss +3 -0
  38. data/stylesheets/_lemonade.scss +38 -0
  39. data/stylesheets/compass/_configuration.scss +54 -0
  40. data/stylesheets/compass/_css3.scss +21 -0
  41. data/stylesheets/compass/_layout.scss +3 -0
  42. data/stylesheets/compass/_reset-legacy.scss +3 -0
  43. data/stylesheets/compass/_reset.scss +3 -0
  44. data/stylesheets/compass/_support.scss +441 -0
  45. data/stylesheets/compass/_typography.scss +4 -0
  46. data/stylesheets/compass/_utilities.scss +9 -0
  47. data/stylesheets/compass/css3/_animation.scss +122 -0
  48. data/stylesheets/compass/css3/_appearance.scss +17 -0
  49. data/stylesheets/compass/css3/_background-clip.scss +35 -0
  50. data/stylesheets/compass/css3/_background-origin.scss +37 -0
  51. data/stylesheets/compass/css3/_background-size.scss +19 -0
  52. data/stylesheets/compass/css3/_border-radius.scss +107 -0
  53. data/stylesheets/compass/css3/_box-shadow.scss +88 -0
  54. data/stylesheets/compass/css3/_box-sizing.scss +15 -0
  55. data/stylesheets/compass/css3/_box.scss +85 -0
  56. data/stylesheets/compass/css3/_columns.scss +210 -0
  57. data/stylesheets/compass/css3/_deprecated-support.scss +272 -0
  58. data/stylesheets/compass/css3/_filter.scss +50 -0
  59. data/stylesheets/compass/css3/_flexbox.scss +156 -0
  60. data/stylesheets/compass/css3/_font-face.scss +48 -0
  61. data/stylesheets/compass/css3/_hyphenation.scss +71 -0
  62. data/stylesheets/compass/css3/_images.scss +139 -0
  63. data/stylesheets/compass/css3/_inline-block.scss +31 -0
  64. data/stylesheets/compass/css3/_opacity.scss +23 -0
  65. data/stylesheets/compass/css3/_pie.scss +1 -0
  66. data/stylesheets/compass/css3/_regions.scss +27 -0
  67. data/stylesheets/compass/css3/_selection.scss +59 -0
  68. data/stylesheets/compass/css3/_shared.scss +5 -0
  69. data/stylesheets/compass/css3/_text-shadow.scss +82 -0
  70. data/stylesheets/compass/css3/_transform.scss +590 -0
  71. data/stylesheets/compass/css3/_transition.scss +171 -0
  72. data/stylesheets/compass/css3/_user-interface.scss +71 -0
  73. data/stylesheets/compass/layout/_grid-background.scss +178 -0
  74. data/stylesheets/compass/layout/_sticky-footer.scss +23 -0
  75. data/stylesheets/compass/layout/_stretching.scss +24 -0
  76. data/stylesheets/compass/reset/_utilities-legacy.scss +135 -0
  77. data/stylesheets/compass/reset/_utilities.scss +142 -0
  78. data/stylesheets/compass/typography/_links.scss +3 -0
  79. data/stylesheets/compass/typography/_lists.scss +4 -0
  80. data/stylesheets/compass/typography/_text.scss +4 -0
  81. data/stylesheets/compass/typography/_units.scss +152 -0
  82. data/stylesheets/compass/typography/_vertical_rhythm.scss +300 -0
  83. data/stylesheets/compass/typography/links/_hover-link.scss +5 -0
  84. data/stylesheets/compass/typography/links/_link-colors.scss +28 -0
  85. data/stylesheets/compass/typography/links/_unstyled-link.scss +7 -0
  86. data/stylesheets/compass/typography/lists/_bullets.scss +34 -0
  87. data/stylesheets/compass/typography/lists/_horizontal-list.scss +63 -0
  88. data/stylesheets/compass/typography/lists/_inline-block-list.scss +50 -0
  89. data/stylesheets/compass/typography/lists/_inline-list.scss +47 -0
  90. data/stylesheets/compass/typography/text/_ellipsis.scss +25 -0
  91. data/stylesheets/compass/typography/text/_force-wrap.scss +12 -0
  92. data/stylesheets/compass/typography/text/_nowrap.scss +2 -0
  93. data/stylesheets/compass/typography/text/_replacement.scss +68 -0
  94. data/stylesheets/compass/utilities/_color.scss +1 -0
  95. data/stylesheets/compass/utilities/_general.scss +6 -0
  96. data/stylesheets/compass/utilities/_links.scss +5 -0
  97. data/stylesheets/compass/utilities/_lists.scss +6 -0
  98. data/stylesheets/compass/utilities/_print.scss +17 -0
  99. data/stylesheets/compass/utilities/_sass.scss +2 -0
  100. data/stylesheets/compass/utilities/_sprites.scss +2 -0
  101. data/stylesheets/compass/utilities/_tables.scss +3 -0
  102. data/stylesheets/compass/utilities/_text.scss +5 -0
  103. data/stylesheets/compass/utilities/color/_brightness.scss +12 -0
  104. data/stylesheets/compass/utilities/color/_contrast.scss +52 -0
  105. data/stylesheets/compass/utilities/general/_clearfix.scss +44 -0
  106. data/stylesheets/compass/utilities/general/_float.scss +38 -0
  107. data/stylesheets/compass/utilities/general/_hacks.scss +65 -0
  108. data/stylesheets/compass/utilities/general/_min.scss +16 -0
  109. data/stylesheets/compass/utilities/general/_reset.scss +2 -0
  110. data/stylesheets/compass/utilities/general/_tabs.scss +1 -0
  111. data/stylesheets/compass/utilities/general/_tag-cloud.scss +18 -0
  112. data/stylesheets/compass/utilities/links/_hover-link.scss +3 -0
  113. data/stylesheets/compass/utilities/links/_link-colors.scss +3 -0
  114. data/stylesheets/compass/utilities/links/_unstyled-link.scss +3 -0
  115. data/stylesheets/compass/utilities/lists/_bullets.scss +3 -0
  116. data/stylesheets/compass/utilities/lists/_horizontal-list.scss +3 -0
  117. data/stylesheets/compass/utilities/lists/_inline-block-list.scss +3 -0
  118. data/stylesheets/compass/utilities/lists/_inline-list.scss +3 -0
  119. data/stylesheets/compass/utilities/sass/_lists.scss +16 -0
  120. data/stylesheets/compass/utilities/sass/_maps.scss +19 -0
  121. data/stylesheets/compass/utilities/sprites/_base.scss +92 -0
  122. data/stylesheets/compass/utilities/sprites/_sprite-img.scss +81 -0
  123. data/stylesheets/compass/utilities/tables/_alternating-rows-and-columns.scss +22 -0
  124. data/stylesheets/compass/utilities/tables/_borders.scss +38 -0
  125. data/stylesheets/compass/utilities/tables/_scaffolding.scss +9 -0
  126. data/stylesheets/compass/utilities/text/_ellipsis.scss +3 -0
  127. data/stylesheets/compass/utilities/text/_nowrap.scss +3 -0
  128. data/stylesheets/compass/utilities/text/_replacement.scss +3 -0
  129. data/templates/ellipsis/ellipsis.sass +9 -0
  130. data/templates/ellipsis/manifest.rb +27 -0
  131. data/templates/ellipsis/xml/ellipsis.xml +14 -0
  132. data/templates/extension/manifest.rb +26 -0
  133. data/templates/extension/stylesheets/main.sass +1 -0
  134. data/templates/extension/templates/project/manifest.rb +2 -0
  135. data/templates/extension/templates/project/screen.sass +2 -0
  136. data/templates/project/USAGE.markdown +32 -0
  137. data/templates/project/ie.sass +6 -0
  138. data/templates/project/manifest.rb +4 -0
  139. data/templates/project/print.sass +6 -0
  140. data/templates/project/screen.sass +7 -0
  141. metadata +241 -0
@@ -0,0 +1,19 @@
1
+ module Compass::Configuration::Paths
2
+
3
+ TRAILING_SEPARATOR = %r{.(/|#{Regexp.escape(File::SEPARATOR)})$}
4
+
5
+ def strip_trailing_separator(*attributes)
6
+ attributes.each do |attr|
7
+ alias_method "#{attr}_with_trailing_separator".to_sym, attr
8
+ class_eval %Q{
9
+ def #{attr} # def css_dir
10
+ path = #{attr}_with_trailing_separator # path = css_dir_with_trailing_separator
11
+ if path.to_s =~ TRAILING_SEPARATOR # if path =~ TRAILING_SEPARATOR
12
+ path = path[0..-($1.length+1)] # path = path[0..-($1.length+1)]
13
+ end # end
14
+ path # path
15
+ end # end
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,64 @@
1
+ require "compass/core/version"
2
+
3
+ module Compass
4
+ module Core
5
+ class << self
6
+ attr_accessor :module_deprecation_warning_issued
7
+ end
8
+ def base_directory(*subdirs)
9
+ File.expand_path(File.join(File.dirname(__FILE__), '..', "..", *subdirs))
10
+ end
11
+ def lib_directory(*subdirs)
12
+ File.expand_path(File.join(File.dirname(__FILE__), "..", *subdirs))
13
+ end
14
+
15
+ module_function :base_directory, :lib_directory
16
+ end
17
+
18
+ module HasDeprecatedConstantsFromCore
19
+ def self.extended(base)
20
+ new_base = base.name.sub(/^Compass/,"Compass::Core")
21
+ base.class_eval <<-RUBY
22
+ def self.const_missing(const_name)
23
+ puts "cannot find \#{const_name}"
24
+ if #{new_base}.const_defined?(const_name)
25
+ unless Compass::Core.module_deprecation_warning_issued
26
+ Compass::Core.module_deprecation_warning_issued = true
27
+ Compass::Util.compass_warn(
28
+ "DEPRECATED: #{base.name}::\#{const_name} has been moved to " +
29
+ "#{new_base}::\#{const_name}.\\n" +
30
+ "Please update \#{caller[0]}")
31
+ end
32
+ #{new_base}.const_get(const_name)
33
+ end
34
+ end
35
+ RUBY
36
+ end
37
+ end
38
+
39
+ extend HasDeprecatedConstantsFromCore
40
+
41
+ module SassExtensions
42
+ extend HasDeprecatedConstantsFromCore
43
+
44
+ module Functions
45
+ extend HasDeprecatedConstantsFromCore
46
+ end
47
+ end
48
+ end
49
+
50
+ require "sass"
51
+ require "sass/plugin"
52
+ require "compass/core/caniuse"
53
+ require 'compass/core/sass_extensions'
54
+ require 'compass/error'
55
+ require 'compass/browser_support'
56
+ require 'compass/configuration'
57
+
58
+ if defined?(Compass::Frameworks)
59
+ Compass::Frameworks.register(
60
+ "compass",
61
+ :stylesheets_directory => Compass::Core.base_directory("stylesheets"),
62
+ :templates_directory => Compass::Core.base_directory("templates")
63
+ )
64
+ end
@@ -0,0 +1,282 @@
1
+ require 'multi_json'
2
+ require 'singleton'
3
+ class Compass::Core::CanIUse
4
+ include Singleton
5
+
6
+ DATA_FILE_NAME = File.join(Compass::Core.base_directory, "data", "caniuse.json")
7
+ DATA_FEATURE_FILES = Dir.glob(File.join(Compass::Core.base_directory, "data", "caniuse_extras", "**", "*.json"))
8
+
9
+ def initialize
10
+ @data = MultiJson.load(File.read(DATA_FILE_NAME))
11
+ # support ad-hoc features
12
+ DATA_FEATURE_FILES.each do |feature_file|
13
+ feature_name = File.basename(feature_file, ".json")
14
+ # if the feature doesn't exist in the master `caniuse.json`
15
+ if @data["data"][feature_name].nil?
16
+ @data["data"][feature_name] = MultiJson.load(File.read(feature_file))
17
+ end
18
+ end
19
+ end
20
+
21
+ # The browser names from caniuse are ugly.
22
+ PUBLIC_BROWSER_NAMES = Hash.new {|h, k| k}
23
+ PUBLIC_BROWSER_NAMES.update(
24
+ "and_chr" => "android-chrome",
25
+ "and_ff" => "android-firefox",
26
+ "android" => "android",
27
+ "bb" => "blackberry",
28
+ "chrome" => "chrome",
29
+ "firefox" => "firefox",
30
+ "ie" => "ie",
31
+ "ie_mob" => "ie-mobile",
32
+ "ios_saf" => "ios-safari",
33
+ "op_mini" => "opera-mini",
34
+ "op_mob" => "opera-mobile",
35
+ "opera" => "opera",
36
+ "safari" => "safari"
37
+ )
38
+ CAN_I_USE_NAMES = Hash.new {|h, k| k}
39
+ CAN_I_USE_NAMES.update(PUBLIC_BROWSER_NAMES.invert)
40
+
41
+ # Returns all the known browsers according to caniuse
42
+ def browsers
43
+ @browsers ||= @data["agents"].keys.map{|b| PUBLIC_BROWSER_NAMES[b] }.sort
44
+ end
45
+
46
+ # Returns the prefix corresponding to a particular browser
47
+ def prefix(browser, version = nil)
48
+ assert_valid_browser browser
49
+ assert_valid_version browser, version if version
50
+ data = browser_data(browser)
51
+ p = if data["prefix_exceptions"] && data["prefix_exceptions"][version]
52
+ data["prefix_exceptions"][version]
53
+ else
54
+ data["prefix"]
55
+ end
56
+ "-#{p}"
57
+ end
58
+
59
+ # returns all possible prefixes a browser might use.
60
+ def all_prefixes(browser)
61
+ assert_valid_browser browser
62
+ data = browser_data(browser)
63
+ prefixes = ["-#{data["prefix"]}"]
64
+ if data["prefix_exceptions"]
65
+ prefixes += data["prefix_exceptions"].values.uniq.map{|p| "-#{p}"}
66
+ end
67
+ prefixes
68
+ end
69
+
70
+ # returns the prefixes needed by the list of browsers given
71
+ def prefixes(browsers = browsers)
72
+ result = browsers.map{|b| all_prefixes(b) }
73
+ result.flatten!
74
+ result.uniq!
75
+ result.sort!
76
+ result
77
+ end
78
+
79
+ def browser_ranges(capability, prefix = nil, include_unprefixed_versions = true)
80
+ assert_valid_capability capability
81
+ browsers = prefix.nil? ? browsers() : browsers_with_prefix(prefix)
82
+ browsers.inject({}) do |m, browser|
83
+ browser_versions = versions(browser)
84
+ min_version = find_first_prefixed_version(browser, browser_versions, capability, prefix)
85
+ if min_version
86
+ max_version = if include_unprefixed_versions
87
+ browser_versions.last
88
+ else
89
+ find_first_prefixed_version(browser, browser_versions.reverse, capability, prefix)
90
+ end
91
+ m.update(browser => [min_version, max_version])
92
+ end
93
+ m
94
+ end
95
+ end
96
+
97
+ def find_first_prefixed_version(browser, versions, capability, prefix)
98
+ versions.find do |version|
99
+ support = browser_support(browser, version, capability)
100
+ if prefix.nil?
101
+ support !~ /\bn\b/ && support !~ /\bx\b/
102
+ else
103
+ actual_prefix = prefix(browser, version)
104
+ support !~ /\bn\b/ && support =~ /\bx\b/ && prefix == actual_prefix
105
+ end
106
+ end
107
+ end
108
+
109
+ # @overload omitted_usage(browser, min_supported_version)
110
+ # How many users would be omitted if support for the given browser starts
111
+ # with the given version.
112
+ #
113
+ # @overload omitted_usage(browser, min_unsupported_version, max_unsupported_version)
114
+ # How many users would be omitted if the browsers with version
115
+ def omitted_usage(browser, min_version, max_version = nil)
116
+ versions = versions(browser)
117
+ if max_version.nil?
118
+ assert_valid_version browser, min_version
119
+ else
120
+ assert_valid_version browser, min_version, max_version
121
+ end
122
+ usage = 0
123
+ in_range = max_version.nil?
124
+ versions.each do |version|
125
+ break if max_version.nil? && version == min_version
126
+ in_range = true if (!max_version.nil? && version == min_version)
127
+ usage += usage(browser, version) if in_range
128
+ break if !max_version.nil? && version == max_version
129
+ end
130
+ return usage
131
+ end
132
+
133
+ # returns the list of browsers that use the given prefix
134
+ def browsers_with_prefix(prefix)
135
+ assert_valid_prefix prefix
136
+ prefix = "-" + prefix unless prefix.start_with?("-")
137
+ browsers.select {|b| all_prefixes(b).include?(prefix) }
138
+ end
139
+
140
+ SPEC_VERSION_MATCHERS = Hash.new do |h, k|
141
+ h[k] = /##{k}\b/
142
+ end
143
+
144
+ CAPABILITY_MATCHERS = {
145
+ :full_support => lambda {|support, capability| !support ^ (capability =~ /\by\b/) },
146
+ :partial_support => lambda {|support, capability| !support ^ (capability =~ /\ba\b/) },
147
+ :prefixed => lambda {|support, capability| !support ^ (capability =~ /\bx\b/) },
148
+ :spec_versions => lambda {|versions, capability| versions.any? {|v| capability =~ SPEC_VERSION_MATCHERS[v] } }
149
+ }
150
+
151
+ # Return whether the capability matcher the options specified.
152
+ # For each capability option in the options the capability will need to match it.
153
+ def capability_matches(support, capability_options_list)
154
+ capability_options_list.any? do |capability_options|
155
+ capability_options.all? {|c, v| CAPABILITY_MATCHERS[c].call(v, support)}
156
+ end
157
+ end
158
+
159
+ # returns the percentage of users (0-100) that would be affected if the prefix
160
+ # was not used with the given capability.
161
+ def prefixed_usage(prefix, capability, capability_options_list)
162
+ assert_valid_prefix prefix
163
+ assert_valid_capability capability
164
+ usage = 0
165
+ browsers_with_prefix(prefix).each do |browser|
166
+ versions(browser).each do |version|
167
+ next unless prefix == prefix(browser, version)
168
+ support = browser_support(browser, version, capability)
169
+ if capability_matches(support, capability_options_list) and support =~ /\bx\b/
170
+ usage += usage(browser, version)
171
+ end
172
+ end
173
+ end
174
+ usage
175
+ end
176
+
177
+ def next_version(browser, version)
178
+ versions = versions(browser)
179
+ index = versions.index(version)
180
+ index < versions.length - 1 ? versions[index + 1] : nil
181
+ end
182
+
183
+ def previous_version(browser, version)
184
+ versions = versions(browser)
185
+ index = versions.index(version)
186
+ index > 0 ? versions[index - 1] : nil
187
+ end
188
+
189
+ # Returns whether the given minimum version of a browser
190
+ # requires the use of a prefix for the stated capability.
191
+ def requires_prefix(browser, min_version, capability, capability_options_list)
192
+ assert_valid_browser browser
193
+ assert_valid_capability capability
194
+ found_version = false
195
+ versions(browser).each do |version|
196
+ found_version ||= version == min_version
197
+ next unless found_version
198
+ support = browser_support(browser, version, capability)
199
+ if capability_matches(support, capability_options_list) and support =~ /\bx\b/
200
+ return prefix(browser, version)
201
+ end
202
+ end
203
+ raise ArgumentError, "#{min_version} is not a version for #{browser}" unless found_version
204
+ nil
205
+ end
206
+
207
+ # Returns the versions of a browser. If the min_usage parameter is provided,
208
+ # only those versions having met the threshold of user percentage.
209
+ #
210
+ # @param min_usage a decimal number betwee 0 and 100
211
+ def versions(browser, min_usage = 0)
212
+ assert_valid_browser browser
213
+ versions = browser_data(browser)["versions"].compact
214
+ return versions if min_usage == 0
215
+ versions.select {|v| browser_data(browser)["usage_global"][v] > min_usage }
216
+ end
217
+
218
+ # The list of capabilities tracked by caniuse.
219
+ def capabilities
220
+ @capabilities ||= @data["data"].keys.select do |cap|
221
+ cats = @data["data"][cap]["categories"]
222
+ cats.any?{|cat| cat =~ /CSS/ }
223
+ end.sort
224
+ end
225
+
226
+ # the usage % for a given browser version.
227
+ def usage(browser, version)
228
+ browser_data(browser)["usage_global"][version]
229
+ end
230
+
231
+
232
+ def inspect
233
+ "#{self.class.name}(#{browsers.join(", ")})"
234
+ end
235
+
236
+ # the browser data assocated with a given capability
237
+ def capability_data(capability)
238
+ @data["data"][capability]
239
+ end
240
+
241
+ def browser_support(browser, version, capability)
242
+ capability_data(capability)["stats"][CAN_I_USE_NAMES[browser]][version]
243
+ end
244
+
245
+ # the metadata assocated with a given browser
246
+ def browser_data(browser)
247
+ @data["agents"][CAN_I_USE_NAMES[browser]]
248
+ end
249
+
250
+ # efficiently checks if a prefix is valid
251
+ def assert_valid_prefix(prefix)
252
+ @known_prefixes ||= Set.new(prefixes(browsers))
253
+ unless @known_prefixes.include?(prefix)
254
+ raise ArgumentError, "#{prefix} is not known browser prefix."
255
+ end
256
+ end
257
+
258
+ # efficiently checks if a browser is valid
259
+ def assert_valid_browser(browser)
260
+ @known_browsers ||= Set.new(browsers)
261
+ unless @known_browsers.include?(browser)
262
+ raise ArgumentError, "#{browser} is not known browser."
263
+ end
264
+ end
265
+
266
+ # efficiently checks if a capability is valid
267
+ def assert_valid_capability(capability)
268
+ @known_capabilities ||= Set.new(capabilities)
269
+ unless @known_capabilities.include?(capability)
270
+ raise ArgumentError, "#{capability} is not known browser capability."
271
+ end
272
+ nil
273
+ end
274
+
275
+ def assert_valid_version(browser, *versions)
276
+ versions.each do |v|
277
+ unless versions(browser).include?(v)
278
+ raise ArgumentError, "#{v} is not known version for #{browser}."
279
+ end
280
+ end
281
+ end
282
+ end
@@ -0,0 +1,10 @@
1
+ require 'sass'
2
+ unless Sass::Script::Functions.methods.grep(/\Adeclare\Z/).any?
3
+ raise LoadError, "It looks like you've got an incompatible version of Sass. This often happens when you have an old haml gem installed. Please upgrade Haml to v3.1 or above."
4
+ end
5
+
6
+ module Compass::Core::SassExtensions
7
+ end
8
+
9
+ require 'compass/core/sass_extensions/functions'
10
+ require 'compass/core/sass_extensions/monkey_patches'
@@ -0,0 +1,39 @@
1
+ module Compass::Core::SassExtensions::Functions
2
+ module SassDeclarationHelper
3
+ def declare(*args)
4
+ Sass::Script::Functions.declare(*args)
5
+ end
6
+ end
7
+ end
8
+
9
+ %w(
10
+ selectors enumerate urls display
11
+ inline_image image_size constants gradient_support
12
+ font_files lists colors math
13
+ env cross_browser_support configuration
14
+ ).each do |func|
15
+ require "compass/core/sass_extensions/functions/#{func}"
16
+ end
17
+
18
+ module Sass::Script::Functions
19
+ include Compass::Core::SassExtensions::Functions::Configuration
20
+ include Compass::Core::SassExtensions::Functions::Selectors
21
+ include Compass::Core::SassExtensions::Functions::Enumerate
22
+ include Compass::Core::SassExtensions::Functions::Urls
23
+ include Compass::Core::SassExtensions::Functions::Display
24
+ include Compass::Core::SassExtensions::Functions::InlineImage
25
+ include Compass::Core::SassExtensions::Functions::ImageSize
26
+ include Compass::Core::SassExtensions::Functions::GradientSupport::Functions
27
+ include Compass::Core::SassExtensions::Functions::FontFiles
28
+ include Compass::Core::SassExtensions::Functions::Constants
29
+ include Compass::Core::SassExtensions::Functions::Lists
30
+ include Compass::Core::SassExtensions::Functions::Colors
31
+ include Compass::Core::SassExtensions::Functions::Math
32
+ include Compass::Core::SassExtensions::Functions::CrossBrowserSupport
33
+ include Compass::Core::SassExtensions::Functions::Env
34
+ end
35
+
36
+ # Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
37
+ class Sass::Script::Functions::EvaluationContext
38
+ include Sass::Script::Functions
39
+ end
@@ -0,0 +1,67 @@
1
+ module Compass::Core::SassExtensions::Functions::Colors
2
+
3
+ # a genericized version of lighten/darken so that negative values can be used.
4
+ def adjust_lightness(color, amount)
5
+ assert_type color, :Color
6
+ assert_type amount, :Number
7
+ color.with(:lightness => Sass::Util.restrict(color.lightness + amount.value, 0..100))
8
+ end
9
+
10
+ # Scales a color's lightness by some percentage.
11
+ # If the amount is negative, the color is scaled darker, if positive, it is scaled lighter.
12
+ # This will never return a pure light or dark color unless the amount is 100%.
13
+ def scale_lightness(color, amount)
14
+ assert_type color, :Color
15
+ assert_type amount, :Number
16
+ color.with(:lightness => scale_color_value(color.lightness, amount.value))
17
+ end
18
+
19
+ # a genericized version of saturation/desaturate so that negative values can be used.
20
+ def adjust_saturation(color, amount)
21
+ assert_type color, :Color
22
+ assert_type amount, :Number
23
+ color.with(:saturation => Sass::Util.restrict(color.saturation + amount.value, 0..100))
24
+ end
25
+
26
+ # Scales a color's saturation by some percentage.
27
+ # If the amount is negative, the color is desaturated, if positive, it is saturated.
28
+ # This will never return a pure saturated or desaturated color unless the amount is 100%.
29
+ def scale_saturation(color, amount)
30
+ assert_type color, :Color
31
+ assert_type amount, :Number
32
+ color.with(:saturation => scale_color_value(color.saturation, amount.value))
33
+ end
34
+
35
+ def shade(color, percentage)
36
+ assert_type color, :Color
37
+ assert_type percentage, :Number
38
+ black = Sass::Script::Color.new([0, 0, 0])
39
+ mix(black, color, percentage)
40
+ end
41
+
42
+ def tint(color, percentage)
43
+ assert_type color, :Color
44
+ assert_type percentage, :Number
45
+ white = Sass::Script::Color.new([255, 255, 255])
46
+ mix(white, color, percentage)
47
+ end
48
+
49
+ # returns an IE hex string for a color with an alpha channel
50
+ # suitable for passing to IE filters.
51
+ def ie_hex_str(color)
52
+ assert_type color, :Color
53
+ alpha = (color.alpha * 255).round
54
+ alphastr = alpha.to_s(16).rjust(2, '0')
55
+ Sass::Script::String.new("##{alphastr}#{color.send(:hex_str)[1..-1]}".upcase)
56
+ end
57
+
58
+ private
59
+ def scale_color_value(value, amount)
60
+ if amount > 0
61
+ value += (100 - value) * (amount / 100.0)
62
+ elsif amount < 0
63
+ value += value * amount / 100.0
64
+ end
65
+ value
66
+ end
67
+ end