Class: Puppet::Pops::Evaluator::EppEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/evaluator/epp_evaluator.rb

Overview

Handler of Epp call/evaluation from the epp and inline_epp functions

Class Method Summary collapse

Class Method Details

.epp(scope, file, env_name, template_args = nil) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puppet/pops/evaluator/epp_evaluator.rb', line 25

def self.epp(scope, file, env_name, template_args = nil)
  unless file.is_a?(String)
    #TRANSLATORS 'epp()' is a method name and should not be translated
    raise ArgumentError, _("epp(): the first argument must be a String with the filename, got a %{class_name}") % { class_name: file.class }
  end

  unless Puppet::FileSystem.exist?(file)
    unless file =~ /\.epp$/
      file = file + ".epp"
    end
  end

  scope.debug "Retrieving epp template #{file}"
  template_file = Puppet::Parser::Files.find_template(file, env_name)
  if template_file.nil? ||  !Puppet::FileSystem.exist?(template_file)
    raise Puppet::ParseError, _("Could not find template '%{file}'") % { file: file }
  end

  # Parse and validate the source
  parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new
  begin
    result = parser.parse_file(template_file)
  rescue Puppet::ParseError => e
    #TRANSLATORS 'epp()' is a method name and 'EPP' refers to 'Embedded Puppet (EPP) template' and should not be translated
    raise ArgumentError, _("epp(): Invalid EPP: %{detail}") % { detail: e.message }
  end

  # Evaluate (and check template_args)
  evaluate(parser, 'epp', scope, true, result, template_args)
end

.inline_epp(scope, epp_source, template_args = nil) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet/pops/evaluator/epp_evaluator.rb', line 5

def self.inline_epp(scope, epp_source, template_args = nil)
  unless epp_source.is_a?(String)
    #TRANSLATORS 'inline_epp()' is a method name and 'epp' refers to 'Embedded Puppet (EPP) template' and should not be translated
    raise ArgumentError, _("inline_epp(): the first argument must be a String with the epp source text, got a %{class_name}") %
        { class_name: epp_source.class }
  end

  # Parse and validate the source
  parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new
  begin
    result = parser.parse_string(epp_source, 'inlined-epp-text')
  rescue Puppet::ParseError => e
    #TRANSLATORS 'inline_epp()' is a method name and 'EPP' refers to 'Embedded Puppet (EPP) template' and should not be translated
    raise ArgumentError, _("inline_epp(): Invalid EPP: %{detail}") % { detail: e.message }
  end

  # Evaluate (and check template_args)
  evaluate(parser, 'inline_epp', scope, false, result, template_args)
end