Skip to content

Instantly share code, notes, and snippets.

@mattsmith
Created October 11, 2013 06:31
Show Gist options
  • Save mattsmith/6930430 to your computer and use it in GitHub Desktop.
Save mattsmith/6930430 to your computer and use it in GitHub Desktop.
Renders a scss stylesheet with erb using Tilt templates.
class DynamicStylesheet
# logical_path = 'app/assets/stylesheets/custom.css.scss.erb'
def render(logical_path, data={})
path = Rails.root.join(logical_path)
context = env.context_class.new(env, logical_path, Pathname.new(path))
# TODO Change to Tilt.templates_for(file) in Tilt 2.x
templates = [Tilt::ERBTemplate, Sass::Rails::ScssTemplate]
css = templates.inject(nil) do |data, template|
blk = proc { data } if data
template.new(path.to_s, &blk).render(context, data)
end
end
def env
::YourApp::Application.assets
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment