sass 3.2.19 → 3.4.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -1
  3. data/CODE_OF_CONDUCT.md +10 -0
  4. data/CONTRIBUTING.md +148 -0
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +87 -61
  7. data/Rakefile +119 -15
  8. data/VERSION +1 -1
  9. data/VERSION_DATE +1 -1
  10. data/VERSION_NAME +1 -1
  11. data/bin/sass +1 -1
  12. data/bin/scss +1 -1
  13. data/extra/sass-spec-ref.sh +32 -0
  14. data/extra/update_watch.rb +1 -1
  15. data/lib/sass/cache_stores/base.rb +2 -2
  16. data/lib/sass/cache_stores/chain.rb +2 -1
  17. data/lib/sass/cache_stores/filesystem.rb +8 -12
  18. data/lib/sass/cache_stores/memory.rb +5 -6
  19. data/lib/sass/cache_stores/null.rb +2 -2
  20. data/lib/sass/callbacks.rb +3 -2
  21. data/lib/sass/css.rb +22 -23
  22. data/lib/sass/deprecation.rb +55 -0
  23. data/lib/sass/engine.rb +487 -191
  24. data/lib/sass/environment.rb +172 -58
  25. data/lib/sass/error.rb +21 -24
  26. data/lib/sass/exec/base.rb +199 -0
  27. data/lib/sass/exec/sass_convert.rb +283 -0
  28. data/lib/sass/exec/sass_scss.rb +440 -0
  29. data/lib/sass/exec.rb +5 -703
  30. data/lib/sass/features.rb +47 -0
  31. data/lib/sass/importers/base.rb +50 -7
  32. data/lib/sass/importers/deprecated_path.rb +51 -0
  33. data/lib/sass/importers/filesystem.rb +54 -21
  34. data/lib/sass/importers.rb +1 -0
  35. data/lib/sass/logger/base.rb +9 -5
  36. data/lib/sass/logger/delayed.rb +50 -0
  37. data/lib/sass/logger/log_level.rb +3 -7
  38. data/lib/sass/logger.rb +9 -7
  39. data/lib/sass/media.rb +20 -23
  40. data/lib/sass/plugin/compiler.rb +321 -145
  41. data/lib/sass/plugin/configuration.rb +45 -34
  42. data/lib/sass/plugin/merb.rb +3 -3
  43. data/lib/sass/plugin/rack.rb +3 -3
  44. data/lib/sass/plugin/rails.rb +1 -1
  45. data/lib/sass/plugin/staleness_checker.rb +6 -6
  46. data/lib/sass/plugin.rb +9 -8
  47. data/lib/sass/repl.rb +3 -3
  48. data/lib/sass/script/css_lexer.rb +8 -4
  49. data/lib/sass/script/css_parser.rb +4 -2
  50. data/lib/sass/script/css_variable_warning.rb +52 -0
  51. data/lib/sass/script/functions.rb +1583 -433
  52. data/lib/sass/script/lexer.rb +198 -79
  53. data/lib/sass/script/parser.rb +463 -133
  54. data/lib/sass/script/tree/funcall.rb +313 -0
  55. data/lib/sass/script/tree/interpolation.rb +223 -0
  56. data/lib/sass/script/tree/list_literal.rb +104 -0
  57. data/lib/sass/script/tree/literal.rb +49 -0
  58. data/lib/sass/script/tree/map_literal.rb +64 -0
  59. data/lib/sass/script/{node.rb → tree/node.rb} +42 -14
  60. data/lib/sass/script/tree/operation.rb +156 -0
  61. data/lib/sass/script/tree/selector.rb +26 -0
  62. data/lib/sass/script/tree/string_interpolation.rb +125 -0
  63. data/lib/sass/script/{unary_operation.rb → tree/unary_operation.rb} +6 -6
  64. data/lib/sass/script/tree/variable.rb +57 -0
  65. data/lib/sass/script/tree.rb +16 -0
  66. data/lib/sass/script/{arg_list.rb → value/arg_list.rb} +9 -25
  67. data/lib/sass/script/value/base.rb +241 -0
  68. data/lib/sass/script/value/bool.rb +35 -0
  69. data/lib/sass/script/value/color.rb +698 -0
  70. data/lib/sass/script/value/helpers.rb +272 -0
  71. data/lib/sass/script/value/list.rb +113 -0
  72. data/lib/sass/script/value/map.rb +70 -0
  73. data/lib/sass/script/{null.rb → value/null.rb} +14 -7
  74. data/lib/sass/script/{number.rb → value/number.rb} +196 -86
  75. data/lib/sass/script/value/string.rb +138 -0
  76. data/lib/sass/script/value.rb +11 -0
  77. data/lib/sass/script.rb +38 -11
  78. data/lib/sass/scss/css_parser.rb +25 -5
  79. data/lib/sass/scss/parser.rb +532 -458
  80. data/lib/sass/scss/rx.rb +21 -14
  81. data/lib/sass/scss/static_parser.rb +328 -9
  82. data/lib/sass/scss.rb +0 -2
  83. data/lib/sass/selector/abstract_sequence.rb +36 -19
  84. data/lib/sass/selector/comma_sequence.rb +125 -26
  85. data/lib/sass/selector/pseudo.rb +266 -0
  86. data/lib/sass/selector/sequence.rb +200 -71
  87. data/lib/sass/selector/simple.rb +30 -32
  88. data/lib/sass/selector/simple_sequence.rb +193 -64
  89. data/lib/sass/selector.rb +65 -194
  90. data/lib/sass/shared.rb +2 -2
  91. data/lib/sass/source/map.rb +213 -0
  92. data/lib/sass/source/position.rb +39 -0
  93. data/lib/sass/source/range.rb +41 -0
  94. data/lib/sass/stack.rb +120 -0
  95. data/lib/sass/supports.rb +19 -23
  96. data/lib/sass/tree/at_root_node.rb +83 -0
  97. data/lib/sass/tree/charset_node.rb +1 -1
  98. data/lib/sass/tree/comment_node.rb +4 -4
  99. data/lib/sass/tree/css_import_node.rb +19 -11
  100. data/lib/sass/tree/debug_node.rb +2 -2
  101. data/lib/sass/tree/directive_node.rb +21 -4
  102. data/lib/sass/tree/each_node.rb +8 -8
  103. data/lib/sass/tree/error_node.rb +18 -0
  104. data/lib/sass/tree/extend_node.rb +14 -7
  105. data/lib/sass/tree/for_node.rb +4 -4
  106. data/lib/sass/tree/function_node.rb +14 -4
  107. data/lib/sass/tree/if_node.rb +1 -1
  108. data/lib/sass/tree/import_node.rb +10 -10
  109. data/lib/sass/tree/keyframe_rule_node.rb +15 -0
  110. data/lib/sass/tree/media_node.rb +4 -14
  111. data/lib/sass/tree/mixin_def_node.rb +4 -4
  112. data/lib/sass/tree/mixin_node.rb +21 -8
  113. data/lib/sass/tree/node.rb +59 -15
  114. data/lib/sass/tree/prop_node.rb +42 -24
  115. data/lib/sass/tree/return_node.rb +3 -2
  116. data/lib/sass/tree/root_node.rb +19 -3
  117. data/lib/sass/tree/rule_node.rb +49 -26
  118. data/lib/sass/tree/supports_node.rb +0 -13
  119. data/lib/sass/tree/trace_node.rb +2 -1
  120. data/lib/sass/tree/variable_node.rb +9 -3
  121. data/lib/sass/tree/visitors/base.rb +5 -8
  122. data/lib/sass/tree/visitors/check_nesting.rb +62 -36
  123. data/lib/sass/tree/visitors/convert.rb +111 -76
  124. data/lib/sass/tree/visitors/cssize.rb +206 -74
  125. data/lib/sass/tree/visitors/deep_copy.rb +11 -6
  126. data/lib/sass/tree/visitors/extend.rb +19 -17
  127. data/lib/sass/tree/visitors/perform.rb +308 -190
  128. data/lib/sass/tree/visitors/set_options.rb +21 -7
  129. data/lib/sass/tree/visitors/to_css.rb +273 -92
  130. data/lib/sass/tree/warn_node.rb +2 -2
  131. data/lib/sass/tree/while_node.rb +2 -2
  132. data/lib/sass/util/cross_platform_random.rb +19 -0
  133. data/lib/sass/util/normalized_map.rb +129 -0
  134. data/lib/sass/util/ordered_hash.rb +192 -0
  135. data/lib/sass/util/subset_map.rb +5 -5
  136. data/lib/sass/util/test.rb +0 -1
  137. data/lib/sass/util.rb +620 -193
  138. data/lib/sass/version.rb +22 -24
  139. data/lib/sass.rb +27 -13
  140. data/test/sass/cache_test.rb +62 -20
  141. data/test/sass/callbacks_test.rb +1 -1
  142. data/test/sass/compiler_test.rb +236 -0
  143. data/test/sass/conversion_test.rb +472 -44
  144. data/test/sass/css2sass_test.rb +73 -5
  145. data/test/sass/css_variable_test.rb +132 -0
  146. data/test/sass/encoding_test.rb +219 -0
  147. data/test/sass/engine_test.rb +618 -415
  148. data/test/sass/exec_test.rb +12 -2
  149. data/test/sass/extend_test.rb +419 -168
  150. data/test/sass/functions_test.rb +931 -93
  151. data/test/sass/importer_test.rb +250 -21
  152. data/test/sass/logger_test.rb +1 -1
  153. data/test/sass/more_results/more_import.css +1 -1
  154. data/test/sass/more_templates/more1.sass +10 -10
  155. data/test/sass/more_templates/more_import.sass +2 -2
  156. data/test/sass/plugin_test.rb +26 -34
  157. data/test/sass/results/compact.css +1 -1
  158. data/test/sass/results/complex.css +4 -4
  159. data/test/sass/results/expanded.css +1 -1
  160. data/test/sass/results/import.css +1 -1
  161. data/test/sass/results/import_charset_ibm866.css +2 -2
  162. data/test/sass/results/mixins.css +17 -17
  163. data/test/sass/results/nested.css +1 -1
  164. data/test/sass/results/parent_ref.css +2 -2
  165. data/test/sass/results/script.css +5 -5
  166. data/test/sass/results/scss_import.css +1 -1
  167. data/test/sass/script_conversion_test.rb +97 -39
  168. data/test/sass/script_test.rb +911 -102
  169. data/test/sass/scss/css_test.rb +215 -34
  170. data/test/sass/scss/rx_test.rb +8 -4
  171. data/test/sass/scss/scss_test.rb +2424 -325
  172. data/test/sass/source_map_test.rb +1055 -0
  173. data/test/sass/superselector_test.rb +210 -0
  174. data/test/sass/templates/_partial.sass +1 -1
  175. data/test/sass/templates/basic.sass +10 -10
  176. data/test/sass/templates/bork1.sass +1 -1
  177. data/test/sass/templates/bork5.sass +1 -1
  178. data/test/sass/templates/compact.sass +10 -10
  179. data/test/sass/templates/complex.sass +187 -187
  180. data/test/sass/templates/compressed.sass +10 -10
  181. data/test/sass/templates/expanded.sass +10 -10
  182. data/test/sass/templates/import.sass +2 -2
  183. data/test/sass/templates/importee.sass +3 -3
  184. data/test/sass/templates/mixins.sass +22 -22
  185. data/test/sass/templates/multiline.sass +4 -4
  186. data/test/sass/templates/nested.sass +13 -13
  187. data/test/sass/templates/parent_ref.sass +12 -12
  188. data/test/sass/templates/script.sass +70 -70
  189. data/test/sass/templates/scss_import.scss +2 -1
  190. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +1 -1
  191. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +2 -2
  192. data/test/sass/templates/subdir/subdir.sass +3 -3
  193. data/test/sass/templates/units.sass +10 -10
  194. data/test/sass/test_helper.rb +1 -1
  195. data/test/sass/util/multibyte_string_scanner_test.rb +11 -3
  196. data/test/sass/util/normalized_map_test.rb +51 -0
  197. data/test/sass/util/subset_map_test.rb +2 -2
  198. data/test/sass/util_test.rb +99 -43
  199. data/test/sass/value_helpers_test.rb +179 -0
  200. data/test/sass-spec.yml +3 -0
  201. data/test/test_helper.rb +42 -12
  202. data/vendor/listen/CHANGELOG.md +1 -228
  203. data/vendor/listen/Gemfile +5 -15
  204. data/vendor/listen/README.md +111 -77
  205. data/vendor/listen/Rakefile +0 -42
  206. data/vendor/listen/lib/listen/adapter.rb +195 -82
  207. data/vendor/listen/lib/listen/adapters/bsd.rb +27 -64
  208. data/vendor/listen/lib/listen/adapters/darwin.rb +21 -58
  209. data/vendor/listen/lib/listen/adapters/linux.rb +23 -55
  210. data/vendor/listen/lib/listen/adapters/polling.rb +25 -34
  211. data/vendor/listen/lib/listen/adapters/windows.rb +50 -46
  212. data/vendor/listen/lib/listen/directory_record.rb +96 -61
  213. data/vendor/listen/lib/listen/listener.rb +135 -37
  214. data/vendor/listen/lib/listen/turnstile.rb +9 -5
  215. data/vendor/listen/lib/listen/version.rb +1 -1
  216. data/vendor/listen/lib/listen.rb +33 -19
  217. data/vendor/listen/listen.gemspec +6 -0
  218. data/vendor/listen/spec/listen/adapter_spec.rb +43 -77
  219. data/vendor/listen/spec/listen/adapters/polling_spec.rb +8 -8
  220. data/vendor/listen/spec/listen/directory_record_spec.rb +81 -56
  221. data/vendor/listen/spec/listen/listener_spec.rb +128 -39
  222. data/vendor/listen/spec/listen_spec.rb +15 -21
  223. data/vendor/listen/spec/spec_helper.rb +4 -0
  224. data/vendor/listen/spec/support/adapter_helper.rb +52 -15
  225. data/vendor/listen/spec/support/directory_record_helper.rb +7 -5
  226. data/vendor/listen/spec/support/listeners_helper.rb +30 -7
  227. metadata +161 -111
  228. data/CONTRIBUTING +0 -3
  229. data/lib/sass/script/bool.rb +0 -18
  230. data/lib/sass/script/color.rb +0 -606
  231. data/lib/sass/script/funcall.rb +0 -245
  232. data/lib/sass/script/interpolation.rb +0 -79
  233. data/lib/sass/script/list.rb +0 -85
  234. data/lib/sass/script/literal.rb +0 -221
  235. data/lib/sass/script/operation.rb +0 -110
  236. data/lib/sass/script/string.rb +0 -51
  237. data/lib/sass/script/string_interpolation.rb +0 -103
  238. data/lib/sass/script/variable.rb +0 -58
  239. data/lib/sass/scss/script_lexer.rb +0 -15
  240. data/lib/sass/scss/script_parser.rb +0 -25
  241. data/test/Gemfile +0 -3
  242. data/test/Gemfile.lock +0 -10
  243. data/vendor/listen/lib/listen/dependency_manager.rb +0 -126
  244. data/vendor/listen/lib/listen/multi_listener.rb +0 -143
  245. data/vendor/listen/spec/listen/dependency_manager_spec.rb +0 -107
  246. data/vendor/listen/spec/listen/multi_listener_spec.rb +0 -174
@@ -0,0 +1,47 @@
1
+ require 'set'
2
+ module Sass
3
+ # Provides `Sass.has_feature?` which allows for simple feature detection
4
+ # by providing a feature name.
5
+ module Features
6
+ # This is the set of features that can be detected.
7
+ #
8
+ # When this is updated, the documentation of `feature-exists()` should be
9
+ # updated as well.
10
+ KNOWN_FEATURES = Set[*%w(
11
+ global-variable-shadowing
12
+ extend-selector-pseudoclass
13
+ units-level-3
14
+ at-error
15
+ )]
16
+
17
+ # Check if a feature exists by name. This is used to implement
18
+ # the Sass function `feature-exists($feature)`
19
+ #
20
+ # @param feature_name [String] The case sensitive name of the feature to
21
+ # check if it exists in this version of Sass.
22
+ # @return [Boolean] whether the feature of that name exists.
23
+ def has_feature?(feature_name)
24
+ KNOWN_FEATURES.include?(feature_name)
25
+ end
26
+
27
+ # Add a feature to Sass. Plugins can use this to easily expose their
28
+ # availability to end users. Plugins must prefix their feature
29
+ # names with a dash to distinguish them from official features.
30
+ #
31
+ # @example
32
+ # Sass.add_feature("-import-globbing")
33
+ # Sass.add_feature("-math-cos")
34
+ #
35
+ #
36
+ # @param feature_name [String] The case sensitive name of the feature to
37
+ # to add to Sass. Must begin with a dash.
38
+ def add_feature(feature_name)
39
+ unless feature_name[0] == ?-
40
+ raise ArgumentError.new("Plugin feature names must begin with a dash")
41
+ end
42
+ KNOWN_FEATURES << feature_name
43
+ end
44
+ end
45
+
46
+ extend Features
47
+ end
@@ -15,13 +15,9 @@ module Sass
15
15
  # They should also implement the \{#find\_relative} method.
16
16
  #
17
17
  # Importers should be serializable via `Marshal.dump`.
18
- # In addition to the standard `_dump` and `_load` methods,
19
- # importers can define `_before_dump`, `_after_dump`, `_around_dump`,
20
- # and `_after_load` methods as per {Sass::Util#dump} and {Sass::Util#load}.
21
18
  #
22
19
  # @abstract
23
20
  class Base
24
-
25
21
  # Find a Sass file relative to another file.
26
22
  # Importers without a notion of "relative paths"
27
23
  # should just return nil here.
@@ -94,7 +90,7 @@ module Sass
94
90
  #
95
91
  # @param uri [String] The URI of the file to check.
96
92
  # Comes from a `:filename` option set on an engine returned by this importer.
97
- # @param options [{Symbol => Objet}] Options for the Sass file
93
+ # @param options [{Symbol => Object}] Options for the Sass file
98
94
  # containing the `@import` currently being checked.
99
95
  # @return [Time, nil]
100
96
  def mtime(uri, options)
@@ -122,6 +118,34 @@ module Sass
122
118
  Sass::Util.abstract(self)
123
119
  end
124
120
 
121
+ # Get the publicly-visible URL for an imported file. This URL is used by
122
+ # source maps to link to the source stylesheet. This may return `nil` to
123
+ # indicate that no public URL is available; however, this will cause
124
+ # sourcemap generation to fail if any CSS is generated from files imported
125
+ # from this importer.
126
+ #
127
+ # If an absolute "file:" URI can be produced for an imported file, that
128
+ # should be preferred to returning `nil`. However, a URL relative to
129
+ # `sourcemap_directory` should be preferred over an absolute "file:" URI.
130
+ #
131
+ # @param uri [String] A URI known to be valid for this importer.
132
+ # @param sourcemap_directory [String, NilClass] The absolute path to a
133
+ # directory on disk where the sourcemap will be saved. If uri refers to
134
+ # a file on disk that's accessible relative to sourcemap_directory, this
135
+ # may return a relative URL. This may be `nil` if the sourcemap's
136
+ # eventual location is unknown.
137
+ # @return [String?] The publicly-visible URL for this file, or `nil`
138
+ # indicating that no publicly-visible URL exists. This should be
139
+ # appropriately URL-escaped.
140
+ def public_url(uri, sourcemap_directory)
141
+ return if @public_url_warning_issued
142
+ @public_url_warning_issued = true
143
+ Sass::Util.sass_warn <<WARNING
144
+ WARNING: #{self.class.name} should define the #public_url method.
145
+ WARNING
146
+ nil
147
+ end
148
+
125
149
  # A string representation of the importer.
126
150
  # Should be overridden by subclasses.
127
151
  #
@@ -132,8 +156,27 @@ module Sass
132
156
  def to_s
133
157
  Sass::Util.abstract(self)
134
158
  end
159
+
160
+ # If the importer is based on files on the local filesystem
161
+ # this method should return folders which should be watched
162
+ # for changes.
163
+ #
164
+ # @return [Array<String>] List of absolute paths of directories to watch
165
+ def directories_to_watch
166
+ []
167
+ end
168
+
169
+ # If this importer is based on files on the local filesystem This method
170
+ # should return true if the file, when changed, should trigger a
171
+ # recompile.
172
+ #
173
+ # It is acceptable for non-sass files to be watched and trigger a recompile.
174
+ #
175
+ # @param filename [String] The absolute filename for a file that has changed.
176
+ # @return [Boolean] When the file changed should cause a recompile.
177
+ def watched_file?(filename)
178
+ false
179
+ end
135
180
  end
136
181
  end
137
182
  end
138
-
139
-
@@ -0,0 +1,51 @@
1
+ module Sass
2
+ module Importers
3
+ # This importer emits a deprecation warning the first time it is used to
4
+ # import a file. It is used to deprecate the current working
5
+ # directory from the list of automatic sass load paths.
6
+ class DeprecatedPath < Filesystem
7
+ # @param root [String] The absolute, expanded path to the folder that is deprecated.
8
+ def initialize(root)
9
+ @specified_root = root
10
+ @warning_given = false
11
+ super
12
+ end
13
+
14
+ # @see Sass::Importers::Base#find
15
+ def find(*args)
16
+ found = super
17
+ if found && !@warning_given
18
+ @warning_given = true
19
+ Sass::Util.sass_warn deprecation_warning
20
+ end
21
+ found
22
+ end
23
+
24
+ # @see Base#directories_to_watch
25
+ def directories_to_watch
26
+ # The current working directory was not watched in Sass 3.2,
27
+ # so we continue not to watch it while it's deprecated.
28
+ []
29
+ end
30
+
31
+ # @see Sass::Importers::Base#to_s
32
+ def to_s
33
+ "#{@root} (DEPRECATED)"
34
+ end
35
+
36
+ protected
37
+
38
+ # @return [String] The deprecation warning that will be printed the first
39
+ # time an import occurs.
40
+ def deprecation_warning
41
+ path = @specified_root == "." ? "the current working directory" : @specified_root
42
+ <<WARNING
43
+ DEPRECATION WARNING: Importing from #{path} will not be
44
+ automatic in future versions of Sass. To avoid future errors, you can add it
45
+ to your environment explicitly by setting `SASS_PATH=#{@specified_root}`, by using the -I command
46
+ line option, or by changing your Sass configuration options.
47
+ WARNING
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,4 +1,3 @@
1
- require 'pathname'
2
1
  require 'set'
3
2
 
4
3
  module Sass
@@ -6,7 +5,6 @@ module Sass
6
5
  # The default importer, used for any strings found in the load path.
7
6
  # Simply loads Sass files from the filesystem using the default logic.
8
7
  class Filesystem < Base
9
-
10
8
  attr_accessor :root
11
9
 
12
10
  # Creates a new filesystem importer that imports files relative to a given path.
@@ -15,6 +13,7 @@ module Sass
15
13
  # This importer will import files relative to this path.
16
14
  def initialize(root)
17
15
  @root = File.expand_path(root)
16
+ @real_root = Sass::Util.realpath(@root).to_s
18
17
  @same_name_warnings = Set.new
19
18
  end
20
19
 
@@ -39,7 +38,7 @@ module Sass
39
38
  # @see Base#key
40
39
  def key(name, options)
41
40
  [self.class.name + ":" + File.dirname(File.expand_path(name)),
42
- File.basename(name)]
41
+ File.basename(name)]
43
42
  end
44
43
 
45
44
  # @see Base#to_s
@@ -52,7 +51,32 @@ module Sass
52
51
  end
53
52
 
54
53
  def eql?(other)
55
- root.eql?(other.root)
54
+ !other.nil? && other.respond_to?(:root) && root.eql?(other.root)
55
+ end
56
+
57
+ # @see Base#directories_to_watch
58
+ def directories_to_watch
59
+ [root]
60
+ end
61
+
62
+ # @see Base#watched_file?
63
+ def watched_file?(filename)
64
+ # Check against the root with symlinks resolved, since Listen
65
+ # returns fully-resolved paths.
66
+ filename =~ /\.s[ac]ss$/ && filename.start_with?(@real_root + File::SEPARATOR)
67
+ end
68
+
69
+ def public_url(name, sourcemap_directory)
70
+ file_pathname = Sass::Util.cleanpath(Sass::Util.absolute_path(name, @root))
71
+ return Sass::Util.file_uri_from_path(file_pathname) if sourcemap_directory.nil?
72
+
73
+ sourcemap_pathname = Sass::Util.cleanpath(sourcemap_directory)
74
+ begin
75
+ Sass::Util.file_uri_from_path(
76
+ Sass::Util.relative_path_from(file_pathname, sourcemap_pathname))
77
+ rescue ArgumentError # when a relative path cannot be constructed
78
+ Sass::Util.file_uri_from_path(file_pathname)
79
+ end
56
80
  end
57
81
 
58
82
  protected
@@ -107,7 +131,7 @@ module Sass
107
131
  end
108
132
  end
109
133
 
110
- REDUNDANT_DIRECTORY = %r{#{Regexp.escape(File::SEPARATOR)}\.#{Regexp.escape(File::SEPARATOR)}}
134
+ REDUNDANT_DIRECTORY = /#{Regexp.escape(File::SEPARATOR)}\.#{Regexp.escape(File::SEPARATOR)}/
111
135
  # Given a base directory and an `@import`ed name,
112
136
  # finds an existant file that matches the name.
113
137
  #
@@ -115,35 +139,39 @@ module Sass
115
139
  # @param name [String] The filename to search for.
116
140
  # @return [(String, Symbol)] A filename-syntax pair.
117
141
  def find_real_file(dir, name, options)
118
- # on windows 'dir' can be in native File::ALT_SEPARATOR form
142
+ # On windows 'dir' or 'name' can be in native File::ALT_SEPARATOR form.
119
143
  dir = dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
144
+ name = name.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
120
145
 
121
146
  found = possible_files(remove_root(name)).map do |f, s|
122
- path = (dir == "." || Pathname.new(f).absolute?) ? f : "#{escape_glob_characters(dir)}/#{f}"
147
+ path = if dir == "." || Sass::Util.pathname(f).absolute?
148
+ f
149
+ else
150
+ "#{escape_glob_characters(dir)}/#{f}"
151
+ end
123
152
  Dir[path].map do |full_path|
124
153
  full_path.gsub!(REDUNDANT_DIRECTORY, File::SEPARATOR)
125
- [Pathname.new(full_path).cleanpath.to_s, s]
154
+ [Sass::Util.cleanpath(full_path).to_s, s]
126
155
  end
127
- end
128
- found = Sass::Util.flatten(found, 1)
156
+ end.flatten(1)
129
157
  return if found.empty?
130
158
 
131
159
  if found.size > 1 && !@same_name_warnings.include?(found.first.first)
132
160
  found.each {|(f, _)| @same_name_warnings << f}
133
- relative_to = Pathname.new(dir)
134
- if options[:_line]
161
+ relative_to = Sass::Util.pathname(dir)
162
+ if options[:_from_import_node]
135
163
  # If _line exists, we're here due to an actual import in an
136
164
  # import_node and we want to print a warning for a user writing an
137
165
  # ambiguous import.
138
- candidates = found.map {|(f, _)| " " + Pathname.new(f).relative_path_from(relative_to).to_s}.join("\n")
139
- Sass::Util.sass_warn <<WARNING
140
- WARNING: On line #{options[:_line]}#{" of #{options[:filename]}" if options[:filename]}:
141
- It's not clear which file to import for '@import "#{name}"'.
142
- Candidates:
166
+ candidates = found.map do |(f, _)|
167
+ " " + Sass::Util.pathname(f).relative_path_from(relative_to).to_s
168
+ end.join("\n")
169
+ raise Sass::SyntaxError.new(<<MESSAGE)
170
+ It's not clear which file to import for '@import "#{name}"'.
171
+ Candidates:
143
172
  #{candidates}
144
- For now I'll choose #{File.basename found.first.first}.
145
- This will be an error in future versions of Sass.
146
- WARNING
173
+ Please delete or rename all but one of these files.
174
+ MESSAGE
147
175
  else
148
176
  # Otherwise, we're here via StalenessChecker, and we want to print a
149
177
  # warning for a user running `sass --watch` with two ambiguous files.
@@ -163,7 +191,7 @@ WARNING
163
191
  def split(name)
164
192
  extension = nil
165
193
  dirname, basename = File.dirname(name), File.basename(name)
166
- if basename =~ /^(.*)\.(#{extensions.keys.map{|e| Regexp.escape(e)}.join('|')})$/
194
+ if basename =~ /^(.*)\.(#{extensions.keys.map {|e| Regexp.escape(e)}.join('|')})$/
167
195
  basename = $1
168
196
  extension = $2
169
197
  end
@@ -176,6 +204,11 @@ WARNING
176
204
  full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
177
205
  return unless full_filename && File.readable?(full_filename)
178
206
 
207
+ # TODO: this preserves historical behavior, but it's possible
208
+ # :filename should be either normalized to the native format
209
+ # or consistently URI-format.
210
+ full_filename = full_filename.tr("\\", "/") if Sass::Util.windows?
211
+
179
212
  options[:syntax] = syntax
180
213
  options[:filename] = full_filename
181
214
  options[:importer] = self
@@ -20,3 +20,4 @@ end
20
20
 
21
21
  require 'sass/importers/base'
22
22
  require 'sass/importers/filesystem'
23
+ require 'sass/importers/deprecated_path'
@@ -1,11 +1,11 @@
1
1
  require 'sass/logger/log_level'
2
2
 
3
3
  class Sass::Logger::Base
4
-
5
4
  include Sass::Logger::LogLevel
6
5
 
7
6
  attr_accessor :log_level
8
7
  attr_accessor :disabled
8
+ attr_accessor :io
9
9
 
10
10
  log_level :trace
11
11
  log_level :debug
@@ -13,8 +13,9 @@ class Sass::Logger::Base
13
13
  log_level :warn
14
14
  log_level :error
15
15
 
16
- def initialize(log_level = :debug)
16
+ def initialize(log_level = :debug, io = nil)
17
17
  self.log_level = log_level
18
+ self.io = io
18
19
  end
19
20
 
20
21
  def logging_level?(level)
@@ -22,11 +23,14 @@ class Sass::Logger::Base
22
23
  end
23
24
 
24
25
  def log(level, message)
25
- self._log(level, message) if logging_level?(level)
26
+ _log(level, message) if logging_level?(level)
26
27
  end
27
28
 
28
29
  def _log(level, message)
29
- Kernel::warn(message)
30
+ if io
31
+ io.puts(message)
32
+ else
33
+ Kernel.warn(message)
34
+ end
30
35
  end
31
-
32
36
  end
@@ -0,0 +1,50 @@
1
+ require 'sass/logger/log_level'
2
+
3
+ # A logger that delays messages until they're explicitly flushed to an inner
4
+ # logger.
5
+ #
6
+ # This can be installed around the current logger by calling \{#install!}, and
7
+ # the original logger can be replaced by calling \{#uninstall!}. The log
8
+ # messages can be flushed by calling \{#flush}.
9
+ class Sass::Logger::Delayed < Sass::Logger::Base
10
+ # Installs a new delayed logger as the current Sass logger, wrapping the
11
+ # original logger.
12
+ #
13
+ # This can be undone by calling \{#uninstall!}.
14
+ #
15
+ # @return [Sass::Logger::Delayed] The newly-created logger.
16
+ def self.install!
17
+ logger = Sass::Logger::Delayed.new(Sass.logger)
18
+ Sass.logger = logger
19
+ logger
20
+ end
21
+
22
+ # Creates a delayed logger wrapping `inner`.
23
+ #
24
+ # @param inner [Sass::Logger::Base] The wrapped logger.
25
+ def initialize(inner)
26
+ self.log_level = inner.log_level
27
+ @inner = inner
28
+ @messages = []
29
+ end
30
+
31
+ # Flushes all queued logs to the wrapped logger.
32
+ def flush
33
+ @messages.each {|(l, m)| @inner.log(l, m)}
34
+ end
35
+
36
+ # Uninstalls this logger from \{Sass.logger\}. This should only be called if
37
+ # the logger was installed using \{#install!}
38
+ def uninstall!
39
+ if Sass.logger != self
40
+ throw Exception.new("Can't uninstall a logger that's not currently installed.")
41
+ end
42
+
43
+ @inner.log_level = log_level
44
+ Sass.logger = @inner
45
+ end
46
+
47
+ def _log(level, message)
48
+ @messages << [level, message]
49
+ end
50
+ end
@@ -1,24 +1,21 @@
1
1
  module Sass
2
2
  module Logger
3
3
  module LogLevel
4
-
5
4
  def self.included(base)
6
5
  base.extend(ClassMethods)
7
6
  end
8
-
7
+
9
8
  module ClassMethods
10
9
  def inherited(subclass)
11
10
  subclass.log_levels = subclass.superclass.log_levels.dup
12
11
  end
13
12
 
13
+ attr_writer :log_levels
14
+
14
15
  def log_levels
15
16
  @log_levels ||= {}
16
17
  end
17
18
 
18
- def log_levels=(levels)
19
- @log_levels = levels
20
- end
21
-
22
19
  def log_level?(level, min_level)
23
20
  log_levels[level] >= log_levels[min_level]
24
21
  end
@@ -43,7 +40,6 @@ module Sass
43
40
  RUBY
44
41
  end
45
42
  end
46
-
47
43
  end
48
44
  end
49
45
  end
data/lib/sass/logger.rb CHANGED
@@ -1,15 +1,17 @@
1
- module Sass::Logger
2
-
3
- end
1
+ module Sass::Logger; end
4
2
 
5
3
  require "sass/logger/log_level"
6
4
  require "sass/logger/base"
5
+ require "sass/logger/delayed"
7
6
 
8
7
  module Sass
9
-
10
8
  class << self
11
- attr_accessor :logger
12
- end
9
+ def logger=(l)
10
+ Thread.current[:sass_logger] = l
11
+ end
13
12
 
14
- self.logger = Sass::Logger::Base.new
13
+ def logger
14
+ Thread.current[:sass_logger] ||= Sass::Logger::Base.new
15
+ end
16
+ end
15
17
  end
data/lib/sass/media.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module Sass::Media
3
3
  # A comma-separated list of queries.
4
4
  #
5
- # media_query [ ',' S* media_query ]*
5
+ # media_query [ ',' S* media_query ]*
6
6
  class QueryList
7
7
  # The queries contained in this list.
8
8
  #
@@ -43,11 +43,11 @@ module Sass::Media
43
43
  end
44
44
 
45
45
  # Returns a representation of the query as an array of strings and
46
- # potentially {Sass::Script::Node}s (if there's interpolation in it). When
47
- # the interpolation is resolved and the strings are joined together, this
48
- # will be the string representation of this query.
46
+ # potentially {Sass::Script::Tree::Node}s (if there's interpolation in it).
47
+ # When the interpolation is resolved and the strings are joined together,
48
+ # this will be the string representation of this query.
49
49
  #
50
- # @return [Array<String, Sass::Script::Node>]
50
+ # @return [Array<String, Sass::Script::Tree::Node>]
51
51
  def to_a
52
52
  Sass::Util.intersperse(queries.map {|q| q.to_a}, ', ').flatten
53
53
  end
@@ -62,7 +62,7 @@ module Sass::Media
62
62
 
63
63
  # A single media query.
64
64
  #
65
- # [ [ONLY | NOT]? S* media_type S* | expression ] [ AND S* expression ]*
65
+ # [ [ONLY | NOT]? S* media_type S* | expression ] [ AND S* expression ]*
66
66
  class Query
67
67
  # The modifier for the query.
68
68
  #
@@ -70,7 +70,7 @@ module Sass::Media
70
70
  # parsed as CSS, it contains a single string (accessible via
71
71
  # \{#resolved_modifier}).
72
72
  #
73
- # @return [Array<String, Sass::Script::Node>]
73
+ # @return [Array<String, Sass::Script::Tree::Node>]
74
74
  attr_accessor :modifier
75
75
 
76
76
  # The type of the query (e.g. `"screen"` or `"print"`).
@@ -79,7 +79,7 @@ module Sass::Media
79
79
  # parsed as CSS, it contains a single string (accessible via
80
80
  # \{#resolved_type}).
81
81
  #
82
- # @return [Array<String, Sass::Script::Node>]
82
+ # @return [Array<String, Sass::Script::Tree::Node>]
83
83
  attr_accessor :type
84
84
 
85
85
  # The trailing expressions in the query.
@@ -87,12 +87,12 @@ module Sass::Media
87
87
  # When parsed as Sass code, each expression contains strings and SassScript
88
88
  # nodes. When parsed as CSS, each one contains a single string.
89
89
  #
90
- # @return [Array<Array<String, Sass::Script::Node>>]
90
+ # @return [Array<Array<String, Sass::Script::Tree::Node>>]
91
91
  attr_accessor :expressions
92
92
 
93
- # @param modifier [Array<String, Sass::Script::Node>] See \{#modifier}
94
- # @param type [Array<String, Sass::Script::Node>] See \{#type}
95
- # @param expressions [Array<Array<String, Sass::Script::Node>>] See \{#expressions}
93
+ # @param modifier [Array<String, Sass::Script::Tree::Node>] See \{#modifier}
94
+ # @param type [Array<String, Sass::Script::Tree::Node>] See \{#type}
95
+ # @param expressions [Array<Array<String, Sass::Script::Tree::Node>>] See \{#expressions}
96
96
  def initialize(modifier, type, expressions)
97
97
  @modifier = modifier
98
98
  @type = type
@@ -125,7 +125,7 @@ module Sass::Media
125
125
  m2, t2 = other.resolved_modifier.downcase, other.resolved_type.downcase
126
126
  t1 = t2 if t1.empty?
127
127
  t2 = t1 if t2.empty?
128
- if ((m1 == 'not') ^ (m2 == 'not'))
128
+ if (m1 == 'not') ^ (m2 == 'not')
129
129
  return if t1 == t2
130
130
  type = m1 == 'not' ? t2 : t1
131
131
  mod = m1 == 'not' ? m2 : m1
@@ -140,7 +140,7 @@ module Sass::Media
140
140
  type = t1
141
141
  mod = m1.empty? ? m2 : m1
142
142
  end
143
- return Query.new([mod], [type], other.expressions + expressions)
143
+ Query.new([mod], [type], other.expressions + expressions)
144
144
  end
145
145
 
146
146
  # Returns the CSS for the media query.
@@ -156,7 +156,7 @@ module Sass::Media
156
156
  # It's possible for there to be script nodes in Expressions even when
157
157
  # we're converting to CSS in the case where we parsed the document as
158
158
  # CSS originally (as in css_test.rb).
159
- e.map {|c| c.is_a?(Sass::Script::Node) ? c.to_sass : c.to_s}.join
159
+ e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.to_sass : c.to_s}.join
160
160
  end.join(' and ')
161
161
  css
162
162
  end
@@ -193,21 +193,18 @@ module Sass::Media
193
193
  # @return [Query]
194
194
  def deep_copy
195
195
  Query.new(
196
- modifier.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c},
197
- type.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c},
198
- expressions.map {|e| e.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c}})
196
+ modifier.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
197
+ type.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
198
+ expressions.map {|e| e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c}})
199
199
  end
200
200
  end
201
201
 
202
202
  # Converts an interpolation array to source.
203
203
  #
204
- # @param [Array<String, Sass::Script::Node>] The interpolation array to convert.
204
+ # @param interp [Array<String, Sass::Script::Tree::Node>] The interpolation array to convert.
205
205
  # @param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}).
206
206
  # @return [String]
207
207
  def self._interp_to_src(interp, options)
208
- interp.map do |r|
209
- next r if r.is_a?(String)
210
- "\#{#{r.to_sass(options)}}"
211
- end.join
208
+ interp.map {|r| r.is_a?(String) ? r : r.to_sass(options)}.join
212
209
  end
213
210
  end