Sha256: 0507f6c800773bdd800a3dfda857484de792a4b6ccdc05e3ee9ba16ae6043ed2

Contents?: true

Size: 1.64 KB

Versions: 23

Compression:

Stored size: 1.64 KB

Contents

module Coral
module Template
class Environment < Base
  #-----------------------------------------------------------------------------
  # Renderers  
   
  def render(input)
    output = ''
    
    case input
    when Hash
      input.each do |name, value|
        output << render_assignment(name, value)
      end
    end              
    return output      
  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

23 entries across 23 versions & 1 rubygems

Version Path
coral_core-0.2.30 lib/coral_core/template/environment.rb
coral_core-0.2.26 lib/coral_core/template/environment.rb
coral_core-0.2.25 lib/coral_core/template/environment.rb
coral_core-0.2.24 lib/coral_core/template/environment.rb
coral_core-0.2.19 lib/coral_core/template/environment.rb
coral_core-0.2.18 lib/coral_core/template/environment.rb
coral_core-0.2.17 lib/coral_core/template/environment.rb
coral_core-0.2.16 lib/coral_core/template/environment.rb
coral_core-0.2.15 lib/coral_core/template/environment.rb
coral_core-0.2.14 lib/coral_core/template/environment.rb
coral_core-0.2.13 lib/coral_core/template/environment.rb
coral_core-0.2.12 lib/coral_core/template/environment.rb
coral_core-0.2.11 lib/coral_core/template/environment.rb
coral_core-0.2.10 lib/coral_core/template/environment.rb
coral_core-0.2.9 lib/coral_core/template/environment.rb
coral_core-0.2.8 lib/coral_core/template/environment.rb
coral_core-0.2.7 lib/coral_core/template/environment.rb
coral_core-0.2.6 lib/coral_core/template/environment.rb
coral_core-0.2.5 lib/coral_core/template/environment.rb
coral_core-0.2.4 lib/coral_core/template/environment.rb