Module: Scribble::Support::Context
- Included in:
- Block, Partial::Context
- Defined in:
- lib/scribble/support/context.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #converter ⇒ Object
-
#evaluate(call, args, context) ⇒ Object
Evaluation.
-
#format ⇒ Object
Format conversion.
-
#nodes ⇒ Object
Rendering.
- #registers ⇒ Object
- #render(nodes: nodes, context: self) ⇒ Object
- #render_format ⇒ Object
- #render_without_conversion(nodes, context) ⇒ Object
- #require_conversion? ⇒ Boolean
- #resolve_variable(call) ⇒ Object
- #set_variable(name, value) ⇒ Object
-
#template ⇒ Object
Template and registers.
-
#variables ⇒ Object
Variables.
Class Method Details
.included(base) ⇒ Object
13 14 15 |
# File 'lib/scribble/support/context.rb', line 13 def self.included base base.extend ClassMethods end |
Instance Method Details
#converter ⇒ Object
65 66 67 |
# File 'lib/scribble/support/context.rb', line 65 def converter @converter ||= template.find_converter(format, render_format) end |
#evaluate(call, args, context) ⇒ Object
Evaluation
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/scribble/support/context.rb', line 85 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 ⇒ Object
Format conversion
53 54 55 |
# File 'lib/scribble/support/context.rb', line 53 def format @context.format end |
#nodes ⇒ Object
Rendering
19 20 21 |
# File 'lib/scribble/support/context.rb', line 19 def nodes raise NotImplementedError, 'Class that includes context must implement nodes method' end |
#registers ⇒ Object
47 48 49 |
# File 'lib/scribble/support/context.rb', line 47 def registers @context.registers end |
#render(nodes: nodes, context: self) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/scribble/support/context.rb', line 23 def render nodes: nodes, context: self 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 ⇒ Object
57 58 59 |
# File 'lib/scribble/support/context.rb', line 57 def render_format @context.format end |
#render_without_conversion(nodes, context) ⇒ Object
37 38 39 |
# File 'lib/scribble/support/context.rb', line 37 def render_without_conversion nodes, context nodes.map { |node| Scribble::Registry.to_string node.evaluate(context) }.join end |
#require_conversion? ⇒ Boolean
61 62 63 |
# File 'lib/scribble/support/context.rb', line 61 def require_conversion? render_format && format != render_format end |
#resolve_variable(call) ⇒ Object
79 80 81 |
# File 'lib/scribble/support/context.rb', line 79 def resolve_variable call variables[call.name] if call.allow_variable end |
#set_variable(name, value) ⇒ Object
75 76 77 |
# File 'lib/scribble/support/context.rb', line 75 def set_variable name, value variables[name] = value end |
#template ⇒ Object
Template and registers
43 44 45 |
# File 'lib/scribble/support/context.rb', line 43 def template @context.template end |
#variables ⇒ Object
Variables
71 72 73 |
# File 'lib/scribble/support/context.rb', line 71 def variables @variables ||= {} end |