Sha256: 9fbe27f8d78d2c4ed1a5caa7263d510271cc1be75b79921e1857c8b2161554cb

Contents?: true

Size: 999 Bytes

Versions: 1

Compression:

Stored size: 999 Bytes

Contents

require 'tilt'

module CssSplitter

  class SprocketsEngine < Tilt::Template
    def self.engine_initialized?
      true
    end

    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+)$/
        CssSplitter::Splitter.split_string(data, $1.to_i)
      else
        data
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
css_splitter-0.4.6 lib/css_splitter/sprockets_engine.rb