Class: Zena::Use::ZafuTemplates::AssetCache

Inherits:
Object
  • Object
show all
Defined in:
lib/zena/use/zafu_templates.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssetCache

Returns a new instance of AssetCache.



9
10
11
12
13
# File 'lib/zena/use/zafu_templates.rb', line 9

def initialize
  @used_assets  = {'zafu' => [], 'images' => [], 'assets' => []}
  @cached_nodes = {}
  @used_assets['zafu'] = []
end

Instance Attribute Details

#used_assetsObject

Returns the value of attribute used_assets.



7
8
9
# File 'lib/zena/use/zafu_templates.rb', line 7

def used_assets
  @used_assets
end

Instance Method Details

#cache_with_path(section_id, path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zena/use/zafu_templates.rb', line 15

def cache_with_path(section_id, path)
  if cached = @cached_nodes[[section_id, path]]
    return cached
  else
    if document = yield
      if document.kind_of?(Template)
        @used_assets['zafu']   << [path, document]
      elsif document.kind_of?(Image)
        @used_assets['images'] << [path, document]
      else
        @used_assets['assets'] << [path, document]
      end
      @cached_nodes[[section_id, path]] = document
    else
      nil
    end
  end
end

#used_nodesObject



34
35
36
# File 'lib/zena/use/zafu_templates.rb', line 34

def used_nodes
  @cached_nodes.values
end