Module: EasyTemplate
- Defined in:
- lib/easy_template.rb
Class Method Summary collapse
-
.process(text, variables) ⇒ Object
Arguments: text: (String) the string containing your template variables: (Hash) the hash containing the values to substitute in place of the keys enclosed by { and }.
Class Method Details
.process(text, variables) ⇒ Object
Arguments:
text: (String)
the string containing your template
variables: (Hash)
the hash containing the values to substitute in place of the keys enclosed by { and }.
7 8 9 |
# File 'lib/easy_template.rb', line 7 def self.process(text, variables) text.gsub(/(\\\{)|((?<!\\)(?:\\\\)*#{variables.map{|v|"\\{#{Regexp.escape(v[0])}\\}"}.join('|')})/i){|s| s[0] == '\\' ? s[1] : variables[s[1..-2].downcase]} end |