Sha256: 9ba96584a709945365008a56dcbfb783447816d637a9a066bfa8e818e6eeb977

Contents?: true

Size: 1.85 KB

Versions: 13

Compression:

Stored size: 1.85 KB

Contents

#
# render.rb
#
# Returns the string-ified form of a given value or set of values.
#
module Puppet::Parser::Functions
  newfunction(:render, :type => :rvalue, :doc => <<-EOS
This function returns the string-ified form of a given value.
    EOS
) do |args|
    
    value = nil
    CORL.run do
      raise(Puppet::ParseError, "render(): Must have a template class name and an optional source value specified; " +
        "given (#{args.size} for 2)") if args.size < 1
    
      provider = args[0]  
      data     = ( args.size > 1 ? args[1] : {} )
      options  = ( args.size > 2 ? args[2] : {} )
      
      module_name = parent_module_name
      contexts    = [ :data, :render, "template_#{provider}" ]
    
      default_options = {
        :provisioner     => :puppetnode,
        :hiera_scope     => self,
        :puppet_scope    => self,
        :search          => 'core::default',
        :force           => true,
        :merge           => true,
        :undefined_value => :undef
      }
      
      if module_name
        config = CORL::Config.init(options, contexts, module_name, default_options)  
      else
        config = CORL::Config.init_flat(options, contexts, default_options)
      end
      
      value = CORL.template(config, provider).render(data)
      
      if config.get(:debug, false)      
        CORL.ui.info("\n", { :prefix => false })
        CORL.ui_group(CORL::Util::Console.cyan("#{provider} template")) do |ui|
          ui.info("-----------------------------------------------------")
        
          source_dump  = CORL::Util::Console.blue(CORL::Util::Data.to_json(data, true))
          value_render = CORL::Util::Console.green(value)       
        
          ui.info("Data:\n#{source_dump}")
          ui.info("Rendered:\n#{value_render}")
          ui.info("\n", { :prefix => false }) 
        end
      end
    end
    return value
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
corl-0.4.16 lib/puppet/parser/functions/render.rb
corl-0.4.15 lib/puppet/parser/functions/render.rb
corl-0.4.14 lib/puppet/parser/functions/render.rb
corl-0.4.13 lib/puppet/parser/functions/render.rb
corl-0.4.12 lib/puppet/parser/functions/render.rb
corl-0.4.11 lib/puppet/parser/functions/render.rb
corl-0.4.10 lib/puppet/parser/functions/render.rb
corl-0.4.9 lib/puppet/parser/functions/render.rb
corl-0.4.8 lib/puppet/parser/functions/render.rb
corl-0.4.7 lib/puppet/parser/functions/render.rb
corl-0.4.6 lib/puppet/parser/functions/render.rb
corl-0.4.5 lib/puppet/parser/functions/render.rb
corl-0.4.4 lib/puppet/parser/functions/render.rb