File: template.rb

package info (click to toggle)
ruby-sprockets-export 1.0.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 124 kB
  • sloc: ruby: 117; sh: 4; makefile: 3
file content (27 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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