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



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

def deferred
  @deferment.deferred
end

#fragmentsObject



32
33
34
# File 'lib/props_template/extension_manager.rb', line 32

def fragments
  @fragment.fragments
end

#handle(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/props_template/extension_manager.rb', line 40

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

  if options[:defer]
    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



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

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

#refine_all_item_options(all_options) ⇒ Object



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

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



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

def refine_options(options, item = nil)
  options = @partialer.refine_options(options, item)
  options = @deferment.refine_options(options, item)
  Cache.refine_options(options, item)
end