Puppet Function: htmlentities
- Defined in:
- lib/puppet/functions/htmlentities.rb
- Function type:
- Ruby 4.x API
Overview
htmlentities.rb
This escapes HTML characters. Currently supported: <>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet/functions/htmlentities.rb', line 7 Puppet::Functions.create_function(:htmlentities) do dispatch :format_number do param 'Numeric', :input_number return_type 'String' end dispatch :format_string do param 'String', :input_string return_type 'String' end dispatch :format_array do param 'Array[String[1]]', :input_array return_type 'Array[String[1]]' end def _htmlentities(str) r_h = { '>' => '>', '<' => '<', '&' => '&', } r_h.sort.each do |k, v| str = str.gsub(%r{#{k}}, v) end str end def format_number(input_number) _htmlentities(input_number.to_s) end def format_string(input_string) _htmlentities(input_string) end def format_array(input_array) input_array.map { |e| _htmlentities(e) } end end |