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
33
34
35
36
37
# 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__} )

  # This is just to get ride of the warning of unused variables
  # The variable are used, but as part of binding
  _ = "#{labels_str}, #{type}"

  template = <<-TEXT.gsub(/^ {6}/, '')
  <%=type%><%=labels_str%> {
  <%- unless value.to_s.empty? -%>
  <%=value.to_tf.strip.gsub(/^/,'    ')%>
  <%- end -%>
  }
  TEXT
  ERB.new(template, trim_mode: '-').result(binding).strip
end

.list(name, value) ⇒ Object



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

def list(name, value)
  template = <<-TEXT.gsub(/^ {6}/, '')
  <%=name%> = <%=DataFormatter.new.format value%>
  TEXT
  ERB.new(template, trim_mode: '-').result(binding).strip
end

.map(name, value) ⇒ Object



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

def map(name, value)
  template = <<-TEXT.gsub(/^ {6}/, '')
  <%=name%> = <%=DataFormatter.new.format value%>
  TEXT
  ERB.new(template, trim_mode: '-').result(binding).strip
end

.value(name, value) ⇒ Object



39
40
41
42
43
44
# File 'lib/tfdsl/template.rb', line 39

def value(name, value)
  template = <<-TEXT.gsub(/^ {6}/, '')
  <%=name%> = "<%=value%>"
  TEXT
  ERB.new(template, trim_mode: '-').result(binding).strip
end