sass 3.4.25 → 3.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/CODE_OF_CONDUCT.md +1 -1
  3. data/CONTRIBUTING.md +3 -3
  4. data/README.md +17 -9
  5. data/VERSION +1 -1
  6. data/VERSION_DATE +1 -1
  7. data/VERSION_NAME +1 -1
  8. data/extra/sass-spec-ref.sh +9 -1
  9. data/lib/sass.rb +0 -7
  10. data/lib/sass/cache_stores/filesystem.rb +1 -1
  11. data/lib/sass/css.rb +1 -2
  12. data/lib/sass/engine.rb +39 -29
  13. data/lib/sass/environment.rb +26 -5
  14. data/lib/sass/error.rb +2 -2
  15. data/lib/sass/exec/base.rb +2 -13
  16. data/lib/sass/exec/sass_scss.rb +1 -5
  17. data/lib/sass/features.rb +1 -0
  18. data/lib/sass/importers/filesystem.rb +6 -4
  19. data/lib/sass/logger/base.rb +11 -0
  20. data/lib/sass/plugin/compiler.rb +20 -50
  21. data/lib/sass/plugin/configuration.rb +2 -2
  22. data/lib/sass/railtie.rb +1 -1
  23. data/lib/sass/script/css_parser.rb +4 -1
  24. data/lib/sass/script/functions.rb +308 -81
  25. data/lib/sass/script/lexer.rb +63 -9
  26. data/lib/sass/script/parser.rb +287 -118
  27. data/lib/sass/script/tree/funcall.rb +35 -34
  28. data/lib/sass/script/tree/interpolation.rb +0 -3
  29. data/lib/sass/script/tree/list_literal.rb +23 -8
  30. data/lib/sass/script/tree/map_literal.rb +2 -2
  31. data/lib/sass/script/tree/node.rb +0 -8
  32. data/lib/sass/script/tree/operation.rb +1 -8
  33. data/lib/sass/script/value.rb +2 -0
  34. data/lib/sass/script/value/arg_list.rb +1 -1
  35. data/lib/sass/script/value/base.rb +17 -0
  36. data/lib/sass/script/value/callable.rb +25 -0
  37. data/lib/sass/script/value/color.rb +8 -2
  38. data/lib/sass/script/value/function.rb +19 -0
  39. data/lib/sass/script/value/helpers.rb +37 -11
  40. data/lib/sass/script/value/list.rb +35 -14
  41. data/lib/sass/script/value/map.rb +2 -2
  42. data/lib/sass/script/value/number.rb +3 -2
  43. data/lib/sass/scss/css_parser.rb +6 -1
  44. data/lib/sass/scss/parser.rb +145 -56
  45. data/lib/sass/scss/rx.rb +5 -11
  46. data/lib/sass/scss/static_parser.rb +20 -42
  47. data/lib/sass/selector.rb +4 -0
  48. data/lib/sass/selector/abstract_sequence.rb +7 -6
  49. data/lib/sass/selector/comma_sequence.rb +9 -5
  50. data/lib/sass/selector/pseudo.rb +20 -3
  51. data/lib/sass/selector/sequence.rb +35 -10
  52. data/lib/sass/selector/simple.rb +9 -2
  53. data/lib/sass/selector/simple_sequence.rb +8 -4
  54. data/lib/sass/source/map.rb +2 -6
  55. data/lib/sass/stack.rb +21 -1
  56. data/lib/sass/tree/charset_node.rb +1 -1
  57. data/lib/sass/tree/prop_node.rb +45 -53
  58. data/lib/sass/tree/rule_node.rb +6 -8
  59. data/lib/sass/tree/visitors/check_nesting.rb +1 -1
  60. data/lib/sass/tree/visitors/convert.rb +2 -3
  61. data/lib/sass/tree/visitors/cssize.rb +4 -15
  62. data/lib/sass/tree/visitors/deep_copy.rb +1 -1
  63. data/lib/sass/tree/visitors/extend.rb +2 -8
  64. data/lib/sass/tree/visitors/perform.rb +23 -15
  65. data/lib/sass/tree/visitors/set_options.rb +1 -1
  66. data/lib/sass/tree/visitors/to_css.rb +49 -22
  67. data/lib/sass/util.rb +72 -310
  68. data/lib/sass/util/multibyte_string_scanner.rb +127 -131
  69. data/lib/sass/util/normalized_map.rb +1 -8
  70. data/lib/sass/version.rb +0 -4
  71. metadata +55 -202
  72. data/Rakefile +0 -453
  73. data/lib/sass/script/css_variable_warning.rb +0 -52
  74. data/lib/sass/util/cross_platform_random.rb +0 -19
  75. data/lib/sass/util/ordered_hash.rb +0 -192
  76. data/test/sass-spec.yml +0 -3
  77. data/test/sass/cache_test.rb +0 -131
  78. data/test/sass/callbacks_test.rb +0 -61
  79. data/test/sass/compiler_test.rb +0 -236
  80. data/test/sass/conversion_test.rb +0 -2188
  81. data/test/sass/css2sass_test.rb +0 -526
  82. data/test/sass/css_variable_test.rb +0 -132
  83. data/test/sass/data/hsl-rgb.txt +0 -319
  84. data/test/sass/encoding_test.rb +0 -219
  85. data/test/sass/engine_test.rb +0 -3447
  86. data/test/sass/exec_test.rb +0 -96
  87. data/test/sass/extend_test.rb +0 -1733
  88. data/test/sass/fixtures/test_staleness_check_across_importers.css +0 -1
  89. data/test/sass/fixtures/test_staleness_check_across_importers.scss +0 -1
  90. data/test/sass/functions_test.rb +0 -1977
  91. data/test/sass/importer_test.rb +0 -421
  92. data/test/sass/logger_test.rb +0 -58
  93. data/test/sass/mock_importer.rb +0 -49
  94. data/test/sass/more_results/more1.css +0 -9
  95. data/test/sass/more_results/more1_with_line_comments.css +0 -26
  96. data/test/sass/more_results/more_import.css +0 -29
  97. data/test/sass/more_templates/_more_partial.sass +0 -2
  98. data/test/sass/more_templates/more1.sass +0 -23
  99. data/test/sass/more_templates/more_import.sass +0 -11
  100. data/test/sass/plugin_test.rb +0 -556
  101. data/test/sass/results/alt.css +0 -4
  102. data/test/sass/results/basic.css +0 -9
  103. data/test/sass/results/cached_import_option.css +0 -3
  104. data/test/sass/results/compact.css +0 -5
  105. data/test/sass/results/complex.css +0 -86
  106. data/test/sass/results/compressed.css +0 -1
  107. data/test/sass/results/expanded.css +0 -19
  108. data/test/sass/results/filename_fn.css +0 -3
  109. data/test/sass/results/if.css +0 -3
  110. data/test/sass/results/import.css +0 -31
  111. data/test/sass/results/import_charset.css +0 -5
  112. data/test/sass/results/import_charset_1_8.css +0 -5
  113. data/test/sass/results/import_charset_ibm866.css +0 -5
  114. data/test/sass/results/import_content.css +0 -1
  115. data/test/sass/results/line_numbers.css +0 -49
  116. data/test/sass/results/mixins.css +0 -95
  117. data/test/sass/results/multiline.css +0 -24
  118. data/test/sass/results/nested.css +0 -22
  119. data/test/sass/results/options.css +0 -1
  120. data/test/sass/results/parent_ref.css +0 -13
  121. data/test/sass/results/script.css +0 -16
  122. data/test/sass/results/scss_import.css +0 -31
  123. data/test/sass/results/scss_importee.css +0 -2
  124. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  125. data/test/sass/results/subdir/subdir.css +0 -3
  126. data/test/sass/results/units.css +0 -11
  127. data/test/sass/results/warn.css +0 -0
  128. data/test/sass/results/warn_imported.css +0 -0
  129. data/test/sass/script_conversion_test.rb +0 -357
  130. data/test/sass/script_test.rb +0 -1431
  131. data/test/sass/scss/css_test.rb +0 -1281
  132. data/test/sass/scss/rx_test.rb +0 -160
  133. data/test/sass/scss/scss_test.rb +0 -4205
  134. data/test/sass/scss/test_helper.rb +0 -37
  135. data/test/sass/source_map_test.rb +0 -1055
  136. data/test/sass/superselector_test.rb +0 -210
  137. data/test/sass/templates/_cached_import_option_partial.scss +0 -1
  138. data/test/sass/templates/_double_import_loop2.sass +0 -1
  139. data/test/sass/templates/_filename_fn_import.scss +0 -11
  140. data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
  141. data/test/sass/templates/_imported_charset_utf8.sass +0 -4
  142. data/test/sass/templates/_imported_content.sass +0 -3
  143. data/test/sass/templates/_partial.sass +0 -2
  144. data/test/sass/templates/_same_name_different_partiality.scss +0 -1
  145. data/test/sass/templates/alt.sass +0 -16
  146. data/test/sass/templates/basic.sass +0 -23
  147. data/test/sass/templates/bork1.sass +0 -2
  148. data/test/sass/templates/bork2.sass +0 -2
  149. data/test/sass/templates/bork3.sass +0 -2
  150. data/test/sass/templates/bork4.sass +0 -2
  151. data/test/sass/templates/bork5.sass +0 -3
  152. data/test/sass/templates/cached_import_option.scss +0 -3
  153. data/test/sass/templates/compact.sass +0 -17
  154. data/test/sass/templates/complex.sass +0 -305
  155. data/test/sass/templates/compressed.sass +0 -15
  156. data/test/sass/templates/double_import_loop1.sass +0 -1
  157. data/test/sass/templates/expanded.sass +0 -17
  158. data/test/sass/templates/filename_fn.scss +0 -18
  159. data/test/sass/templates/if.sass +0 -11
  160. data/test/sass/templates/import.sass +0 -12
  161. data/test/sass/templates/import_charset.sass +0 -9
  162. data/test/sass/templates/import_charset_1_8.sass +0 -6
  163. data/test/sass/templates/import_charset_ibm866.sass +0 -11
  164. data/test/sass/templates/import_content.sass +0 -4
  165. data/test/sass/templates/importee.less +0 -2
  166. data/test/sass/templates/importee.sass +0 -19
  167. data/test/sass/templates/line_numbers.sass +0 -13
  168. data/test/sass/templates/mixin_bork.sass +0 -5
  169. data/test/sass/templates/mixins.sass +0 -76
  170. data/test/sass/templates/multiline.sass +0 -20
  171. data/test/sass/templates/nested.sass +0 -25
  172. data/test/sass/templates/nested_bork1.sass +0 -2
  173. data/test/sass/templates/nested_bork2.sass +0 -2
  174. data/test/sass/templates/nested_bork3.sass +0 -2
  175. data/test/sass/templates/nested_bork4.sass +0 -2
  176. data/test/sass/templates/nested_import.sass +0 -2
  177. data/test/sass/templates/nested_mixin_bork.sass +0 -6
  178. data/test/sass/templates/options.sass +0 -2
  179. data/test/sass/templates/parent_ref.sass +0 -25
  180. data/test/sass/templates/same_name_different_ext.sass +0 -2
  181. data/test/sass/templates/same_name_different_ext.scss +0 -1
  182. data/test/sass/templates/same_name_different_partiality.scss +0 -1
  183. data/test/sass/templates/script.sass +0 -101
  184. data/test/sass/templates/scss_import.scss +0 -12
  185. data/test/sass/templates/scss_importee.scss +0 -1
  186. data/test/sass/templates/single_import_loop.sass +0 -1
  187. data/test/sass/templates/subdir/import_up1.scss +0 -1
  188. data/test/sass/templates/subdir/import_up2.scss +0 -1
  189. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  190. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  191. data/test/sass/templates/subdir/subdir.sass +0 -6
  192. data/test/sass/templates/units.sass +0 -11
  193. data/test/sass/templates/warn.sass +0 -3
  194. data/test/sass/templates/warn_imported.sass +0 -4
  195. data/test/sass/test_helper.rb +0 -8
  196. data/test/sass/util/multibyte_string_scanner_test.rb +0 -155
  197. data/test/sass/util/normalized_map_test.rb +0 -51
  198. data/test/sass/util/subset_map_test.rb +0 -91
  199. data/test/sass/util_test.rb +0 -438
  200. data/test/sass/value_helpers_test.rb +0 -179
  201. data/test/test_helper.rb +0 -110
  202. data/vendor/listen/CHANGELOG.md +0 -1
  203. data/vendor/listen/CONTRIBUTING.md +0 -38
  204. data/vendor/listen/Gemfile +0 -20
  205. data/vendor/listen/Guardfile +0 -8
  206. data/vendor/listen/LICENSE +0 -20
  207. data/vendor/listen/README.md +0 -349
  208. data/vendor/listen/Rakefile +0 -5
  209. data/vendor/listen/Vagrantfile +0 -96
  210. data/vendor/listen/lib/listen.rb +0 -54
  211. data/vendor/listen/lib/listen/adapter.rb +0 -327
  212. data/vendor/listen/lib/listen/adapters/bsd.rb +0 -75
  213. data/vendor/listen/lib/listen/adapters/darwin.rb +0 -48
  214. data/vendor/listen/lib/listen/adapters/linux.rb +0 -81
  215. data/vendor/listen/lib/listen/adapters/polling.rb +0 -58
  216. data/vendor/listen/lib/listen/adapters/windows.rb +0 -91
  217. data/vendor/listen/lib/listen/directory_record.rb +0 -406
  218. data/vendor/listen/lib/listen/listener.rb +0 -323
  219. data/vendor/listen/lib/listen/turnstile.rb +0 -32
  220. data/vendor/listen/lib/listen/version.rb +0 -3
  221. data/vendor/listen/listen.gemspec +0 -28
  222. data/vendor/listen/spec/listen/adapter_spec.rb +0 -149
  223. data/vendor/listen/spec/listen/adapters/bsd_spec.rb +0 -36
  224. data/vendor/listen/spec/listen/adapters/darwin_spec.rb +0 -37
  225. data/vendor/listen/spec/listen/adapters/linux_spec.rb +0 -47
  226. data/vendor/listen/spec/listen/adapters/polling_spec.rb +0 -68
  227. data/vendor/listen/spec/listen/adapters/windows_spec.rb +0 -30
  228. data/vendor/listen/spec/listen/directory_record_spec.rb +0 -1250
  229. data/vendor/listen/spec/listen/listener_spec.rb +0 -258
  230. data/vendor/listen/spec/listen/turnstile_spec.rb +0 -56
  231. data/vendor/listen/spec/listen_spec.rb +0 -67
  232. data/vendor/listen/spec/spec_helper.rb +0 -25
  233. data/vendor/listen/spec/support/adapter_helper.rb +0 -666
  234. data/vendor/listen/spec/support/directory_record_helper.rb +0 -57
  235. data/vendor/listen/spec/support/fixtures_helper.rb +0 -29
  236. data/vendor/listen/spec/support/listeners_helper.rb +0 -179
  237. data/vendor/listen/spec/support/platform_helper.rb +0 -15
@@ -1,49 +0,0 @@
1
- class MockImporter < Sass::Importers::Base
2
- def initialize(name = "mock")
3
- @name = name
4
- @imports = Hash.new({})
5
- end
6
-
7
- def find_relative(uri, base, options)
8
- nil
9
- end
10
-
11
- def find(uri, options)
12
- contents = @imports[uri][:contents]
13
- return unless contents
14
- options[:syntax] = @imports[uri][:syntax]
15
- options[:filename] = uri
16
- options[:importer] = self
17
- @imports[uri][:engine] = Sass::Engine.new(contents, options)
18
- end
19
-
20
- def mtime(uri, options)
21
- @imports[uri][:mtime]
22
- end
23
-
24
- def key(uri, options)
25
- ["mock", uri]
26
- end
27
-
28
- def to_s
29
- @name
30
- end
31
-
32
- # Methods for testing
33
-
34
- def add_import(uri, contents, syntax = :scss, mtime = Time.now - 10)
35
- @imports[uri] = {
36
- :contents => contents,
37
- :mtime => mtime,
38
- :syntax => syntax
39
- }
40
- end
41
-
42
- def touch(uri)
43
- @imports[uri][:mtime] = Time.now
44
- end
45
-
46
- def engine(uri)
47
- @imports[uri][:engine]
48
- end
49
- end
@@ -1,9 +0,0 @@
1
- body { font: Arial; background: blue; }
2
-
3
- #page { width: 700px; height: 100; }
4
- #page #header { height: 300px; }
5
- #page #header h1 { font-size: 50px; color: blue; }
6
-
7
- #content.user.show #container.top #column.left { width: 100px; }
8
- #content.user.show #container.top #column.right { width: 600px; }
9
- #content.user.show #container.bottom { background: brown; }
@@ -1,26 +0,0 @@
1
- /* line 3, ../more_templates/more1.sass */
2
- body {
3
- font: Arial;
4
- background: blue; }
5
-
6
- /* line 7, ../more_templates/more1.sass */
7
- #page {
8
- width: 700px;
9
- height: 100; }
10
- /* line 10, ../more_templates/more1.sass */
11
- #page #header {
12
- height: 300px; }
13
- /* line 12, ../more_templates/more1.sass */
14
- #page #header h1 {
15
- font-size: 50px;
16
- color: blue; }
17
-
18
- /* line 18, ../more_templates/more1.sass */
19
- #content.user.show #container.top #column.left {
20
- width: 100px; }
21
- /* line 20, ../more_templates/more1.sass */
22
- #content.user.show #container.top #column.right {
23
- width: 600px; }
24
- /* line 22, ../more_templates/more1.sass */
25
- #content.user.show #container.bottom {
26
- background: brown; }
@@ -1,29 +0,0 @@
1
- @import url(basic.css);
2
- @import url(../results/complex.css);
3
- imported { otherconst: hello; myconst: goodbye; pre-mixin: here; }
4
-
5
- body { font: Arial; background: blue; }
6
-
7
- #page { width: 700px; height: 100; }
8
- #page #header { height: 300px; }
9
- #page #header h1 { font-size: 50px; color: blue; }
10
-
11
- #content.user.show #container.top #column.left { width: 100px; }
12
- #content.user.show #container.top #column.right { width: 600px; }
13
- #content.user.show #container.bottom { background: brown; }
14
-
15
- midrule { inthe: middle; }
16
-
17
- body { font: Arial; background: blue; }
18
-
19
- #page { width: 700px; height: 100; }
20
- #page #header { height: 300px; }
21
- #page #header h1 { font-size: 50px; color: blue; }
22
-
23
- #content.user.show #container.top #column.left { width: 100px; }
24
- #content.user.show #container.top #column.right { width: 600px; }
25
- #content.user.show #container.bottom { background: brown; }
26
-
27
- #foo { background-color: #baf; }
28
-
29
- nonimported { myconst: hello; otherconst: goodbye; post-mixin: here; }
@@ -1,2 +0,0 @@
1
- #foo
2
- :background-color #baf
@@ -1,23 +0,0 @@
1
-
2
-
3
- body
4
- font: Arial
5
- background: blue
6
-
7
- #page
8
- width: 700px
9
- height: 100
10
- #header
11
- height: 300px
12
- h1
13
- font-size: 50px
14
- color: blue
15
-
16
- #content.user.show
17
- #container.top
18
- #column.left
19
- width: 100px
20
- #column.right
21
- width: 600px
22
- #container.bottom
23
- background: brown
@@ -1,11 +0,0 @@
1
- $preconst: hello
2
-
3
- =premixin
4
- pre-mixin: here
5
-
6
- @import importee, basic, basic.css, ../results/complex.css, more_partial
7
-
8
- nonimported
9
- myconst: $preconst
10
- otherconst: $postconst
11
- +postmixin
@@ -1,556 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../test_helper'
3
- require File.dirname(__FILE__) + '/test_helper'
4
- require 'sass/plugin'
5
- require 'fileutils'
6
-
7
- module Sass::Script::Functions
8
- def filename
9
- filename = options[:filename].gsub(%r{.*((/[^/]+){4})}, '\1')
10
- Sass::Script::Value::String.new(filename)
11
- end
12
-
13
- def whatever
14
- custom = options[:custom]
15
- whatever = custom && custom[:whatever]
16
- Sass::Script::Value::String.new(whatever || "incorrect")
17
- end
18
- end
19
-
20
- class SassPluginTest < MiniTest::Test
21
- @@templates = %w{
22
- complex script parent_ref import scss_import alt
23
- subdir/subdir subdir/nested_subdir/nested_subdir
24
- options import_content filename_fn
25
- }
26
- @@templates += %w[import_charset import_charset_ibm866] unless Sass::Util.ruby1_8?
27
- @@templates << 'import_charset_1_8' if Sass::Util.ruby1_8?
28
-
29
- @@cache_store = Sass::CacheStores::Memory.new
30
-
31
- def setup
32
- Sass::Util.retry_on_windows {FileUtils.mkdir_p tempfile_loc}
33
- Sass::Util.retry_on_windows {FileUtils.mkdir_p tempfile_loc(nil,"more_")}
34
- set_plugin_opts
35
- check_for_updates!
36
- reset_mtimes
37
- end
38
-
39
- def teardown
40
- clean_up_sassc
41
- Sass::Plugin.reset!
42
- Sass::Util.retry_on_windows {FileUtils.rm_r tempfile_loc}
43
- Sass::Util.retry_on_windows {FileUtils.rm_r tempfile_loc(nil,"more_")}
44
- end
45
-
46
- @@templates.each do |name|
47
- define_method("test_template_renders_correctly (#{name})") do
48
- silence_warnings {assert_renders_correctly(name)}
49
- end
50
- end
51
-
52
- def test_no_update
53
- File.delete(tempfile_loc('basic'))
54
- assert_needs_update 'basic'
55
- check_for_updates!
56
- assert_stylesheet_updated 'basic'
57
- end
58
-
59
- def test_update_needed_when_modified
60
- touch 'basic'
61
- assert_needs_update 'basic'
62
- check_for_updates!
63
- assert_stylesheet_updated 'basic'
64
- end
65
-
66
- def test_update_needed_when_dependency_modified
67
- touch 'basic'
68
- assert_needs_update 'import'
69
- check_for_updates!
70
- assert_stylesheet_updated 'basic'
71
- assert_stylesheet_updated 'import'
72
- end
73
-
74
- def test_update_needed_when_scss_dependency_modified
75
- touch 'scss_importee'
76
- assert_needs_update 'import'
77
- check_for_updates!
78
- assert_stylesheet_updated 'scss_importee'
79
- assert_stylesheet_updated 'import'
80
- end
81
-
82
- def test_scss_update_needed_when_dependency_modified
83
- touch 'basic'
84
- assert_needs_update 'scss_import'
85
- check_for_updates!
86
- assert_stylesheet_updated 'basic'
87
- assert_stylesheet_updated 'scss_import'
88
- end
89
-
90
- def test_update_needed_when_nested_import_dependency_modified
91
- touch 'basic'
92
- assert_needs_update 'nested_import'
93
- check_for_updates!
94
- assert_stylesheet_updated 'basic'
95
- assert_stylesheet_updated 'scss_import'
96
- end
97
-
98
- def test_no_updates_when_always_check_and_always_update_both_false
99
- Sass::Plugin.options[:always_update] = false
100
- Sass::Plugin.options[:always_check] = false
101
-
102
- touch 'basic'
103
- assert_needs_update 'basic'
104
- check_for_updates!
105
-
106
- # Check it's still stale
107
- assert_needs_update 'basic'
108
- end
109
-
110
- def test_full_exception_handling
111
- File.delete(tempfile_loc('bork1'))
112
- check_for_updates!
113
- File.open(tempfile_loc('bork1')) do |file|
114
- assert_equal(<<CSS.strip, file.read.split("\n")[0...6].join("\n"))
115
- /*
116
- Error: Undefined variable: "$bork".
117
- on line 2 of #{template_loc('bork1')}
118
-
119
- 1: bork
120
- 2: bork: $bork
121
- CSS
122
- end
123
- File.delete(tempfile_loc('bork1'))
124
- end
125
-
126
- def test_full_exception_with_block_comment
127
- File.delete(tempfile_loc('bork5'))
128
- check_for_updates!
129
- File.open(tempfile_loc('bork5')) do |file|
130
- assert_equal(<<CSS.strip, file.read.split("\n")[0...7].join("\n"))
131
- /*
132
- Error: Undefined variable: "$bork".
133
- on line 3 of #{template_loc('bork5')}
134
-
135
- 1: bork
136
- 2: /* foo *\\/
137
- 3: bork: $bork
138
- CSS
139
- end
140
- File.delete(tempfile_loc('bork1'))
141
- end
142
-
143
- def test_single_level_import_loop
144
- File.delete(tempfile_loc('single_import_loop'))
145
- check_for_updates!
146
- File.open(tempfile_loc('single_import_loop')) do |file|
147
- assert_equal(<<CSS.strip, file.read.split("\n")[0...2].join("\n"))
148
- /*
149
- Error: An @import loop has been found: #{template_loc('single_import_loop')} imports itself
150
- CSS
151
- end
152
- end
153
-
154
- def test_double_level_import_loop
155
- File.delete(tempfile_loc('double_import_loop1'))
156
- check_for_updates!
157
- File.open(tempfile_loc('double_import_loop1')) do |file|
158
- assert_equal(<<CSS.strip, file.read.split("\n")[0...4].join("\n"))
159
- /*
160
- Error: An @import loop has been found:
161
- #{template_loc('double_import_loop1')} imports #{template_loc('_double_import_loop2')}
162
- #{template_loc('_double_import_loop2')} imports #{template_loc('double_import_loop1')}
163
- CSS
164
- end
165
- end
166
-
167
- def test_import_name_cleanup
168
- File.delete(tempfile_loc('subdir/import_up1'))
169
- check_for_updates!
170
- File.open(tempfile_loc('subdir/import_up1')) do |file|
171
- assert_equal(<<CSS.strip, file.read.split("\n")[0...5].join("\n"))
172
- /*
173
- Error: File to import not found or unreadable: ../subdir/import_up3.scss.
174
- Load path: #{template_loc}
175
- on line 1 of #{template_loc 'subdir/import_up2'}
176
- from line 1 of #{template_loc 'subdir/import_up1'}
177
- CSS
178
- end
179
- end
180
-
181
- def test_nonfull_exception_handling
182
- old_full_exception = Sass::Plugin.options[:full_exception]
183
- Sass::Plugin.options[:full_exception] = false
184
-
185
- File.delete(tempfile_loc('bork1'))
186
- assert_raises(Sass::SyntaxError) {check_for_updates!}
187
- ensure
188
- Sass::Plugin.options[:full_exception] = old_full_exception
189
- end
190
-
191
- def test_two_template_directories
192
- set_plugin_opts :template_location => {
193
- template_loc => tempfile_loc,
194
- template_loc(nil,'more_') => tempfile_loc(nil,'more_')
195
- }
196
- check_for_updates!
197
- ['more1', 'more_import'].each { |name| assert_renders_correctly(name, :prefix => 'more_') }
198
- end
199
-
200
- def test_two_template_directories_with_line_annotations
201
- set_plugin_opts :line_comments => true,
202
- :style => :nested,
203
- :template_location => {
204
- template_loc => tempfile_loc,
205
- template_loc(nil,'more_') => tempfile_loc(nil,'more_')
206
- }
207
- check_for_updates!
208
- assert_renders_correctly('more1_with_line_comments', 'more1', :prefix => 'more_')
209
- end
210
-
211
- def test_doesnt_render_partials
212
- assert !File.exist?(tempfile_loc('_partial'))
213
- end
214
-
215
- def test_template_location_array
216
- assert_equal [[template_loc, tempfile_loc]], Sass::Plugin.template_location_array
217
- end
218
-
219
- def test_add_template_location
220
- Sass::Plugin.add_template_location(template_loc(nil, "more_"), tempfile_loc(nil, "more_"))
221
- assert_equal(
222
- [[template_loc, tempfile_loc], [template_loc(nil, "more_"), tempfile_loc(nil, "more_")]],
223
- Sass::Plugin.template_location_array)
224
-
225
- touch 'more1', 'more_'
226
- touch 'basic'
227
- assert_needs_update "more1", "more_"
228
- assert_needs_update "basic"
229
- check_for_updates!
230
- assert_doesnt_need_update "more1", "more_"
231
- assert_doesnt_need_update "basic"
232
- end
233
-
234
- def test_remove_template_location
235
- Sass::Plugin.add_template_location(template_loc(nil, "more_"), tempfile_loc(nil, "more_"))
236
- Sass::Plugin.remove_template_location(template_loc, tempfile_loc)
237
- assert_equal(
238
- [[template_loc(nil, "more_"), tempfile_loc(nil, "more_")]],
239
- Sass::Plugin.template_location_array)
240
-
241
- touch 'more1', 'more_'
242
- touch 'basic'
243
- assert_needs_update "more1", "more_"
244
- assert_needs_update "basic"
245
- check_for_updates!
246
- assert_doesnt_need_update "more1", "more_"
247
- assert_needs_update "basic"
248
- end
249
-
250
- def test_import_same_name
251
- assert_warning <<WARNING do
252
- WARNING: In #{template_loc}:
253
- There are multiple files that match the name "same_name_different_partiality.scss":
254
- _same_name_different_partiality.scss
255
- same_name_different_partiality.scss
256
- WARNING
257
- touch "_same_name_different_partiality"
258
- assert_needs_update "same_name_different_partiality"
259
- end
260
- end
261
-
262
- # Callbacks
263
-
264
- def test_updated_stylesheet_callback_for_updated_template
265
- Sass::Plugin.options[:always_update] = false
266
- touch 'basic'
267
- assert_no_callback :updated_stylesheet, template_loc("complex"), tempfile_loc("complex") do
268
- assert_callbacks(
269
- [:updated_stylesheet, template_loc("basic"), tempfile_loc("basic")],
270
- [:updated_stylesheet, template_loc("import"), tempfile_loc("import")])
271
- end
272
- end
273
-
274
- def test_updated_stylesheet_callback_for_fresh_template
275
- Sass::Plugin.options[:always_update] = false
276
- assert_no_callback :updated_stylesheet
277
- end
278
-
279
- def test_updated_stylesheet_callback_for_error_template
280
- Sass::Plugin.options[:always_update] = false
281
- touch 'bork1'
282
- assert_no_callback :updated_stylesheet
283
- end
284
-
285
- def test_not_updating_stylesheet_callback_for_fresh_template
286
- Sass::Plugin.options[:always_update] = false
287
- assert_callback :not_updating_stylesheet, template_loc("basic"), tempfile_loc("basic")
288
- end
289
-
290
- def test_not_updating_stylesheet_callback_for_updated_template
291
- Sass::Plugin.options[:always_update] = false
292
- assert_callback :not_updating_stylesheet, template_loc("complex"), tempfile_loc("complex") do
293
- assert_no_callbacks(
294
- [:updated_stylesheet, template_loc("basic"), tempfile_loc("basic")],
295
- [:updated_stylesheet, template_loc("import"), tempfile_loc("import")])
296
- end
297
- end
298
-
299
- def test_not_updating_stylesheet_callback_with_never_update
300
- Sass::Plugin.options[:never_update] = true
301
- assert_no_callback :not_updating_stylesheet
302
- end
303
-
304
- def test_not_updating_stylesheet_callback_for_partial
305
- Sass::Plugin.options[:always_update] = false
306
- assert_no_callback :not_updating_stylesheet, template_loc("_partial"), tempfile_loc("_partial")
307
- end
308
-
309
- def test_not_updating_stylesheet_callback_for_error
310
- Sass::Plugin.options[:always_update] = false
311
- touch 'bork1'
312
- assert_no_callback :not_updating_stylesheet, template_loc("bork1"), tempfile_loc("bork1")
313
- end
314
-
315
- def test_compilation_error_callback
316
- Sass::Plugin.options[:always_update] = false
317
- touch 'bork1'
318
- assert_callback(:compilation_error,
319
- lambda {|e| e.message == 'Undefined variable: "$bork".'},
320
- template_loc("bork1"), tempfile_loc("bork1"))
321
- end
322
-
323
- def test_compilation_error_callback_for_file_access
324
- Sass::Plugin.options[:always_update] = false
325
- assert_callback(:compilation_error,
326
- lambda {|e| e.is_a?(Errno::ENOENT)},
327
- template_loc("nonexistent"), tempfile_loc("nonexistent")) do
328
- Sass::Plugin.update_stylesheets([[template_loc("nonexistent"), tempfile_loc("nonexistent")]])
329
- end
330
- end
331
-
332
- def test_creating_directory_callback
333
- Sass::Plugin.options[:always_update] = false
334
- dir = File.join(tempfile_loc, "subdir", "nested_subdir")
335
- FileUtils.rm_r dir
336
- assert_callback :creating_directory, dir
337
- end
338
-
339
- ## Regression
340
-
341
- def test_cached_dependencies_update
342
- FileUtils.mv(template_loc("basic"), template_loc("basic", "more_"))
343
- set_plugin_opts :load_paths => [template_loc(nil, "more_")]
344
-
345
- touch 'basic', 'more_'
346
- assert_needs_update "import"
347
- check_for_updates!
348
- assert_renders_correctly("import")
349
- ensure
350
- FileUtils.mv(template_loc("basic", "more_"), template_loc("basic"))
351
- end
352
-
353
- def test_cached_relative_import
354
- old_always_update = Sass::Plugin.options[:always_update]
355
- Sass::Plugin.options[:always_update] = true
356
- check_for_updates!
357
- assert_renders_correctly('subdir/subdir')
358
- ensure
359
- Sass::Plugin.options[:always_update] = old_always_update
360
- end
361
-
362
- def test_cached_if
363
- set_plugin_opts :cache_store => Sass::CacheStores::Filesystem.new(tempfile_loc + '/cache')
364
- check_for_updates!
365
- assert_renders_correctly 'if'
366
- check_for_updates!
367
- assert_renders_correctly 'if'
368
- ensure
369
- set_plugin_opts
370
- end
371
-
372
- def test_cached_import_option
373
- set_plugin_opts :custom => {:whatever => "correct"}
374
- check_for_updates!
375
- assert_renders_correctly "cached_import_option"
376
-
377
- @@cache_store.reset!
378
- set_plugin_opts :custom => nil, :always_update => false
379
- check_for_updates!
380
- assert_renders_correctly "cached_import_option"
381
-
382
- set_plugin_opts :custom => {:whatever => "correct"}, :always_update => true
383
- check_for_updates!
384
- assert_renders_correctly "cached_import_option"
385
- ensure
386
- set_plugin_opts :custom => nil
387
- end
388
-
389
- private
390
-
391
- def assert_renders_correctly(*arguments)
392
- options = arguments.last.is_a?(Hash) ? arguments.pop : {}
393
- prefix = options[:prefix]
394
- result_name = arguments.shift
395
- tempfile_name = arguments.shift || result_name
396
-
397
- expected_str = File.read(result_loc(result_name, prefix))
398
- actual_str = File.read(tempfile_loc(tempfile_name, prefix))
399
- unless Sass::Util.ruby1_8?
400
- expected_str = expected_str.force_encoding('IBM866') if result_name == 'import_charset_ibm866'
401
- actual_str = actual_str.force_encoding('IBM866') if tempfile_name == 'import_charset_ibm866'
402
- end
403
- expected_lines = expected_str.split("\n")
404
- actual_lines = actual_str.split("\n")
405
-
406
- if actual_lines.first == "/*" && expected_lines.first != "/*"
407
- assert(false, actual_lines[0..Sass::Util.enum_with_index(actual_lines).find {|l, i| l == "*/"}.last].join("\n"))
408
- end
409
-
410
- expected_lines.zip(actual_lines).each_with_index do |pair, line|
411
- message = "template: #{result_name}\nline: #{line + 1}"
412
- assert_equal(pair.first, pair.last, message)
413
- end
414
- if expected_lines.size < actual_lines.size
415
- assert(false, "#{actual_lines.size - expected_lines.size} Trailing lines found in #{tempfile_name}.css: #{actual_lines[expected_lines.size..-1].join('\n')}")
416
- end
417
- end
418
-
419
- def assert_stylesheet_updated(name)
420
- assert_doesnt_need_update name
421
-
422
- # Make sure it isn't an exception
423
- expected_lines = File.read(result_loc(name)).split("\n")
424
- actual_lines = File.read(tempfile_loc(name)).split("\n")
425
- if actual_lines.first == "/*" && expected_lines.first != "/*"
426
- assert(false, actual_lines[0..actual_lines.enum_with_index.find {|l, i| l == "*/"}.last].join("\n"))
427
- end
428
- end
429
-
430
- def assert_callback(name, *expected_args)
431
- run = false
432
- received_args = nil
433
- Sass::Plugin.send("on_#{name}") do |*args|
434
- received_args = args
435
- run ||= expected_args.zip(received_args).all? do |ea, ra|
436
- ea.respond_to?(:call) ? ea.call(ra) : ea == ra
437
- end
438
- end
439
-
440
- if block_given?
441
- Sass::Util.silence_sass_warnings {yield}
442
- else
443
- check_for_updates!
444
- end
445
-
446
- assert run, "Expected #{name} callback to be run with arguments:\n #{expected_args.inspect}\nHowever, it got:\n #{received_args.inspect}"
447
- end
448
-
449
- def assert_no_callback(name, *unexpected_args)
450
- Sass::Plugin.send("on_#{name}") do |*a|
451
- next unless unexpected_args.empty? || a == unexpected_args
452
-
453
- msg = "Expected #{name} callback not to be run"
454
- if !unexpected_args.empty?
455
- msg << " with arguments #{unexpected_args.inspect}"
456
- elsif !a.empty?
457
- msg << ",\n was run with arguments #{a.inspect}"
458
- end
459
-
460
- flunk msg
461
- end
462
-
463
- if block_given?
464
- yield
465
- else
466
- check_for_updates!
467
- end
468
- end
469
-
470
- def assert_callbacks(*args)
471
- return check_for_updates! if args.empty?
472
- assert_callback(*args.pop) {assert_callbacks(*args)}
473
- end
474
-
475
- def assert_no_callbacks(*args)
476
- return check_for_updates! if args.empty?
477
- assert_no_callback(*args.pop) {assert_no_callbacks(*args)}
478
- end
479
-
480
- def check_for_updates!
481
- Sass::Util.silence_sass_warnings do
482
- Sass::Plugin.check_for_updates
483
- end
484
- end
485
-
486
- def assert_needs_update(*args)
487
- assert(Sass::Plugin::StalenessChecker.stylesheet_needs_update?(tempfile_loc(*args), template_loc(*args)),
488
- "Expected #{template_loc(*args)} to need an update.")
489
- end
490
-
491
- def assert_doesnt_need_update(*args)
492
- assert(!Sass::Plugin::StalenessChecker.stylesheet_needs_update?(tempfile_loc(*args), template_loc(*args)),
493
- "Expected #{template_loc(*args)} not to need an update.")
494
- end
495
-
496
- def touch(*args)
497
- FileUtils.touch(template_loc(*args))
498
- end
499
-
500
- def reset_mtimes
501
- Sass::Plugin::StalenessChecker.dependencies_cache = {}
502
- atime = Time.now
503
- mtime = Time.now - 5
504
- Dir["{#{template_loc},#{tempfile_loc}}/**/*.{css,sass,scss}"].each do |f|
505
- Sass::Util.retry_on_windows {File.utime(atime, mtime, f)}
506
- end
507
- end
508
-
509
- def template_loc(name = nil, prefix = nil)
510
- if name
511
- scss = absolutize "#{prefix}templates/#{name}.scss"
512
- File.exist?(scss) ? scss : absolutize("#{prefix}templates/#{name}.sass")
513
- else
514
- absolutize "#{prefix}templates"
515
- end
516
- end
517
-
518
- def tempfile_loc(name = nil, prefix = nil)
519
- if name
520
- absolutize "#{prefix}tmp/#{name}.css"
521
- else
522
- absolutize "#{prefix}tmp"
523
- end
524
- end
525
-
526
- def result_loc(name = nil, prefix = nil)
527
- if name
528
- absolutize "#{prefix}results/#{name}.css"
529
- else
530
- absolutize "#{prefix}results"
531
- end
532
- end
533
-
534
- def set_plugin_opts(overrides = {})
535
- Sass::Plugin.options.merge!(
536
- :template_location => template_loc,
537
- :css_location => tempfile_loc,
538
- :style => :compact,
539
- :always_update => true,
540
- :never_update => false,
541
- :full_exception => true,
542
- :cache_store => @@cache_store,
543
- :sourcemap => :none
544
- )
545
- Sass::Plugin.options.merge!(overrides)
546
- end
547
- end
548
-
549
- class Sass::Engine
550
- alias_method :old_render, :render
551
-
552
- def render
553
- raise "bork bork bork!" if @template[0] == "{bork now!}"
554
- old_render
555
- end
556
- end