Class: Props::ExtensionManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, defered = [], fragments = []) ⇒ ExtensionManager

Returns a new instance of ExtensionManager.



5
6
7
8
9
10
11
12
13
# File 'lib/props_template/extension_manager.rb', line 5

def initialize(base, defered = [], fragments = [])
  @base = base
  @context = base.context
  @builder = base.builder
  @fragment = Fragment.new(base, fragments)
  @deferment = Deferment.new(base, defered)
  @partialer = Partialer.new(base, context, builder)
  @cache = Cache.new(@context)
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



3
4
5
# File 'lib/props_template/extension_manager.rb', line 3

def base
  @base
end

#builderObject (readonly)

Returns the value of attribute builder.



3
4
5
# File 'lib/props_template/extension_manager.rb', line 3

def builder
  @builder
end

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/props_template/extension_manager.rb', line 3

def context
  @context
end

Instance Method Details

#deferredObject



35
36
37
# File 'lib/props_template/extension_manager.rb', line 35

def deferred
  @deferment.deferred
end

#disable_defermentsObject



15
16
17
# File 'lib/props_template/extension_manager.rb', line 15

def disable_deferments
  @deferment.disable!
end

#fragmentsObject



39
40
41
# File 'lib/props_template/extension_manager.rb', line 39

def fragments
  @fragment.fragments
end

#handle(options) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/props_template/extension_manager.rb', line 47

def handle(options)
  return yield if !has_extensions(options)

  if options[:defer] && !@deferment.disabled
    placeholder = @deferment.handle(options)
    base.stream.push_value(placeholder)
    @fragment.handle(options)
  else
    handle_cache(options) do
      base.set_block_content! do
        if options[:partial]
          @fragment.handle(options)
          @partialer.handle(options)
        else
          yield
        end

        if options[:key]
          id, val = options[:key]
          base.set!(id, val)
        end
      end
    end
  end
end

#has_extensions(options) ⇒ Object



43
44
45
# File 'lib/props_template/extension_manager.rb', line 43

def has_extensions(options)
  options[:defer] || options[:cache] || options[:partial] || options[:key]
end

#refine_all_item_options(all_options) ⇒ Object



28
29
30
31
32
33
# File 'lib/props_template/extension_manager.rb', line 28

def refine_all_item_options(all_options)
  return all_options if all_options.empty?

  all_options = @partialer.find_and_add_template(all_options)
  @cache.multi_fetch_and_add_results(all_options)
end

#refine_options(options, item = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/props_template/extension_manager.rb', line 19

def refine_options(options, item = nil)
  options = @partialer.refine_options(options, item)
  if !@deferment.disabled
    options = @deferment.refine_options(options, item)
  end

  Cache.refine_options(options, item)
end