Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Nuke all Rails 3.1 support.

The new plan is to have Rails take care of any and all integration and
compilation.
  • Loading branch information...
commit 1f56925df17ec8196fd6687b9f16f2da2b6b2a2d 1 parent d9b9e52
@nex3 nex3 authored
View
28 lib/sass/cache_stores/active_support.rb
@@ -1,28 +0,0 @@
-module Sass
- module CacheStores
- # A cache store that wraps an ActiveSupport cache store.
- # This is useful for integrating with an app that uses ActiveSupport,
- # or for taking advantage of the wide variety of ActiveSupport cache backends.
- #
- # This is automatically used within Rails.
- class ActiveSupport < Base
- # @param store [::ActiveSupport::Cache::Store] The cache store to wrap.
- def initialize(store)
- @store = store
- end
-
- # @see Base#_retrieve
- def _retrieve(key, version, sha)
- return unless val = @store.fetch('_sass/' + key)
- return unless val[:version] == version
- return unless val[:sha] == sha
- return val[:contents]
- end
-
- # @see Base#_store
- def _store(key, version, sha, contents)
- @store.write('_sass/' + key, :version => version, :sha => sha, :contents => contents)
- end
- end
- end
-end
View
75 lib/sass/importers/rails.rb
@@ -1,75 +0,0 @@
-module Sass
- module Importers
- # An importer that wraps the Rails 3.1 view infrastructure.
- # Loads Sass files as though they were views in Rails.
- # Currently doesn't support caching.
- #
- # This is different from standard Rails rendering
- # in that Sass doesn't have a concept of importing partials
- # as a distinct action from importing other Sass files.
- # Imports within Rails behave more like Sass imports:
- # they will first attempt to find a non-partial file,
- # and failing that will fall back on a partial.
- #
- # Each importer instance is local to a single request for a single view.
- # It contains the ActionView::LookupContext for that request,
- # as well as the controller prefix for the view being generated.
- class Rails < Base
- # Creates a new Rails importer that imports files as Rails views.
- def initialize; end
-
- # @see Base#find_relative
- def find_relative(uri, base, options)
- find_(uri, base.split('/')[0...-1].join('/'), options)
- end
-
- # @see Base#find
- def find(uri, options)
- find_(uri, nil, options)
- end
-
- # @see Base#mtime
- def mtime(uri, options)
- return unless template =
- find_template(uri, nil, !:partial, options) ||
- find_template(uri, nil, :partial, options)
- template.updated_at
- end
-
- # @see Base#key
- def key(uri, options)
- [self.class.name + ":" + uri.split('/')[0...-1].join('/'),
- uri.split('/')[-1] + "." + options[:syntax].to_s]
- end
-
- # @see Base#to_s
- def to_s
- "(Rails importer)"
- end
-
- private
-
- def find_(uri, prefix, options)
- prepare_template(
- find_template(uri, prefix, !:partial, options) ||
- find_template(uri, prefix, :partial, options),
- options)
- end
-
- def find_template(uri, prefix, partial, options)
- return options[:_rails_lookup_context].
- find_all(uri, prefix, partial).
- find {|t| t.handler.is_a?(Sass::Plugin::TemplateHandler)}
- end
-
- def prepare_template(template, options)
- return unless template
- options[:syntax] = template.handler.syntax
- options[:filename] = template.virtual_path
- options[:_rails_filename] = template.identifier
- options[:importer] = self
- Sass::Engine.new(template.source, options)
- end
- end
- end
-end
View
90 lib/sass/plugin/rails.rb
@@ -11,18 +11,11 @@ def default_options
:cache_location => Sass::Util.rails_root + '/tmp/sass-cache'
}
- if Sass::Util.ap_geq?('3.1.0.beta')
- require 'sass/importers/rails'
- require 'sass/cache_stores/active_support'
- opts.merge!(:load_paths => [Sass::Importers::Rails.new])
- opts.merge!(:cache_store => Sass::CacheStores::ActiveSupport.new(Rails.cache)) if Rails.cache
- else
- opts.merge!(
- :always_update => false,
- :template_location => Sass::Util.rails_root + '/public/stylesheets/sass',
- :css_location => Sass::Util.rails_root + '/public/stylesheets',
- :always_check => Sass::Util.rails_env == "development")
- end
+ opts.merge!(
+ :always_update => false,
+ :template_location => Sass::Util.rails_root + '/public/stylesheets/sass',
+ :css_location => Sass::Util.rails_root + '/public/stylesheets',
+ :always_check => Sass::Util.rails_env == "development")
@default_options = opts.freeze
end
@@ -30,76 +23,9 @@ def default_options
Sass::Plugin.options.reverse_merge!(Sass::Plugin.default_options)
- # Disable this for now, until we figure out how to get Rails
- # to pass in the view.
- if Sass::Util.ap_geq?('3.1.0.beta')
- class Sass::Plugin::TemplateHandler
- attr_reader :syntax
-
- def initialize(syntax)
- @syntax = syntax
- end
-
- def handles_encoding?; true; end
-
- def call(template, view)
- engine = Sass::Engine.new(template.source,
- Sass::Plugin.engine_options.merge(
- :syntax => @syntax,
- :filename => template.virtual_path,
- :_rails_lookup_context => view.lookup_context,
- :importer => Sass::Importers::Rails.new))
-
- template.data[:sass_importers] = engine.dependencies.map do |e|
- [e.options[:filename], e.options[:importer]]
- end
-
- stylesheet =
- begin
- engine.render
- rescue Sass::SyntaxError => e
- Sass::Plugin::TemplateHandler.munge_exception e, view.lookup_context
- Sass::SyntaxError.exception_to_css(e, Sass::Plugin.engine_options)
- end
-
- <<RUBY
-begin
- if Sass::Plugin::TemplateHandler.dependencies_changed?(
- @_template.data[:sass_importers], #{Time.now.to_i}, lookup_context)
- @_template.expire!
- @_template.rerender(self)
- else
- #{stylesheet.inspect}
- end
-rescue Sass::SyntaxError => e
- Sass::Plugin::TemplateHandler.munge_exception e, lookup_context
- Sass::SyntaxError.exception_to_css(e, Sass::Plugin.engine_options)
-end
-RUBY
- end
-
- def self.dependencies_changed?(deps, since, lookup_context)
- opts = Sass::Plugin.engine_options.merge(:_rails_lookup_context => lookup_context)
- deps.any? do |d, i|
- return true unless time = i.mtime(d, opts)
- time.to_i > since
- end
- end
-
- def self.munge_exception(e, lookup_context)
- importer = Sass::Importers::Rails.new
- opts = Sass::Plugin.engine_options.merge(:_rails_lookup_context => lookup_context)
- e.sass_backtrace.each do |bt|
- next unless engine = importer.find(bt[:filename], opts)
- bt[:filename] = engine.options[:_rails_filename]
- end
- end
- end
-
- ActionView::Template.register_template_handler(:sass, Sass::Plugin::TemplateHandler.new(:sass))
- ActionView::Template.register_template_handler(:scss, Sass::Plugin::TemplateHandler.new(:scss))
- elsif defined?(ActionController::Metal)
- # Rails >= 3.0
+ # Rails 3.1 loads and handles Sass all on its own
+ if defined?(ActionController::Metal)
+ # 3.1 > Rails >= 3.0
require 'sass/plugin/rack'
Rails.configuration.middleware.use(Sass::Plugin::Rack)
elsif defined?(ActionController::Dispatcher) &&
View
5 lib/sass/railtie.rb
@@ -1,5 +1,6 @@
-# Rails 3.0.0.beta.2+
-if defined?(ActiveSupport) && Sass::Util.has?(:public_method, ActiveSupport, :on_load)
+# Rails 3.0.0.beta.2+, < 3.1
+if defined?(ActiveSupport) && Sass::Util.has?(:public_method, ActiveSupport, :on_load) &&
+ !Sass::Util.ap_geq?('3.1.0.beta')
require 'sass/plugin/configuration'
ActiveSupport.on_load(:before_initialize) do
require 'sass'
Please sign in to comment.
Something went wrong with that request. Please try again.