Created
October 11, 2013 06:31
-
-
Save mattsmith/6930430 to your computer and use it in GitHub Desktop.
Renders a scss stylesheet with erb using Tilt templates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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