Sha256: f6199dbadf47f8038856c6574deaeb513afad3424a99295f522f1363ec08adb2

Contents?: true

Size: 1.69 KB

Versions: 29

Compression:

Stored size: 1.69 KB

Contents

module CORL
module Template
class Environment < CORL.plugin_class(:template)
  
  #-----------------------------------------------------------------------------
  # Renderers  
   
  def render_processed(data)
    return super do |output|   
      case data
      when Hash
        data.each do |name, value|
          output << render_assignment(name, value)
        end
      end
      output          
    end      
  end
  
  #-----------------------------------------------------------------------------
  
  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
  
  #---
  
  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
  
  #---
  
  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
end
end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
corl-0.4.29 lib/CORL/template/environment.rb
corl-0.4.28 lib/CORL/template/environment.rb
corl-0.4.27 lib/CORL/template/environment.rb
corl-0.4.26 lib/CORL/template/environment.rb
corl-0.4.25 lib/CORL/template/environment.rb
corl-0.4.24 lib/CORL/template/environment.rb
corl-0.4.23 lib/CORL/template/environment.rb
corl-0.4.22 lib/CORL/template/environment.rb
corl-0.4.21 lib/CORL/template/environment.rb
corl-0.4.20 lib/CORL/template/environment.rb
corl-0.4.19 lib/CORL/template/environment.rb
corl-0.4.18 lib/CORL/template/environment.rb
corl-0.4.17 lib/CORL/template/environment.rb
corl-0.4.16 lib/CORL/template/environment.rb
corl-0.4.15 lib/CORL/template/environment.rb
corl-0.4.14 lib/CORL/template/environment.rb
corl-0.4.13 lib/CORL/template/environment.rb
corl-0.4.12 lib/CORL/template/environment.rb
corl-0.4.11 lib/CORL/template/environment.rb
corl-0.4.10 lib/CORL/template/environment.rb