Sha256: b2758f4a184a284068411bbb441926f8159606334391fd073e2db22e9613feba
Contents?: true
Size: 608 Bytes
Versions: 5
Compression:
Stored size: 608 Bytes
Contents
module Docify class Template REGEX = /(\{\{([a-z\-\_]{1,})\}\})/i # Initialize Template object with a string template def initialize(content) @template = content.strip.to_s raise ArgumentError, "Template content required!" if @template.empty? end # Render template # params - Hash of parameters. # Each params in template should be wrapped with {{var}}. def render(params={}) params.stringify_keys! @template.gsub(REGEX) do |m| key = m.scan(REGEX).flatten.last.to_s m = params[key] end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
docify-1.0.7 | lib/docify/template.rb |
docify-1.0.6 | lib/docify/template.rb |
docify-1.0.5 | lib/docify/template.rb |
docify-1.0.4 | lib/docify/template.rb |
docify-1.0.3 | lib/docify/template.rb |