Class: Props::Template
- Inherits:
-
Object
- Object
- Props::Template
- Defined in:
- lib/props_template.rb
Class Attribute Summary collapse
-
.template_lookup_options ⇒ Object
Returns the value of attribute template_lookup_options.
Instance Method Summary collapse
- #builder! ⇒ Object
- #found_path! ⇒ Object
- #fragment_context! ⇒ Object
-
#initialize(context = nil, options = {}) ⇒ Template
constructor
A new instance of Template.
- #partial!(**options) ⇒ Object
- #set!(key, options = {}, &block) ⇒ Object (also: #method_missing)
Constructor Details
#initialize(context = nil, options = {}) ⇒ Template
Returns a new instance of Template.
38 39 40 41 42 43 |
# File 'lib/props_template.rb', line 38 def initialize(context = nil, = {}) @builder = BaseWithExtensions.new(self, context, ) @context = context @fragment_context = nil @found_path = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object (private)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/props_template.rb', line 87 def set!(key, = {}, &block) if block && ([:search] || [:dig]) && !@builder.is_a?(Searcher) search = [:search] || [:dig] prev_builder = @builder @builder = Searcher.new(self, search, @context) .delete(:search) .delete(:dig) @builder.set!(key, , &block) found_block, found_path, , fragment_path, fragment_context, found_item = @builder.found! @found_path = found_path || [] @fragment_context = fragment_context @builder = prev_builder @fragment_path = fragment_path if found_block @builder.item_context = found_item set!(key, , &found_block) end else @builder.set!(key, , &block) end end |
Class Attribute Details
.template_lookup_options ⇒ Object
Returns the value of attribute template_lookup_options.
21 22 23 |
# File 'lib/props_template.rb', line 21 def end |
Instance Method Details
#builder! ⇒ Object
83 84 85 |
# File 'lib/props_template.rb', line 83 def builder! @builder end |
#found_path! ⇒ Object
75 76 77 |
# File 'lib/props_template.rb', line 75 def found_path! @found_path[@fragment_path.size..].join(".") end |
#fragment_context! ⇒ Object
79 80 81 |
# File 'lib/props_template.rb', line 79 def fragment_context! @fragment_context end |
#partial!(**options) ⇒ Object
71 72 73 |
# File 'lib/props_template.rb', line 71 def partial!(**) @context.render end |
#set!(key, options = {}, &block) ⇒ Object Also known as: method_missing
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/props_template.rb', line 45 def set!(key, = {}, &block) if block && ([:search] || [:dig]) && !@builder.is_a?(Searcher) search = [:search] || [:dig] prev_builder = @builder @builder = Searcher.new(self, search, @context) .delete(:search) .delete(:dig) @builder.set!(key, , &block) found_block, found_path, , fragment_path, fragment_context, found_item = @builder.found! @found_path = found_path || [] @fragment_context = fragment_context @builder = prev_builder @fragment_path = fragment_path if found_block @builder.item_context = found_item set!(key, , &found_block) end else @builder.set!(key, , &block) end end |