Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/css_splitter/sprockets_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ def self.engine_initialized?
def prepare
end

def self.call(input)
data_in = input[:data]

# Instantiate Sprockets::Context to pass along helper methods for Tilt
# processors
context = input[:environment].context_class.new(input)

# Pass the asset file contents as a block to the template engine,
# then get the results of the engine rendering
engine = self.new { data_in }
rendered_data = engine.render(context, {})

# Return the data and any metadata (ie file dependencies, etc)
context.metadata.merge(data: rendered_data.to_str)
end

def evaluate(scope, locals, &block)
# Evaluate the split if the asset is named with a trailing _split2, _split3, etc.
if scope.logical_path =~ /_split(\d+)$/
Expand Down