sass 3.1.0.alpha.29 → 3.1.0.alpha.30

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.29
1
+ 3.1.0.alpha.30
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.29
1
+ 3.1.0.alpha.30
@@ -0,0 +1,72 @@
1
+ module Sass
2
+ module Importers
3
+ # An importer that wraps the Rails 3.1 view infrastructure.
4
+ # Loads Sass files as though they were views in Rails.
5
+ # Currently doesn't support caching.
6
+ #
7
+ # This is different from standard Rails rendering
8
+ # in that Sass doesn't have a concept of importing partials
9
+ # as a distinct action from importing other Sass files.
10
+ # Imports within Rails behave more like Sass imports:
11
+ # they will first attempt to find a non-partial file,
12
+ # and failing that will fall back on a partial.
13
+ #
14
+ # Each importer instance is local to a single request for a single view.
15
+ # It contains the ActionView::LookupContext for that request,
16
+ # as well as the controller prefix for the view being generated.
17
+ class Rails < Base
18
+ # Creates a new Rails importer that imports files as Rails views.
19
+ #
20
+ # @param lookup_context [ActionView::LookupContext] The Rails view finder.
21
+ def initialize(lookup_context)
22
+ @lookup_context = lookup_context
23
+ end
24
+
25
+ # @see Base#find_relative
26
+ def find_relative(uri, base, options)
27
+ find_(uri, base.split('/')[0...-1].join('/'), options)
28
+ end
29
+
30
+ # @see Base#find
31
+ def find(uri, options)
32
+ find_(uri, nil, options)
33
+ end
34
+
35
+ # @see Base#mtime
36
+ def mtime(uri, options)
37
+ return unless template =
38
+ find_template(uri, nil, !:partial) ||
39
+ find_template(uri, nil, :partial)
40
+ File.mtime(template.identifier).to_i
41
+ end
42
+
43
+ # @see Base#to_s
44
+ def to_s
45
+ "(Rails importer)"
46
+ end
47
+
48
+ private
49
+
50
+ def find_(uri, prefix, options)
51
+ prepare_template(
52
+ find_template(uri, prefix, !:partial) ||
53
+ find_template(uri, prefix, :partial),
54
+ options)
55
+ end
56
+
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)}
61
+ end
62
+
63
+ def prepare_template(template, options)
64
+ return unless template
65
+ options[:syntax] = template.handler.syntax
66
+ options[:filename] = template.virtual_path
67
+ options[:importer] = self
68
+ Sass::Engine.new(template.source, options)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -18,7 +18,47 @@ unless defined?(Sass::RAILS_LOADED)
18
18
 
19
19
  Sass::Plugin.options.reverse_merge!(Sass::Plugin.default_options)
20
20
 
21
- if defined?(ActionController::Metal)
21
+ if Sass::Util.ap_geq?('3.1.0.beta')
22
+ require 'sass/importers/rails'
23
+ class Sass::Plugin::TemplateHandler
24
+ attr_reader :syntax
25
+
26
+ def initialize(syntax)
27
+ @syntax = syntax
28
+ end
29
+
30
+ def handles_encoding?; true; end
31
+
32
+ def call(template, view)
33
+ rails_importer = Sass::Importers::Rails.new(view.lookup_context)
34
+ tree = Sass::Engine.new(template.source,
35
+ :syntax => @syntax,
36
+ :cache => false,
37
+ :filename => template.virtual_path,
38
+ :importer => rails_importer,
39
+ :load_paths => [rails_importer],
40
+ ).to_tree
41
+
42
+ <<RUBY
43
+ importer = Sass::Importers::Rails.new(lookup_context)
44
+ staleness_checker = Sass::Plugin::StalenessChecker.new(
45
+ Sass::Plugin.engine_options.merge(:load_paths => [importer], :cache => false))
46
+ if staleness_checker.stylesheet_modified_since?(
47
+ #{template.virtual_path.inspect},
48
+ #{Time.now.to_i},
49
+ importer)
50
+ @_template.expire!
51
+ @_template.rerender(self)
52
+ else
53
+ #{tree.render.inspect}
54
+ end
55
+ RUBY
56
+ end
57
+ end
58
+
59
+ ActionView::Template.register_template_handler(:sass, Sass::Plugin::TemplateHandler.new(:sass))
60
+ ActionView::Template.register_template_handler(:scss, Sass::Plugin::TemplateHandler.new(:scss))
61
+ elsif defined?(ActionController::Metal)
22
62
  # Rails >= 3.0
23
63
  require 'sass/plugin/rack'
24
64
  Rails.configuration.middleware.use(Sass::Plugin::Rack)
@@ -53,6 +53,7 @@ module Sass
53
53
  # @param css_file [String] The location of the CSS file to check.
54
54
  # @param template_file [String] The location of the Sass or SCSS template
55
55
  # that is compiled to `css_file`.
56
+ # @return [Boolean] Whether the stylesheet needs to be updated.
56
57
  def stylesheet_needs_update?(css_file, template_file)
57
58
  template_file = File.expand_path(template_file)
58
59
  begin
@@ -61,8 +62,19 @@ module Sass
61
62
  return true
62
63
  end
63
64
 
64
- dependency_updated?(css_mtime).call(
65
- template_file, @options[:filesystem_importer].new("."))
65
+ stylesheet_modified_since?(template_file, css_mtime)
66
+ end
67
+
68
+ # Returns whether a Sass or SCSS stylesheet has been modified since a given time.
69
+ #
70
+ # @param template_file [String] The location of the Sass or SCSS template.
71
+ # @param mtime [Fixnum] The modification time to check against.
72
+ # @param importer [Sass::Importers::Base] The importer used to locate the stylesheet.
73
+ # Defaults to the filesystem importer.
74
+ # @return [Boolean] Whether the stylesheet has been modified.
75
+ def stylesheet_modified_since?(template_file, mtime, importer = nil)
76
+ importer ||= @options[:filesystem_importer].new(".")
77
+ dependency_updated?(mtime).call(template_file, importer)
66
78
  end
67
79
 
68
80
  # Returns whether or not a given CSS file is out of date
@@ -75,10 +87,26 @@ module Sass
75
87
  # @param css_file [String] The location of the CSS file to check.
76
88
  # @param template_file [String] The location of the Sass or SCSS template
77
89
  # that is compiled to `css_file`.
90
+ # @return [Boolean] Whether the stylesheet needs to be updated.
78
91
  def self.stylesheet_needs_update?(css_file, template_file)
79
92
  new(Plugin.engine_options).stylesheet_needs_update?(css_file, template_file)
80
93
  end
81
94
 
95
+ # Returns whether a Sass or SCSS stylesheet has been modified since a given time.
96
+ #
97
+ # The distinction between this method and the instance-level \{#stylesheet\_modified\_since?}
98
+ # is that the instance method preserves mtime and stale-dependency caches,
99
+ # so it's better to use when checking multiple stylesheets at once.
100
+ #
101
+ # @param template_file [String] The location of the Sass or SCSS template.
102
+ # @param mtime [Fixnum] The modification time to check against.
103
+ # @param importer [Sass::Importers::Base] The importer used to locate the stylesheet.
104
+ # Defaults to the filesystem importer.
105
+ # @return [Boolean] Whether the stylesheet has been modified.
106
+ def self.stylesheet_modified_since?(template_file, mtime, importer = nil)
107
+ new(Plugin.engine_options).stylesheet_modified_since?(template_file, mtime, importer)
108
+ end
109
+
82
110
  private
83
111
 
84
112
  def dependencies_stale?(uri, importer, css_mtime)
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.29
4
+ version: 3.1.0.alpha.30
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-16 00:00:00 -05:00
14
+ date: 2010-11-17 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -69,6 +69,7 @@ files:
69
69
  - lib/sass/repl.rb
70
70
  - lib/sass/importers/base.rb
71
71
  - lib/sass/importers/filesystem.rb
72
+ - lib/sass/importers/rails.rb
72
73
  - lib/sass/root.rb
73
74
  - lib/sass/script/bool.rb
74
75
  - lib/sass/script/color.rb