Class: Blocks::RuntimeContext
- Inherits:
-
HashWithRenderStrategy
- Object
- HashWithIndifferentAccess
- HashWithCaller
- HashWithRenderStrategy
- Blocks::RuntimeContext
- Defined in:
- lib/blocks/renderers/runtime_context.rb
Constant Summary collapse
- CONTROL_VARIABLES =
{ wrap_all: [], wrap_each: [:outer_wrapper], wrap_with: [:wrap, :wrapper, :inner_wrapper], collection: [], as: [] }
Constants inherited from HashWithRenderStrategy
HashWithRenderStrategy::RENDERING_STRATEGIES, HashWithRenderStrategy::RENDER_WITH_BLOCK, HashWithRenderStrategy::RENDER_WITH_PARTIAL, HashWithRenderStrategy::RENDER_WITH_PROXY
Instance Attribute Summary collapse
-
#block_name ⇒ Object
Returns the value of attribute block_name.
-
#block_options_set ⇒ Object
Returns the value of attribute block_options_set.
-
#builder ⇒ Object
Returns the value of attribute builder.
-
#parent_runtime_context ⇒ Object
Returns the value of attribute parent_runtime_context.
-
#proxy_options_set ⇒ Object
Returns the value of attribute proxy_options_set.
-
#render_item ⇒ Object
Returns the value of attribute render_item.
-
#render_options_set ⇒ Object
Returns the value of attribute render_options_set.
-
#runtime_args ⇒ Object
Returns the value of attribute runtime_args.
-
#runtime_block ⇒ Object
Returns the value of attribute runtime_block.
Attributes inherited from HashWithRenderStrategy
Attributes inherited from HashWithCaller
Instance Method Summary collapse
-
#extend_to_block_definition(block_definition) ⇒ Object
TODO: this method needs to clone without context, i.e.
-
#initialize(builder, *runtime_args, &runtime_block) ⇒ RuntimeContext
constructor
A new instance of RuntimeContext.
-
#to_s ⇒ Object
TODO: this method needs to be rewritten to output a proper hash.
Methods inherited from HashWithRenderStrategy
#add_options, #initialize_copy, #render_strategy_and_item, #reverse_merge
Methods inherited from HashWithCaller
#add_options, #nested_under_indifferent_access
Constructor Details
#initialize(builder, *runtime_args, &runtime_block) ⇒ RuntimeContext
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/blocks/renderers/runtime_context.rb', line 33 def initialize(builder, *runtime_args, &runtime_block) super(&nil) self.builder = builder self.runtime_block = runtime_block self. = OptionsSet.new("Proxy Options Set") = runtime_args. block_name = runtime_args.shift () identify_block(block_name) self.runtime_args = runtime_args end |
Instance Attribute Details
#block_name ⇒ Object
Returns the value of attribute block_name.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def block_name @block_name end |
#block_options_set ⇒ Object
Returns the value of attribute block_options_set.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def @block_options_set end |
#builder ⇒ Object
Returns the value of attribute builder.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def builder @builder end |
#parent_runtime_context ⇒ Object
Returns the value of attribute parent_runtime_context.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def parent_runtime_context @parent_runtime_context end |
#proxy_options_set ⇒ Object
Returns the value of attribute proxy_options_set.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def @proxy_options_set end |
#render_item ⇒ Object
Returns the value of attribute render_item.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def render_item @render_item end |
#render_options_set ⇒ Object
Returns the value of attribute render_options_set.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def @render_options_set end |
#runtime_args ⇒ Object
Returns the value of attribute runtime_args.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def runtime_args @runtime_args end |
#runtime_block ⇒ Object
Returns the value of attribute runtime_block.
12 13 14 |
# File 'lib/blocks/renderers/runtime_context.rb', line 12 def runtime_block @runtime_block end |
Instance Method Details
#extend_to_block_definition(block_definition) ⇒ Object
TODO: this method needs to clone without context, i.e. with render_strategy, item, etc
52 53 54 55 56 |
# File 'lib/blocks/renderers/runtime_context.rb', line 52 def extend_to_block_definition(block_definition) RuntimeContext.new(builder, block_definition, parent_runtime_context: self).tap do |rc| rc.runtime_args = self.runtime_args end end |
#to_s ⇒ Object
TODO: this method needs to be rewritten to output a proper hash
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/blocks/renderers/runtime_context.rb', line 59 def to_s description = [] if block_name block_name = self.block_name.to_s if block_name.include?(" ") block_name = ":\"#{block_name}\"" else block_name = ":#{block_name}" end description << "Block Name: #{block_name}" end if render_item.is_a?(String) description << "Renders with partial \"#{render_item}\"" elsif render_item.is_a?(Proc) description << "Renders with block defined at #{render_item.source_location}" end CONTROL_VARIABLES.each do |control_variable, *| if value = send(control_variable) description << "#{control_variable}: #{value} [#{callers[control_variable]}]" end end description << super description.join("\n") end |