Sha256: 1cf2925c4ea032fec9dee2bbadd8ff84df1739c4f155bb14aac6a9d4d420ffc5

Contents?: true

Size: 728 Bytes

Versions: 5

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true
require 'erb'

class Sprockets::ERBProcessor
  # Public: Return singleton instance with default options.
  #
  # Returns ERBProcessor object.
  def self.instance
    @instance ||= new
  end

  def self.call(input)
    instance.call(input)
  end

  def initialize(&block)
    @block = block
  end

  def call(input)
    engine = ::ERB.new(input[:data], nil, '<>')
    engine.filename = input[:filename]

    context = input[:environment].context_class.new(input)
    klass = (class << context; self; end)
    klass.const_set(:ENV, context.env_proxy)
    klass.class_eval(&@block) if @block

    data = engine.result(context.instance_eval('binding'))
    context.metadata.merge(data: data)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sprockets-4.0.0.beta8 lib/sprockets/erb_processor.rb
sprockets-4.0.0.beta7 lib/sprockets/erb_processor.rb
sprockets-4.0.0.beta6 lib/sprockets/erb_processor.rb
sprockets-4.0.0.beta5 lib/sprockets/erb_processor.rb
sprockets-4.0.0.beta4 lib/sprockets/erb_processor.rb