Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module ActionView
class ErSass < ActionView::TemplateHandler
include ERB::Util
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.engine_options).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
You can’t perform that action at this time.