Sha256: 2c851b6494ba9b55a642771e9235a94db338ecacfc942a81f552a63ecf841b92

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

module Nucleon
module Plugin
class Template < Base

  #-----------------------------------------------------------------------------
  # Template plugin interface

  
  #-----------------------------------------------------------------------------
  # Property accessor / modifiers

  #-----------------------------------------------------------------------------
  # Operations
  
  def process(value)
    case value
    when String, Symbol
      return nil        if Util::Data.undef?(value)
      return 'false'    if value == false
      return 'true'     if value == true      
      return value.to_s if value.is_a?(Symbol)
      
    when Hash
      results = {}
      value.each do |key, item|
        result = process(item)
        unless result.nil?
          results[key] = result  
        end
        value = results
      end
      
    when Array
      results = []
      value.each_with_index do |item, index|
        result = process(item)
        unless result.nil?
          results << result  
        end        
      end
      value = results
    end
    return value
  end
    
  #---
  
  def render(data)
    normalize   = get(:normalize_template, true)
    interpolate = get(:interpolate_template, true)
    
    logger.debug("Rendering data: normalize: #{normalize.inspect}; interpolate: #{interpolate.inspect}: #{data.inspect}")
    
    if normalize
      data = Config.normalize(data, nil, export)
      logger.debug("Pre-rendering data normalization: #{data.inspect}")
    end
    
    if normalize && interpolate
      data = Util::Data.interpolate(data, data, export)
      logger.debug("Pre-rendering data interpolation: #{data.inspect}")
    end    
    return render_processed(process(data))
  end
  
  #---
  
  def render_processed(data)
    logger.debug("Rendering #{plugin_provider} data: #{data.inspect}")
    
    output = ''
    output = yield(output) if block_given?
    
    logger.debug("Completed rendering of #{plugin_provider} data: #{output}")
    return output
  end
end
end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nucleon-0.1.12 lib/core/plugin/template.rb
nucleon-0.1.11 lib/core/plugin/template.rb
nucleon-0.1.10 lib/core/plugin/template.rb
nucleon-0.1.9 lib/core/plugin/template.rb
nucleon-0.1.8 lib/core/plugin/template.rb
nucleon-0.1.7 lib/core/plugin/template.rb
nucleon-0.1.6 lib/core/plugin/template.rb
nucleon-0.1.5 lib/core/plugin/template.rb