Sha256: e7efc6c873428f5d83556570e92206a0d74ef5ef3a7c9a7b3a431a92933e5907
Contents?: true
Size: 962 Bytes
Versions: 3
Compression:
Stored size: 962 Bytes
Contents
module Sablon # A context represents the user supplied arguments to render a # template. # # This module contains transformation functions to turn a # user supplied hash into a data structure suitable for rendering the # docx template. module Context class << self def transform_hash(hash) Hash[hash.map { |k, v| transform_pair(k.to_s, v) }] end private def transform_standard_key(key, value) case value when Hash [key, transform_hash(value)] else [key, value] end end def transform_pair(key, value) if key =~ /\A([^:]+):(.+)\z/ if value.nil? [Regexp.last_match[2], value] else key_sym = Regexp.last_match[1].to_sym [Regexp.last_match[2], Content.make(key_sym, value)] end else transform_standard_key(key, value) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sablon-0.1.1 | lib/sablon/context.rb |
sablon-0.1.0 | lib/sablon/context.rb |
sablon-0.0.22 | lib/sablon/context.rb |