Skip to content

Instantly share code, notes, and snippets.

@avit
Forked from chriseppstein/sass_template_handler.rb
Created March 19, 2009 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avit/81534 to your computer and use it in GitHub Desktop.
Save avit/81534 to your computer and use it in GitHub Desktop.
# Set up rendering of sass through ERB in ActionView
require 'ersass_template_handler'
ActionView::Template.register_template_handler :sass, ActionView::TemplateHandlers::ErSass
ActionView::Template.exempt_from_layout :sass
## Preprocess SASS templates through ERB
module ActionView
module TemplateHandlers
class ErSass < TemplateHandler
include Compilable
def initialize(view=nil)
@view = view
end
def compile(template)
<<-END.gsub("\n", ";")
controller.headers['Content-Type'] = 'text/css'
controller.headers['Cache-Control'] = 'max-age=86400 public'
__in_erb_template = true
erbout = eval(ERB.new(template.source).src)
@output_buffer = Sass::Engine.new(erbout, Sass::Plugin.engine_options).render
END
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment