sass 3.1.0.alpha.32 → 3.1.0.alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 3.1.0.alpha.32
1
+ 3.1.0.alpha.33
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.32
1
+ 3.1.0.alpha.33
@@ -1,4 +1,5 @@
1
1
  require 'strscan'
2
+ require 'set'
2
3
  require 'digest/sha1'
3
4
  require 'sass/cache_store'
4
5
  require 'sass/tree/node'
@@ -241,13 +242,14 @@ module Sass
241
242
  end
242
243
  alias_method :to_css, :render
243
244
 
244
- # Parses the document into its parse tree.
245
+ # Parses the document into its parse tree. Memoized.
245
246
  #
246
247
  # @return [Sass::Tree::Node] The root of the parse tree.
247
248
  # @raise [Sass::SyntaxError] if there's an error in the document
248
249
  def to_tree
249
- return _to_tree unless @options[:quiet]
250
- Sass::Util.silence_sass_warnings {_to_tree}
250
+ @tree ||= @options[:quiet] ?
251
+ Sass::Util.silence_sass_warnings {_to_tree} :
252
+ _to_tree
251
253
  end
252
254
 
253
255
  # Returns the original encoding of the document,
@@ -262,6 +264,29 @@ module Sass
262
264
  @original_encoding
263
265
  end
264
266
 
267
+ # Gets a set of all the documents
268
+ # that are (transitive) dependencies of this document,
269
+ # not including the document itself.
270
+ #
271
+ # @return [[Sass::Engine]] The dependency documents.
272
+ def dependencies
273
+ _dependencies(Set.new, engines = Set.new)
274
+ engines - [self]
275
+ end
276
+
277
+ # Helper for \{#dependencies}.
278
+ #
279
+ # @private
280
+ def _dependencies(seen, engines)
281
+ return if seen.include?(key = [@options[:filename], @options[:importer]])
282
+ seen << key
283
+ engines << self
284
+ to_tree.grep(Tree::ImportNode) do |n|
285
+ next if n.css_import?
286
+ n.imported_file._dependencies(seen, engines)
287
+ end
288
+ end
289
+
265
290
  private
266
291
 
267
292
  def _render
@@ -325,7 +350,7 @@ module Sass
325
350
  comment_tab_str = nil
326
351
  first = true
327
352
  lines = []
328
- string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^.*?$/).each_with_index do |line, index|
353
+ string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^[^\n]*?$/).each_with_index do |line, index|
329
354
  index += (@options[:line] || 1)
330
355
  if line.strip.empty?
331
356
  lines.last.text << "\n" if lines.last && lines.last.comment?
@@ -55,15 +55,16 @@ module Sass
55
55
  end
56
56
 
57
57
  def find_template(uri, prefix, partial)
58
- return @lookup_context
59
- .find_all(uri, prefix, partial)
60
- .find {|t| t.handler.is_a?(Sass::Plugin::TemplateHandler)}
58
+ return @lookup_context.
59
+ find_all(uri, prefix, partial).
60
+ find {|t| t.handler.is_a?(Sass::Plugin::TemplateHandler)}
61
61
  end
62
62
 
63
63
  def prepare_template(template, options)
64
64
  return unless template
65
65
  options[:syntax] = template.handler.syntax
66
66
  options[:filename] = template.virtual_path
67
+ options[:_rails_filename] = template.identifier
67
68
  options[:importer] = self
68
69
  Sass::Engine.new(template.source, options)
69
70
  end
@@ -4,15 +4,23 @@ unless defined?(Sass::RAILS_LOADED)
4
4
  module Sass::Plugin::Configuration
5
5
  # Different default options in a rails envirionment.
6
6
  def default_options
7
- @default_options ||= {
8
- :always_update => false,
9
- :template_location => Sass::Util.rails_root + '/public/stylesheets/sass',
10
- :css_location => Sass::Util.rails_root + '/public/stylesheets',
11
- :cache_location => Sass::Util.rails_root + '/tmp/sass-cache',
12
- :always_check => Sass::Util.rails_env == "development",
7
+ opts = {
13
8
  :quiet => Sass::Util.rails_env != "production",
14
9
  :full_exception => Sass::Util.rails_env != "production"
15
- }.freeze
10
+ }
11
+
12
+ if Sass::Util.ap_geq?('3.1.0.beta')
13
+ opts.merge!(:cache => false, :load_paths => [])
14
+ else
15
+ opts.merge!(
16
+ :always_update => false,
17
+ :template_location => Sass::Util.rails_root + '/public/stylesheets/sass',
18
+ :css_location => Sass::Util.rails_root + '/public/stylesheets',
19
+ :cache_location => Sass::Util.rails_root + '/tmp/sass-cache',
20
+ :always_check => Sass::Util.rails_env == "development")
21
+ end
22
+
23
+ @default_options ||= opts.freeze
16
24
  end
17
25
  end
18
26
 
@@ -20,7 +28,7 @@ unless defined?(Sass::RAILS_LOADED)
20
28
 
21
29
  # Disable this for now, until we figure out how to get Rails
22
30
  # to pass in the view.
23
- if false #Sass::Util.ap_geq?('3.1.0.beta')
31
+ if Sass::Util.ap_geq?('3.1.0.beta')
24
32
  require 'sass/importers/rails'
25
33
  class Sass::Plugin::TemplateHandler
26
34
  attr_reader :syntax
@@ -33,32 +41,65 @@ unless defined?(Sass::RAILS_LOADED)
33
41
 
34
42
  def call(template, view)
35
43
  rails_importer = Sass::Importers::Rails.new(view.lookup_context)
36
- tree = Sass::Engine.new(template.source,
37
- :syntax => @syntax,
38
- :cache => false,
39
- :filename => template.virtual_path,
40
- :importer => rails_importer,
41
- :load_paths => [rails_importer],
42
- ).to_tree
44
+ engine = Sass::Engine.new(template.source,
45
+ Sass::Plugin.options.merge(
46
+ :syntax => @syntax,
47
+ :filename => template.virtual_path,
48
+ :importer => rails_importer,
49
+ :load_paths => [rails_importer] + Sass::Plugin.options[:load_paths]))
50
+
51
+ # We need to serialize/deserialize the importers to make sure
52
+ # that each dependency is matched up to its proper importer
53
+ # for when importer#mtime is called.
54
+ dependencies = engine.dependencies
55
+ importers = Sass::Util.to_hash(
56
+ Sass::Util.enum_with_index(dependencies).map do |e, i|
57
+ importer = e.options[:importer]
58
+ [importer, {
59
+ :variable => "importer_#{i}",
60
+ :expression => (importer == rails_importer ?
61
+ "Sass::Importers::Rails.new(lookup_context)" :
62
+ "Sass::Util.load(#{Sass::Util.dump(importer)})")
63
+ }]
64
+ end)
65
+
66
+ stylesheet =
67
+ begin
68
+ engine.render
69
+ rescue Sass::SyntaxError => e
70
+ Sass::Plugin::TemplateHandler.munge_exception e, view.lookup_context
71
+ Sass::SyntaxError.exception_to_css(e, Sass::Plugin.options)
72
+ end
43
73
 
44
74
  <<RUBY
45
- importer = Sass::Importers::Rails.new(lookup_context)
46
- # Since we need to re-parse the template, force Rails to re-load the source.
47
- # Once we pre-compute the dependencies, we can avoid doing this
48
- # until we know we need to update the method.
49
- @_template.expire!
50
- staleness_checker = Sass::Plugin::StalenessChecker.new(
51
- Sass::Plugin.engine_options.merge(:load_paths => [importer], :cache => false))
52
- if staleness_checker.stylesheet_modified_since?(
53
- #{template.virtual_path.inspect},
54
- #{Time.now.to_i},
55
- importer)
56
- @_template.rerender(self)
57
- else
58
- #{tree.render.inspect}
75
+ begin
76
+ #{importers.map {|_, val| "#{val[:variable]} = #{val[:expression]}"}.join("\n")}
77
+ if Sass::Plugin::TemplateHandler.dependencies_changed?(
78
+ [#{dependencies.map {|e| "[#{e.options[:filename].inspect}, #{importers[e.options[:importer]][:variable]}]"}.join(',')}],
79
+ #{Time.now.to_i})
80
+ @_template.expire!
81
+ @_template.rerender(self)
82
+ else
83
+ #{stylesheet.inspect}
84
+ end
85
+ rescue Sass::SyntaxError => e
86
+ Sass::Plugin::TemplateHandler.munge_exception e, lookup_context
87
+ Sass::SyntaxError.exception_to_css(e, Sass::Plugin.options)
59
88
  end
60
89
  RUBY
61
90
  end
91
+
92
+ def self.dependencies_changed?(deps, since)
93
+ deps.any? {|d, i| i.mtime(d, Sass::Plugin.options) > since}
94
+ end
95
+
96
+ def self.munge_exception(e, lookup_context)
97
+ importer = Sass::Importers::Rails.new(lookup_context)
98
+ e.sass_backtrace.each do |bt|
99
+ next unless engine = importer.find(bt[:filename], Sass::Plugin.options)
100
+ bt[:filename] = engine.options[:_rails_filename]
101
+ end
102
+ end
62
103
  end
63
104
 
64
105
  ActionView::Template.register_template_handler(:sass, Sass::Plugin::TemplateHandler.new(:sass))
@@ -17,7 +17,7 @@ module Sass
17
17
  def to_s(*args)
18
18
  super
19
19
  rescue Sass::SyntaxError => e
20
- e.sass_template = @template
20
+ e.sass_template ||= @template
21
21
  raise e
22
22
  end
23
23
 
@@ -36,7 +36,7 @@ module Sass
36
36
  environment.options = @options if environment.options.nil? || environment.options.empty?
37
37
  super
38
38
  rescue Sass::SyntaxError => e
39
- e.sass_template = @template
39
+ e.sass_template ||= @template
40
40
  raise e
41
41
  end
42
42
 
@@ -49,7 +49,7 @@ module Sass
49
49
  def cssize(extends = Sass::Util::SubsetMap.new, parent = nil)
50
50
  return super(extends, parent), extends
51
51
  rescue Sass::SyntaxError => e
52
- e.sass_template = @template
52
+ e.sass_template ||= @template
53
53
  raise e
54
54
  end
55
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.alpha.32
4
+ version: 3.1.0.alpha.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-11-17 00:00:00 -05:00
14
+ date: 2010-11-19 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency