Module: WIP::Runner::Renderers::ERB

Defined in:
lib/wip/runner/renderers/erb.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/wip/runner/renderers/erb.rb', line 7

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#clean(string) ⇒ Object



18
19
20
21
22
23
# File 'lib/wip/runner/renderers/erb.rb', line 18

def clean(string)
  return if string.nil?

  indent = (string.scan(/^[ \t]*(?=\S)/).min || '').size
  string.gsub(/^[ \t]{#{indent}}/, '').strip
end

#render(template, context) ⇒ Object



11
12
13
14
15
16
# File 'lib/wip/runner/renderers/erb.rb', line 11

def render(template, context)
  if (file = File.join("#{self.class.templates}/#{template}.erb")) && File.exist?(file)
    template = File.read(file)
  end
  ::ERB.new(clean(template)).result(context)
end