module Scribble::Support::Context

Public Class Methods

included(base) click to toggle source
# File lib/scribble/support/context.rb, line 13
def self.included base
  base.extend ClassMethods
end

Public Instance Methods

converter() click to toggle source
# File lib/scribble/support/context.rb, line 67
def converter
  @converter ||= template.find_converter(format, render_format)
end
evaluate(call, args, context) click to toggle source

Evaluation

# File lib/scribble/support/context.rb, line 87
def evaluate call, args, context
  resolve_variable(call) || Scribble::Registry.evaluate(call.name, self, args, call, context)
rescue Support::Unmatched => local
  raise local if @context.nil? || call.split?

  begin
    @context.evaluate call, args, context
  rescue Support::Unmatched => global
    raise global.merge(local)
  end
end
format() click to toggle source

Format conversion

# File lib/scribble/support/context.rb, line 55
def format
  @context.format
end
nodes() click to toggle source

Rendering

# File lib/scribble/support/context.rb, line 19
def nodes
  raise NotImplementedError, 'Class that includes context must implement nodes method'
end
registers() click to toggle source
# File lib/scribble/support/context.rb, line 49
def registers
  @context.registers
end
render(nodes: nil, context: self) click to toggle source
# File lib/scribble/support/context.rb, line 23
def render nodes: nil, context: self
  nodes ||= self.nodes
  
  if !require_conversion?
    render_without_conversion nodes, context

  elsif converter
    converter.convert render_without_conversion(nodes, context)

  elsif format.nil?
    raise "Cannot convert to #{render_format} without format"
  else
    raise "No suitable converter converting #{format} to #{render_format}"
  end
end
render_format() click to toggle source
# File lib/scribble/support/context.rb, line 59
def render_format
  @context.format
end
render_without_conversion(nodes, context) click to toggle source
# File lib/scribble/support/context.rb, line 39
def render_without_conversion nodes, context
  nodes.map { |node| Scribble::Registry.to_string node.evaluate(context) }.join
end
require_conversion?() click to toggle source
# File lib/scribble/support/context.rb, line 63
def require_conversion?
  render_format && format != render_format
end
resolve_variable(call) click to toggle source
# File lib/scribble/support/context.rb, line 81
def resolve_variable call
  variables[call.name] if call.allow_variable
end
set_variable(name, value) click to toggle source
# File lib/scribble/support/context.rb, line 77
def set_variable name, value
  variables[name] = value
end
template() click to toggle source

Template and registers

# File lib/scribble/support/context.rb, line 45
def template
  @context.template
end
variables() click to toggle source

Variables

# File lib/scribble/support/context.rb, line 73
def variables
  @variables ||= {}
end