Sha256: dcbeb13bdb64d6053fe8117162534e60cec2101eb0d3d0c9fa5d8db2a459b4bc

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

require "erb"

class Sprockets::Export::Template
  def self.content
    @content ||= Sprockets::Export.lib_path.join("sprockets/export/template.js.erb").read
  end

  def initialize(data = {})
    data.each do |key, value|
      instance_variable_set("@#{key}".to_sym, value)
    end
  end

  def render
    ERB.new(self.class.content, nil, "-").result(binding).strip + "\n"
  end

  private
    def indent(string, amount)
      lines = string.lines.to_a
      result = lines.shift
      lines.each do |line|
        result << line.gsub(/^(?!$)/, " " * amount)
      end
      result
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprockets-export-1.0.0 lib/sprockets/export/template.rb