Class: Coral::Template::Environment

Inherits:
Base show all
Defined in:
lib/coral_core/template/environment.rb

Instance Method Summary collapse

Methods inherited from Base

#intialize

Methods inherited from Config

#[], #[]=, array, #array, #clear, #defaults, #delete, ensure, #export, #filter, filter, #get, #get_array, #get_hash, #hash, hash, #import, init, #init, init_flat, #initialize, #set, #string, string, string_map, #string_map, #symbol, symbol, symbol_map, #symbol_map, test, #test

Methods included from Mixin::ConfigOptions

#clear_options, #contexts, #get_options, #set_options

Methods included from Mixin::ConfigCollection

#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property

Methods included from Mixin::Lookup

#hiera, #hiera_config, #initialized?, #lookup, #lookup_array, #lookup_hash, #normalize

Methods included from Mixin::ConfigOps

#parse

Constructor Details

This class inherits a constructor from Coral::Config

Instance Method Details

#render(input) ⇒ Object


Renderers



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/coral_core/template/environment.rb', line 8

def render(input)
  output = ''
  
  case input
  when Hash
    input.each do |name, value|
      output << render_assignment(name, value)
    end
  end              
  return output      
end

#render_assignment(name, value) ⇒ Object




22
23
24
25
26
27
28
29
30
31
# File 'lib/coral_core/template/environment.rb', line 22

def render_assignment(name, value)
  name  = render_name(name)
  value = render_value(value)
  
  export      = get(:export, true)
  export_text = export ? get(:export_text, 'export ') : ''
  operator    = get(:operator, '=')
  
  return "#{export_text}#{name}#{operator}#{value}\n"  
end

#render_name(name) ⇒ Object




35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/coral_core/template/environment.rb', line 35

def render_name(name)
  prefix     = get(:name_prefix, '')
  prefix_sep = prefix.empty? ? '' : get(:name_prefix_sep, '_')
  
  suffix     = get(:name_suffix, '')
  suffix_sep = suffix.empty? ? '' : get(:name_suffix_sep, '')
  
  unless prefix.empty?
    name = "#{prefix}#{prefix_sep}#{name}#{suffix_sep}#{suffix}"
  end
  return name
end

#render_value(value) ⇒ Object




50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/coral_core/template/environment.rb', line 50

def render_value(value)
  sep          = get(:value_sep, ' ')
  quote        = get(:quote, true)
  
  array_prefix = get(:array_prefix, '(')
  array_suffix = get(:array_suffix, ')')
  
  case value
  when Array
    values = []
    value.each do |item|
      values << quote ? "'#{item}'" : "#{item}"  
    end
    value = "#{array_prefix}#{values.join(sep)}#{array_suffix}"
          
  when String
    value = quote ? "'#{value}'" : "#{value}" 
  end
  return value
end