Sha256: f2778bd18a3028c505438988e063eb491fae3490f8b36b9edc79dc9e8c127c42

Contents?: true

Size: 1.99 KB

Versions: 19

Compression:

Stored size: 1.99 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 = {
        :node            => CORL::Provisioner::Puppetnode.node,
        :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
      
      template = CORL.template(config, provider)
      value    = template.render(data)
      
      CORL.remove_plugin(template)
      
      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

19 entries across 19 versions & 1 rubygems

Version Path
corl-0.5.18 lib/puppet/parser/functions/render.rb
corl-0.5.17 lib/puppet/parser/functions/render.rb
corl-0.5.16 lib/puppet/parser/functions/render.rb
corl-0.5.15 lib/puppet/parser/functions/render.rb
corl-0.5.14 lib/puppet/parser/functions/render.rb
corl-0.5.13 lib/puppet/parser/functions/render.rb
corl-0.5.12 lib/puppet/parser/functions/render.rb
corl-0.5.11 lib/puppet/parser/functions/render.rb
corl-0.5.10 lib/puppet/parser/functions/render.rb
corl-0.5.9 lib/puppet/parser/functions/render.rb
corl-0.5.8 lib/puppet/parser/functions/render.rb
corl-0.5.7 lib/puppet/parser/functions/render.rb
corl-0.5.6 lib/puppet/parser/functions/render.rb
corl-0.5.5 lib/puppet/parser/functions/render.rb
corl-0.5.4 lib/puppet/parser/functions/render.rb
corl-0.5.3 lib/puppet/parser/functions/render.rb
corl-0.5.2 lib/puppet/parser/functions/render.rb
corl-0.5.1 lib/puppet/parser/functions/render.rb
corl-0.5.0 lib/puppet/parser/functions/render.rb