module Sablon::Context
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.
Public Class Methods
transform_hash(hash)
click to toggle source
# File lib/sablon/context.rb, line 10 def transform_hash(hash) Hash[hash.map { |k, v| transform_pair(k.to_s, v) }] end
Private Class Methods
transform_pair(key, value)
click to toggle source
# File lib/sablon/context.rb, line 27 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
transform_standard_key(key, value)
click to toggle source
# File lib/sablon/context.rb, line 16 def transform_standard_key(key, value) case value when Hash [key, transform_hash(value)] when Array [key, value.map { |v| v.is_a?(Hash) ? transform_hash(v) : v }] else [key, value] end end