haml 3.0.25 → 3.1.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (212) hide show
  1. data/.yardopts +1 -1
  2. data/CONTRIBUTING +0 -1
  3. data/EDGE_GEM_VERSION +1 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +10 -175
  6. data/Rakefile +56 -84
  7. data/VERSION +1 -1
  8. data/VERSION_NAME +1 -1
  9. data/init.rb +1 -1
  10. data/lib/haml.rb +14 -12
  11. data/lib/haml/engine.rb +1 -1
  12. data/lib/haml/exec.rb +19 -316
  13. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  14. data/lib/haml/html.rb +69 -76
  15. data/lib/haml/precompiler.rb +34 -41
  16. data/lib/haml/railtie.rb +4 -6
  17. data/lib/haml/template/plugin.rb +6 -16
  18. data/lib/haml/util.rb +91 -107
  19. data/lib/haml/version.rb +7 -0
  20. data/test/benchmark.rb +2 -9
  21. data/test/haml/engine_test.rb +195 -92
  22. data/test/haml/html2haml/erb_tests.rb +0 -14
  23. data/test/haml/util_test.rb +32 -0
  24. data/test/test_helper.rb +0 -39
  25. metadata +96 -324
  26. data/bin/css2sass +0 -13
  27. data/bin/sass +0 -8
  28. data/bin/sass-convert +0 -7
  29. data/extra/haml-mode.el +0 -753
  30. data/extra/sass-mode.el +0 -207
  31. data/lib/haml/util/subset_map.rb +0 -101
  32. data/lib/sass.rb +0 -29
  33. data/lib/sass/callbacks.rb +0 -52
  34. data/lib/sass/css.rb +0 -294
  35. data/lib/sass/engine.rb +0 -720
  36. data/lib/sass/environment.rb +0 -143
  37. data/lib/sass/error.rb +0 -198
  38. data/lib/sass/files.rb +0 -160
  39. data/lib/sass/less.rb +0 -382
  40. data/lib/sass/plugin.rb +0 -279
  41. data/lib/sass/plugin/configuration.rb +0 -221
  42. data/lib/sass/plugin/generic.rb +0 -15
  43. data/lib/sass/plugin/merb.rb +0 -37
  44. data/lib/sass/plugin/rack.rb +0 -47
  45. data/lib/sass/plugin/rails.rb +0 -32
  46. data/lib/sass/plugin/staleness_checker.rb +0 -123
  47. data/lib/sass/repl.rb +0 -58
  48. data/lib/sass/script.rb +0 -63
  49. data/lib/sass/script/bool.rb +0 -18
  50. data/lib/sass/script/color.rb +0 -491
  51. data/lib/sass/script/css_lexer.rb +0 -29
  52. data/lib/sass/script/css_parser.rb +0 -31
  53. data/lib/sass/script/funcall.rb +0 -77
  54. data/lib/sass/script/functions.rb +0 -861
  55. data/lib/sass/script/interpolation.rb +0 -70
  56. data/lib/sass/script/lexer.rb +0 -337
  57. data/lib/sass/script/literal.rb +0 -236
  58. data/lib/sass/script/node.rb +0 -112
  59. data/lib/sass/script/number.rb +0 -423
  60. data/lib/sass/script/operation.rb +0 -95
  61. data/lib/sass/script/parser.rb +0 -401
  62. data/lib/sass/script/string.rb +0 -67
  63. data/lib/sass/script/string_interpolation.rb +0 -93
  64. data/lib/sass/script/unary_operation.rb +0 -57
  65. data/lib/sass/script/variable.rb +0 -48
  66. data/lib/sass/scss.rb +0 -17
  67. data/lib/sass/scss/css_parser.rb +0 -46
  68. data/lib/sass/scss/parser.rb +0 -855
  69. data/lib/sass/scss/rx.rb +0 -126
  70. data/lib/sass/scss/sass_parser.rb +0 -11
  71. data/lib/sass/scss/script_lexer.rb +0 -15
  72. data/lib/sass/scss/script_parser.rb +0 -25
  73. data/lib/sass/scss/static_parser.rb +0 -40
  74. data/lib/sass/selector.rb +0 -361
  75. data/lib/sass/selector/abstract_sequence.rb +0 -62
  76. data/lib/sass/selector/comma_sequence.rb +0 -82
  77. data/lib/sass/selector/sequence.rb +0 -237
  78. data/lib/sass/selector/simple.rb +0 -113
  79. data/lib/sass/selector/simple_sequence.rb +0 -136
  80. data/lib/sass/tree/charset_node.rb +0 -37
  81. data/lib/sass/tree/comment_node.rb +0 -128
  82. data/lib/sass/tree/debug_node.rb +0 -36
  83. data/lib/sass/tree/directive_node.rb +0 -75
  84. data/lib/sass/tree/extend_node.rb +0 -65
  85. data/lib/sass/tree/for_node.rb +0 -55
  86. data/lib/sass/tree/if_node.rb +0 -69
  87. data/lib/sass/tree/import_node.rb +0 -102
  88. data/lib/sass/tree/mixin_def_node.rb +0 -48
  89. data/lib/sass/tree/mixin_node.rb +0 -111
  90. data/lib/sass/tree/node.rb +0 -464
  91. data/lib/sass/tree/prop_node.rb +0 -220
  92. data/lib/sass/tree/root_node.rb +0 -163
  93. data/lib/sass/tree/rule_node.rb +0 -261
  94. data/lib/sass/tree/variable_node.rb +0 -39
  95. data/lib/sass/tree/warn_node.rb +0 -42
  96. data/lib/sass/tree/while_node.rb +0 -36
  97. data/test/haml/util/subset_map_test.rb +0 -91
  98. data/test/sass/callbacks_test.rb +0 -61
  99. data/test/sass/conversion_test.rb +0 -1218
  100. data/test/sass/css2sass_test.rb +0 -364
  101. data/test/sass/data/hsl-rgb.txt +0 -319
  102. data/test/sass/engine_test.rb +0 -2267
  103. data/test/sass/extend_test.rb +0 -1348
  104. data/test/sass/functions_test.rb +0 -556
  105. data/test/sass/less_conversion_test.rb +0 -653
  106. data/test/sass/more_results/more1.css +0 -9
  107. data/test/sass/more_results/more1_with_line_comments.css +0 -26
  108. data/test/sass/more_results/more_import.css +0 -29
  109. data/test/sass/more_templates/_more_partial.sass +0 -2
  110. data/test/sass/more_templates/more1.sass +0 -23
  111. data/test/sass/more_templates/more_import.sass +0 -11
  112. data/test/sass/plugin_test.rb +0 -433
  113. data/test/sass/results/alt.css +0 -4
  114. data/test/sass/results/basic.css +0 -9
  115. data/test/sass/results/compact.css +0 -5
  116. data/test/sass/results/complex.css +0 -86
  117. data/test/sass/results/compressed.css +0 -1
  118. data/test/sass/results/expanded.css +0 -19
  119. data/test/sass/results/import.css +0 -31
  120. data/test/sass/results/import_charset.css +0 -4
  121. data/test/sass/results/import_charset_1_8.css +0 -4
  122. data/test/sass/results/import_charset_ibm866.css +0 -4
  123. data/test/sass/results/line_numbers.css +0 -49
  124. data/test/sass/results/mixins.css +0 -95
  125. data/test/sass/results/multiline.css +0 -24
  126. data/test/sass/results/nested.css +0 -22
  127. data/test/sass/results/options.css +0 -1
  128. data/test/sass/results/parent_ref.css +0 -13
  129. data/test/sass/results/script.css +0 -16
  130. data/test/sass/results/scss_import.css +0 -31
  131. data/test/sass/results/scss_importee.css +0 -2
  132. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  133. data/test/sass/results/subdir/subdir.css +0 -3
  134. data/test/sass/results/units.css +0 -11
  135. data/test/sass/results/warn.css +0 -0
  136. data/test/sass/results/warn_imported.css +0 -0
  137. data/test/sass/script_conversion_test.rb +0 -314
  138. data/test/sass/script_test.rb +0 -470
  139. data/test/sass/scss/css_test.rb +0 -916
  140. data/test/sass/scss/rx_test.rb +0 -156
  141. data/test/sass/scss/scss_test.rb +0 -1122
  142. data/test/sass/scss/test_helper.rb +0 -37
  143. data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
  144. data/test/sass/templates/_imported_charset_utf8.sass +0 -4
  145. data/test/sass/templates/_partial.sass +0 -2
  146. data/test/sass/templates/alt.sass +0 -16
  147. data/test/sass/templates/basic.sass +0 -23
  148. data/test/sass/templates/bork1.sass +0 -2
  149. data/test/sass/templates/bork2.sass +0 -2
  150. data/test/sass/templates/bork3.sass +0 -2
  151. data/test/sass/templates/bork4.sass +0 -2
  152. data/test/sass/templates/compact.sass +0 -17
  153. data/test/sass/templates/complex.sass +0 -305
  154. data/test/sass/templates/compressed.sass +0 -15
  155. data/test/sass/templates/expanded.sass +0 -17
  156. data/test/sass/templates/import.sass +0 -12
  157. data/test/sass/templates/import_charset.sass +0 -7
  158. data/test/sass/templates/import_charset_1_8.sass +0 -4
  159. data/test/sass/templates/import_charset_ibm866.sass +0 -9
  160. data/test/sass/templates/importee.less +0 -2
  161. data/test/sass/templates/importee.sass +0 -19
  162. data/test/sass/templates/line_numbers.sass +0 -13
  163. data/test/sass/templates/mixin_bork.sass +0 -5
  164. data/test/sass/templates/mixins.sass +0 -76
  165. data/test/sass/templates/multiline.sass +0 -20
  166. data/test/sass/templates/nested.sass +0 -25
  167. data/test/sass/templates/nested_bork1.sass +0 -2
  168. data/test/sass/templates/nested_bork2.sass +0 -2
  169. data/test/sass/templates/nested_bork3.sass +0 -2
  170. data/test/sass/templates/nested_bork4.sass +0 -2
  171. data/test/sass/templates/nested_mixin_bork.sass +0 -6
  172. data/test/sass/templates/options.sass +0 -2
  173. data/test/sass/templates/parent_ref.sass +0 -25
  174. data/test/sass/templates/script.sass +0 -101
  175. data/test/sass/templates/scss_import.scss +0 -11
  176. data/test/sass/templates/scss_importee.scss +0 -1
  177. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  178. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  179. data/test/sass/templates/subdir/subdir.sass +0 -6
  180. data/test/sass/templates/units.sass +0 -11
  181. data/test/sass/templates/warn.sass +0 -3
  182. data/test/sass/templates/warn_imported.sass +0 -4
  183. data/vendor/fssm/LICENSE +0 -20
  184. data/vendor/fssm/README.markdown +0 -55
  185. data/vendor/fssm/Rakefile +0 -59
  186. data/vendor/fssm/VERSION.yml +0 -5
  187. data/vendor/fssm/example.rb +0 -9
  188. data/vendor/fssm/fssm.gemspec +0 -77
  189. data/vendor/fssm/lib/fssm.rb +0 -33
  190. data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
  191. data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
  192. data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
  193. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
  194. data/vendor/fssm/lib/fssm/monitor.rb +0 -26
  195. data/vendor/fssm/lib/fssm/path.rb +0 -91
  196. data/vendor/fssm/lib/fssm/pathname.rb +0 -502
  197. data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
  198. data/vendor/fssm/lib/fssm/state/file.rb +0 -24
  199. data/vendor/fssm/lib/fssm/support.rb +0 -63
  200. data/vendor/fssm/lib/fssm/tree.rb +0 -176
  201. data/vendor/fssm/profile/prof-cache.rb +0 -40
  202. data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
  203. data/vendor/fssm/profile/prof-pathname.rb +0 -68
  204. data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
  205. data/vendor/fssm/profile/prof.html +0 -2379
  206. data/vendor/fssm/spec/path_spec.rb +0 -75
  207. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  208. data/vendor/fssm/spec/root/file.css +0 -0
  209. data/vendor/fssm/spec/root/file.rb +0 -0
  210. data/vendor/fssm/spec/root/file.yml +0 -0
  211. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  212. data/vendor/fssm/spec/spec_helper.rb +0 -14
@@ -1,221 +0,0 @@
1
- # We keep configuration in its own self-contained file
2
- # so that we can load it independently in Rails 3,
3
- # where the full plugin stuff is lazy-loaded.
4
-
5
- require 'sass/callbacks'
6
-
7
- module Sass
8
- module Plugin
9
- include Sass::Callbacks
10
- extend self
11
-
12
- # Register a callback to be run before stylesheets are mass-updated.
13
- # This is run whenever \{#update\_stylesheets} is called,
14
- # unless the \{file:SASS_REFERENCE.md#never_update-option `:never_update` option}
15
- # is enabled.
16
- #
17
- # @yield [individual_files]
18
- # @yieldparam individual_files [<(String, String)>]
19
- # Individual files to be updated, in addition to the directories
20
- # specified in the options.
21
- # The first element of each pair is the source file,
22
- # the second is the target CSS file.
23
- define_callback :updating_stylesheets
24
-
25
- # Register a callback to be run before a single stylesheet is updated.
26
- # The callback is only run if the stylesheet is guaranteed to be updated;
27
- # if the CSS file is fresh, this won't be run.
28
- #
29
- # Even if the \{file:SASS_REFERENCE.md#full_exception-option `:full_exception` option}
30
- # is enabled, this callback won't be run
31
- # when an exception CSS file is being written.
32
- # To run an action for those files, use \{#on\_compilation\_error}.
33
- #
34
- # @yield [template, css]
35
- # @yieldparam template [String]
36
- # The location of the Sass/SCSS file being updated.
37
- # @yieldparam css [String]
38
- # The location of the CSS file being generated.
39
- define_callback :updating_stylesheet
40
-
41
- # Register a callback to be run when Sass decides not to update a stylesheet.
42
- # In particular, the callback is run when Sass finds that
43
- # the template file and none of its dependencies
44
- # have been modified since the last compilation.
45
- #
46
- # Note that this is **not** run when the
47
- # \{file:SASS_REFERENCE.md#never-update_option `:never_update` option} is set,
48
- # nor when Sass decides not to compile a partial.
49
- #
50
- # @yield [template, css]
51
- # @yieldparam template [String]
52
- # The location of the Sass/SCSS file not being updated.
53
- # @yieldparam css [String]
54
- # The location of the CSS file not being generated.
55
- define_callback :not_updating_stylesheet
56
-
57
- # Register a callback to be run when there's an error
58
- # compiling a Sass file.
59
- # This could include not only errors in the Sass document,
60
- # but also errors accessing the file at all.
61
- #
62
- # @yield [error, template, css]
63
- # @yieldparam error [Exception] The exception that was raised.
64
- # @yieldparam template [String]
65
- # The location of the Sass/SCSS file being updated.
66
- # @yieldparam css [String]
67
- # The location of the CSS file being generated.
68
- define_callback :compilation_error
69
-
70
- # Register a callback to be run when Sass creates a directory
71
- # into which to put CSS files.
72
- #
73
- # Note that even if multiple levels of directories need to be created,
74
- # the callback may only be run once.
75
- # For example, if "foo/" exists and "foo/bar/baz/" needs to be created,
76
- # this may only be run for "foo/bar/baz/".
77
- # This is not a guarantee, however;
78
- # it may also be run for "foo/bar/".
79
- #
80
- # @yield [dirname]
81
- # @yieldparam dirname [String]
82
- # The location of the directory that was created.
83
- define_callback :creating_directory
84
-
85
- # Register a callback to be run when Sass detects
86
- # that a template has been modified.
87
- # This is only run when using \{#watch}.
88
- #
89
- # @yield [template]
90
- # @yieldparam template [String]
91
- # The location of the template that was modified.
92
- define_callback :template_modified
93
-
94
- # Register a callback to be run when Sass detects
95
- # that a new template has been created.
96
- # This is only run when using \{#watch}.
97
- #
98
- # @yield [template]
99
- # @yieldparam template [String]
100
- # The location of the template that was created.
101
- define_callback :template_created
102
-
103
- # Register a callback to be run when Sass detects
104
- # that a template has been deleted.
105
- # This is only run when using \{#watch}.
106
- #
107
- # @yield [template]
108
- # @yieldparam template [String]
109
- # The location of the template that was deleted.
110
- define_callback :template_deleted
111
-
112
- # Register a callback to be run when Sass deletes a CSS file.
113
- # This happens when the corresponding Sass/SCSS file has been deleted.
114
- #
115
- # @yield [filename]
116
- # @yieldparam filename [String]
117
- # The location of the CSS file that was deleted.
118
- define_callback :deleting_css
119
-
120
- @options = {:full_exception => true}
121
-
122
- # An options hash.
123
- # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
124
- #
125
- # @return [{Symbol => Object}]
126
- attr_reader :options
127
-
128
- # Sets the options hash.
129
- # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
130
- #
131
- # @param value [{Symbol => Object}] The options hash
132
- def options=(value)
133
- @options.merge!(value)
134
- end
135
-
136
- # Non-destructively modifies \{#options} so that default values are properly set.
137
- #
138
- # @param additional_options [{Symbol => Object}] An options hash with which to merge \{#options}
139
- # @return [{Symbol => Object}] The modified options hash
140
- def engine_options(additional_options = {})
141
- opts = options.dup.merge(additional_options)
142
- opts[:load_paths] = load_paths(opts)
143
- opts
144
- end
145
-
146
- # Adds a new template-location/css-location mapping.
147
- # This means that Sass/SCSS files in `template_location`
148
- # will be compiled to CSS files in `css_location`.
149
- #
150
- # This is preferred over manually manipulating the {file:SASS_REFERENCE.md#template_location-option `:template_location` option}
151
- # since the option can be in multiple formats.
152
- #
153
- # Note that this method will change `options[:template_location]`
154
- # to be in the Array format.
155
- # This means that even if `options[:template_location]`
156
- # had previously been a Hash or a String,
157
- # it will now be an Array.
158
- #
159
- # @param template_location [String] The location where Sass/SCSS files will be.
160
- # @param css_location [String] The location where compiled CSS files will go.
161
- def add_template_location(template_location, css_location = options[:css_location])
162
- normalize_template_location!
163
- template_location_array << [template_location, css_location]
164
- end
165
-
166
- # Removes a template-location/css-location mapping.
167
- # This means that Sass/SCSS files in `template_location`
168
- # will no longer be compiled to CSS files in `css_location`.
169
- #
170
- # This is preferred over manually manipulating the {file:SASS_REFERENCE.md#template_location-option `:template_location` option}
171
- # since the option can be in multiple formats.
172
- #
173
- # Note that this method will change `options[:template_location]`
174
- # to be in the Array format.
175
- # This means that even if `options[:template_location]`
176
- # had previously been a Hash or a String,
177
- # it will now be an Array.
178
- #
179
- # @param template_location [String]
180
- # The location where Sass/SCSS files were,
181
- # which is now going to be ignored.
182
- # @param css_location [String]
183
- # The location where compiled CSS files went, but will no longer go.
184
- # @return [Boolean]
185
- # Non-`nil` if the given mapping already existed and was removed,
186
- # or `nil` if nothing was changed.
187
- def remove_template_location(template_location, css_location = options[:css_location])
188
- normalize_template_location!
189
- template_location_array.delete([template_location, css_location])
190
- end
191
-
192
- # Returns the template locations configured for Sass
193
- # as an array of `[template_location, css_location]` pairs.
194
- # See the {file:SASS_REFERENCE.md#template_location-option `:template_location` option}
195
- # for details.
196
- #
197
- # @return [Array<(String, String)>]
198
- # An array of `[template_location, css_location]` pairs.
199
- def template_location_array
200
- old_template_location = options[:template_location]
201
- normalize_template_location!
202
- options[:template_location]
203
- ensure
204
- options[:template_location] = old_template_location
205
- end
206
-
207
- private
208
-
209
- def normalize_template_location!
210
- return if options[:template_location].is_a?(Array)
211
- options[:template_location] =
212
- case options[:template_location]
213
- when nil
214
- css_location = options[:css_location] || './public/stylesheets'
215
- [[File.join(css_location, 'sass'), css_location]]
216
- when String; [[options[:template_location], options[:css_location]]]
217
- else; options[:template_location].to_a
218
- end
219
- end
220
- end
221
- end
@@ -1,15 +0,0 @@
1
- # The reason some options are declared here rather than in sass/plugin/configuration.rb
2
- # is that otherwise they'd clobber the Rails-specific options.
3
- # Since Rails' options are lazy-loaded in Rails 3,
4
- # they're reverse-merged with the default options
5
- # so that user configuration is preserved.
6
- # This means that defaults that differ from Rails'
7
- # must be declared here.
8
-
9
- unless defined?(Sass::GENERIC_LOADED)
10
- Sass::GENERIC_LOADED = true
11
-
12
- Sass::Plugin.options.merge!(:css_location => './public/stylesheets',
13
- :always_update => false,
14
- :always_check => true)
15
- end
@@ -1,37 +0,0 @@
1
- unless defined?(Sass::MERB_LOADED)
2
- Sass::MERB_LOADED = true
3
-
4
- version = Merb::VERSION.split('.').map { |n| n.to_i }
5
- if version[0] <= 0 && version[1] < 5
6
- root = MERB_ROOT
7
- env = MERB_ENV
8
- else
9
- root = Merb.root.to_s
10
- env = Merb.environment
11
- end
12
-
13
- Sass::Plugin.options.merge!(:template_location => root + '/public/stylesheets/sass',
14
- :css_location => root + '/public/stylesheets',
15
- :cache_location => root + '/tmp/sass-cache',
16
- :always_check => env != "production",
17
- :quiet => env != "production",
18
- :full_exception => env != "production")
19
- config = Merb::Plugins.config[:sass] || Merb::Plugins.config["sass"] || {}
20
-
21
- if defined? config.symbolize_keys!
22
- config.symbolize_keys!
23
- end
24
-
25
- Sass::Plugin.options.merge!(config)
26
-
27
- require 'sass/plugin/rack'
28
- class Sass::Plugin::MerbBootLoader < Merb::BootLoader
29
- after Merb::BootLoader::RackUpApplication
30
-
31
- def self.run
32
- # Apparently there's no better way than this to add Sass
33
- # to Merb's Rack stack.
34
- Merb::Config[:app] = Sass::Plugin::Rack.new(Merb::Config[:app])
35
- end
36
- end
37
- end
@@ -1,47 +0,0 @@
1
- module Sass
2
- module Plugin
3
- # Rack middleware for compiling Sass code.
4
- #
5
- # ## Activate
6
- #
7
- # require 'sass/plugin/rack'
8
- # use Sass::Plugin::Rack
9
- #
10
- # ## Customize
11
- #
12
- # Sass::Plugin.options.merge(
13
- # :cache_location => './tmp/sass-cache',
14
- # :never_update => environment != :production,
15
- # :full_exception => environment != :production)
16
- #
17
- # {file:SASS_REFERENCE.md#options See the Reference for more options}.
18
- #
19
- # ## Use
20
- #
21
- # Put your Sass files in `public/stylesheets/sass`.
22
- # Your CSS will be generated in `public/stylesheets`,
23
- # and regenerated every request if necessary.
24
- # The locations and frequency {file:SASS_REFERENCE.md#options can be customized}.
25
- # That's all there is to it!
26
- class Rack
27
- # Initialize the middleware.
28
- #
29
- # @param app [#call] The Rack application
30
- def initialize(app)
31
- @app = app
32
- end
33
-
34
- # Process a request, checking the Sass stylesheets for changes
35
- # and updating them if necessary.
36
- #
37
- # @param env The Rack request environment
38
- # @return [(#to_i, {String => String}, Object)] The Rack response
39
- def call(env)
40
- Sass::Plugin.check_for_updates
41
- @app.call(env)
42
- end
43
- end
44
- end
45
- end
46
-
47
- require 'sass/plugin'
@@ -1,32 +0,0 @@
1
- unless defined?(Sass::RAILS_LOADED)
2
- Sass::RAILS_LOADED = true
3
-
4
- # Reverse-merging (we're in Rails, anyway) so we dont' clobber what's already been defined further up-stream
5
- Sass::Plugin.options.reverse_merge!(:template_location => Haml::Util.rails_root + '/public/stylesheets/sass',
6
- :css_location => Haml::Util.rails_root + '/public/stylesheets',
7
- :cache_location => Haml::Util.rails_root + '/tmp/sass-cache',
8
- :always_check => Haml::Util.rails_env == "development",
9
- :quiet => Haml::Util.rails_env != "production",
10
- :full_exception => Haml::Util.rails_env != "production")
11
-
12
- if defined?(ActionController::Metal)
13
- # Rails >= 3.0
14
- require 'sass/plugin/rack'
15
- Rails.configuration.middleware.use(Sass::Plugin::Rack)
16
- elsif defined?(ActionController::Dispatcher) &&
17
- defined?(ActionController::Dispatcher.middleware)
18
- # Rails >= 2.3
19
- require 'sass/plugin/rack'
20
- ActionController::Dispatcher.middleware.use(Sass::Plugin::Rack)
21
- else
22
- module ActionController
23
- class Base
24
- alias_method :sass_old_process, :process
25
- def process(*args)
26
- Sass::Plugin.check_for_updates
27
- sass_old_process(*args)
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,123 +0,0 @@
1
- module Sass
2
- module Plugin
3
- # The class handles `.s[ca]ss` file staleness checks via their mtime timestamps.
4
- #
5
- # To speed things up two level of caches are employed:
6
- #
7
- # * A class-level dependency cache which stores @import paths for each file.
8
- # This is a long-lived cache that is reused by every StalenessChecker instance.
9
- # * Two short-lived instance-level caches, one for file mtimes
10
- # and one for whether a file is stale during this particular run.
11
- # These are only used by a single StalenessChecker instance.
12
- #
13
- # Usage:
14
- #
15
- # * For a one-off staleness check of a single `.s[ca]ss` file,
16
- # the class-level {stylesheet_needs_update?} method
17
- # should be used.
18
- # * For a series of staleness checks (e.g. checking all files for staleness)
19
- # a StalenessChecker instance should be created,
20
- # and the instance-level \{#stylesheet\_needs\_update?} method should be used.
21
- # the caches should make the whole process significantly faster.
22
- # *WARNING*: It is important not to retain the instance for too long,
23
- # as its instance-level caches are never explicitly expired.
24
- class StalenessChecker
25
- DELETED = 1.0/0.0 # positive Infinity
26
- @dependencies_cache = {}
27
-
28
- class << self
29
- # @private
30
- attr_accessor :dependencies_cache
31
- end
32
-
33
- # Creates a new StalenessChecker
34
- # for checking the staleness of several stylesheets at once.
35
- def initialize
36
- @dependencies = self.class.dependencies_cache
37
-
38
- # Entries in the following instance-level caches are never explicitly expired.
39
- # Instead they are supposed to automaticaly go out of scope when a series of staleness checks
40
- # (this instance of StalenessChecker was created for) is finished.
41
- @mtimes, @dependencies_stale = {}, {}
42
- end
43
-
44
- # Returns whether or not a given CSS file is out of date
45
- # and needs to be regenerated.
46
- #
47
- # @param css_file [String] The location of the CSS file to check.
48
- # @param template_file [String] The location of the Sass or SCSS template
49
- # that is compiled to `css_file`.
50
- def stylesheet_needs_update?(css_file, template_file)
51
- template_file, css_mtime = File.expand_path(template_file), mtime(css_file)
52
-
53
- css_mtime == DELETED || dependency_updated?(css_mtime).call(template_file)
54
- end
55
-
56
- # Returns whether or not a given CSS file is out of date
57
- # and needs to be regenerated.
58
- #
59
- # The distinction between this method and the instance-level \{#stylesheet\_needs\_update?}
60
- # is that the instance method preserves mtime and stale-dependency caches,
61
- # so it's better to use when checking multiple stylesheets at once.
62
- #
63
- # @param css_file [String] The location of the CSS file to check.
64
- # @param template_file [String] The location of the Sass or SCSS template
65
- # that is compiled to `css_file`.
66
- def self.stylesheet_needs_update?(css_file, template_file)
67
- new.stylesheet_needs_update?(css_file, template_file)
68
- end
69
-
70
- private
71
-
72
- def dependencies_stale?(template_file, css_mtime)
73
- timestamps = @dependencies_stale[template_file] ||= {}
74
- timestamps.each_pair do |checked_css_mtime, is_stale|
75
- if checked_css_mtime <= css_mtime && !is_stale
76
- return false
77
- elsif checked_css_mtime > css_mtime && is_stale
78
- return true
79
- end
80
- end
81
- timestamps[css_mtime] = dependencies(template_file).any?(&dependency_updated?(css_mtime))
82
- end
83
-
84
- def mtime(filename)
85
- @mtimes[filename] ||= begin
86
- File.mtime(filename).to_i
87
- rescue Errno::ENOENT
88
- @dependencies.delete(filename)
89
- DELETED
90
- end
91
- end
92
-
93
- def dependencies(filename)
94
- stored_mtime, dependencies = @dependencies[filename]
95
-
96
- if !stored_mtime || stored_mtime < mtime(filename)
97
- @dependencies[filename] = [mtime(filename), dependencies = compute_dependencies(filename)]
98
- end
99
-
100
- dependencies
101
- end
102
-
103
- def dependency_updated?(css_mtime)
104
- lambda do |dep|
105
- begin
106
- mtime(dep) > css_mtime || dependencies_stale?(dep, css_mtime)
107
- rescue Sass::SyntaxError
108
- # If there's an error finding depenencies, default to recompiling.
109
- true
110
- end
111
- end
112
- end
113
-
114
- def compute_dependencies(filename)
115
- Files.tree_for(filename, Plugin.engine_options).grep(Tree::ImportNode) do |n|
116
- File.expand_path(n.full_filename) unless n.full_filename =~ /\.css$/
117
- end.compact
118
- rescue Sass::SyntaxError => e
119
- [] # If the file has an error, we assume it has no dependencies
120
- end
121
- end
122
- end
123
- end