Class: Skytap::Templates::Base

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/skytap/templates.rb

Direct Known Subclasses

Help

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render(hash) ⇒ Object

The template can refer to hash keys as if they were local variables.



26
27
28
29
# File 'lib/skytap/templates.rb', line 26

def self.render(hash)
  attrs = {'description' => 'DEFAULT DESCRIPTION HERE'}.merge(hash)
  new(attrs).render
end

Instance Method Details

#indent(msg = '', width = 5) ⇒ Object



41
42
43
44
45
46
# File 'lib/skytap/templates.rb', line 41

def indent(msg='', width=5)
  msg ||= ''
  msg.split("\n").collect do |line|
    (' ' * width) << line
  end.join("\n")
end

#renderObject



35
36
37
38
39
# File 'lib/skytap/templates.rb', line 35

def render
  # Allow -%> to trim surrounding whitespace in ERB.
  trim_mode_char = '-'
  ERB.new(template_str, nil, trim_mode_char).result(binding)
end

#template_strObject



31
32
33
# File 'lib/skytap/templates.rb', line 31

def template_str
  raise 'must be overridden'
end