module LiquidMarkdown::TemplateHandler
Constants
- OBJECT_ATTRIBUTE_MATCHER
- UNDERSCORE
Public Class Methods
expand_variables(template, variables)
click to toggle source
# File lib/liquid_markdown/template_handler.rb, line 13 def self.expand_variables(template, variables) template.scan(OBJECT_ATTRIBUTE_MATCHER) .map(&:first) .each_with_object(variables) do |match, buffer| target, attribute = match.split('.') buffer[match.to_sym] = variables[target.to_sym].public_send(attribute) end end
extract_variables(context)
click to toggle source
# File lib/liquid_markdown/template_handler.rb, line 22 def self.extract_variables(context) context .instance_variable_get(:@_assigns) .each_with_object({}) do |(name, value), buffer| next if name.start_with?(UNDERSCORE) buffer[name.to_sym] = value end end
render(template, context, format)
click to toggle source
# File lib/liquid_markdown/template_handler.rb, line 6 def self.render(template, context, format) variables = expand_variables(template, extract_variables(context)) liquid_variables = variables.deep_stringify_keys lm = LiquidMarkdown::Render.new(template, liquid_variables) lm.send(format) end