lib/mcp/common/templates.rb
# Run the template with the given parameters and return
# the template with the values replaced
Run the template with the given parameters and return
the template with the values replaced
Run the template with the given parameters and return the template with the values replaced
def run()
        out_arr = []
        @replace_strs.keys.each { |replace_str|
          @template.each do |out_str|
            next if out_str.nil?
            val = nil
            out_str.gsub!( /#{replace_str}(.*?)#{replace_str}/ ) {
              begin
                val = @replace_strs[ replace_str ].call( $1 )
              rescue IndexError => e
                raise McastTemplateException.new, "Unknown key '#{$1}' found in template"
              end
              if val.is_a?(Array)
                val.shift.to_s
              else
                val.to_s
              end
            }
            out_arr << out_str unless out_str == ""
            if val.is_a?(Array)
              val.each do |out_str|
                out_str = TemplateString.substitute(out_str, @replace_strs[ replace_str ], replace_str)
                out_arr << out_str unless out_str == ""
              end
            end
          end
        }
        out_arr
      end
def run ( ) out_arr = [ ] @replace_strs . keys . each { | replace_str | @template . each do | out_str | next if out_str . nil? val = nil out_str . gsub! ( / #{ replace_str } (.*?) #{ replace_str } / ) { begin val = @replace_strs [ replace_str ] . call ( $1 ) rescue IndexError => e raise McastTemplateException . new , "Unknown key '#{$1}' found in template" end if val . is_a? ( Array ) val . shift . to_s else val . to_s end } out_arr << out_str unless out_str == "" if val . is_a? ( Array ) val . each do | out_str | out_str = TemplateString . substitute ( out_str , @replace_strs [ replace_str ] , replace_str ) out_arr << out_str unless out_str == "" end end end } out_arr end
Run the template with the given parameters and return
the template with the values replaced
Run the template with the given parameters and return the template with the values replaced