Class: Props::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/props_template.rb

Class Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @builder = BaseWithExtensions.new(self, context, options)
  @context = context
  @fragment_context = nil
  @found_path = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject (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, options = {}, &block)
  if block && (options[:search] || options[:dig]) && !@builder.is_a?(Searcher)
    search = options[:search] || options[:dig]

    prev_builder = @builder
    @builder = Searcher.new(self, search, @context)

    options.delete(:search)
    options.delete(:dig)

    @builder.set!(key, options, &block)
    found_block, found_path, found_options, 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_options, &found_block)
    end
  else
    @builder.set!(key, options, &block)
  end
end

Class Attribute Details

.template_lookup_optionsObject

Returns the value of attribute template_lookup_options.



21
22
23
# File 'lib/props_template.rb', line 21

def template_lookup_options
  @template_lookup_options
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!(**options)
  @context.render options
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, options = {}, &block)
  if block && (options[:search] || options[:dig]) && !@builder.is_a?(Searcher)
    search = options[:search] || options[:dig]

    prev_builder = @builder
    @builder = Searcher.new(self, search, @context)

    options.delete(:search)
    options.delete(:dig)

    @builder.set!(key, options, &block)
    found_block, found_path, found_options, 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_options, &found_block)
    end
  else
    @builder.set!(key, options, &block)
  end
end