Class: Bemer::TemplateCatalog

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload
Defined in:
lib/bemer/template_catalog.rb,
lib/bemer/template_catalog/drawer.rb

Defined Under Namespace

Classes: Drawer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner) ⇒ TemplateCatalog



15
16
17
18
19
# File 'lib/bemer/template_catalog.rb', line 15

def initialize(owner)
  @drawers        = {}
  @owner          = owner
  @template_queue = []
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



13
14
15
# File 'lib/bemer/template_catalog.rb', line 13

def owner
  @owner
end

Instance Method Details

#add(path, cached = false, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/bemer/template_catalog.rb', line 28

def add(path, cached = false, &block)
  return unless block_given?

  id = [block.source_location, path].join(':')

  @template_queue << id

  drawers[id] = Drawer.new(cached, &block) unless drawers.key?(id) && drawers[id].cached?
end

#compiled_templatesObject



21
22
23
24
25
26
# File 'lib/bemer/template_catalog.rb', line 21

def compiled_templates
  template_queue  = @template_queue
  @template_queue = []

  template_queue.flat_map { |id| drawers[id].compiled_templates }
end