Skip to content

Commit

Permalink
[Sass] Make Rails 3 integration less hacky.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 10, 2010
1 parent c050ce9 commit 2ca9097
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
27 changes: 6 additions & 21 deletions lib/haml/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@
if defined?(ActiveSupport) && Haml::Util.has?(:public_method, ActiveSupport, :on_load)
require 'haml/template/options'
require 'sass/plugin/configuration'
ActiveSupport.on_load(:action_view) do
if Rails.application
ActiveSupport.on_load(:before_initialize) do
require 'sass'
require 'sass/plugin'

# Haml requires AV, but Sass doesn't
ActiveSupport.on_load(:action_view) do
Haml.init_rails(binding)
else
# I can't believe we have to do this, but we do.
# Rails 3's lovely lazy-loading means that it's possible to load ActionView
# before the application has even begin loading.
# This means that Rails.root doesn't exist yet.
# So if the application isn't loaded, we use this arcane initializer stuff
# to load Haml/Sass *after* the application loads.
#
# Of course, it's also possible that the application is loaded before ActionView,
# so we can't *just* rely on this method of loading.
#
# Ugh.
module Haml
class Railtie < Rails::Railtie
initializer :haml do
Haml.init_rails(binding)
end
end
end
end
end
end
12 changes: 1 addition & 11 deletions lib/sass/plugin/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@
if defined?(ActionController::Metal)
# Rails >= 3.0
require 'sass/plugin/rack'
if Rails.application.instance_variable_get('@app')
# The application has already been built,
# so we need to hack the middleware in
Rails.application.instance_variable_set('@app',
Sass::Plugin::Rack.new(Rails.application.app))
else
# The application hasn't been built yet,
# so we can just add Sass::Plugin::Rack
# to the pending middleware stack.
Rails.configuration.middleware.use(Sass::Plugin::Rack)
end
Rails.configuration.middleware.use(Sass::Plugin::Rack)
elsif defined?(ActionController::Dispatcher) &&
defined?(ActionController::Dispatcher.middleware)
# Rails >= 2.3
Expand Down

0 comments on commit 2ca9097

Please sign in to comment.