Skip to content

Instantly share code, notes, and snippets.

@avit
Created March 18, 2009 12:18
Show Gist options
  • Save avit/81087 to your computer and use it in GitHub Desktop.
Save avit/81087 to your computer and use it in GitHub Desktop.
module ActionView
class ErSass < ActionView::TemplateHandler
include ERB::Util
SASS_ENGINE_OPTS = {
:load_paths => Compass.configuration.sass_load_paths + ["#{Rails.root}/app/stylesheets"]
}
def self.call(template)
"ActionView::ErSass.new(self).render(template, local_assigns)"
end
def initialize(view = nil)
@view = view
end
def render(template, local_assigns = {})
controller = @view.controller
controller.headers['Content-Type'] ||= Mime::CSS
controller.instance_variables.each do |v|
instance_variable_set v, controller.instance_variable_get(v)
end
erbsrc = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, '-').src
erboutput = @view.instance_eval(erbsrc)
Sass::Engine.new(erboutput, Sass::Plugin.options.merge(SASS_ENGINE_OPTS)).render
end
end
end
ActionView::Template.register_template_handler :sass, ActionView::ErSass
ActionView::Template.exempt_from_layout :sass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment