Module: TFDSL::Template

Defined in:
lib/tfdsl/template.rb

Overview

Collection of small templates to be used on to_s / to_str of blocks

Class Method Summary collapse

Class Method Details

.child_block(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tfdsl/template.rb', line 20

def child_block(value)
  labels = value.__labels__.nil? ? [] : value.__labels__
  labels_str = labels.map { |l| %("#{l}") }.join ' '
  type = value.__type__.nil? ? '' : %( #{value.__type__} )
  template = "  <%=type%><%=labels_str%> {\n  <%- unless value.to_s.empty? -%>\n  <%=value.to_tf.strip.gsub(/^/,'    ')%>\n  <%- end -%>\n  }\n  TEXT\n  ERB.new(template, nil, '-').result(binding).strip\nend\n".gsub(/^ {6}/, '')

.list(name, value) ⇒ Object



6
7
8
9
10
11
# File 'lib/tfdsl/template.rb', line 6

def list(name, value)
  template = "  <%=name%> = <%=DataFormatter.new.format value%>\n  TEXT\n  ERB.new(template, nil, '-').result(binding).strip\nend\n".gsub(/^ {6}/, '')

.map(name, value) ⇒ Object



13
14
15
16
17
18
# File 'lib/tfdsl/template.rb', line 13

def map(name, value)
  template = "  <%=name%> = <%=DataFormatter.new.format value%>\n  TEXT\n  ERB.new(template, nil, '-').result(binding).strip\nend\n".gsub(/^ {6}/, '')

.value(name, value) ⇒ Object



34
35
36
37
38
39
# File 'lib/tfdsl/template.rb', line 34

def value(name, value)
  template = "  <%=name%> = \"<%=value%>\"\n  TEXT\n  ERB.new(template, nil, '-').result(binding).strip\nend\n".gsub(/^ {6}/, '')