Class: Codnar::Weaver

Inherits:
Reader
  • Object
show all
Defined in:
lib/codnar/weaver.rb

Overview

Weave all chunks to a unified HTML.

Constant Summary collapse

FILE_TEMPLATE_PROCESSORS =

How to process each magical file template.

{
  "file" => lambda { |name, data| data },
  "image" => lambda { |name, data| Weaver.embedded_base64_img_tag(name, data) },
}

Instance Method Summary collapse

Methods inherited from Reader

#[], #collect_unused_chunk_errors

Constructor Details

#initialize(errors, paths, templates) ⇒ Weaver

Load all chunks from the specified disk files to memory for weaving using the specified templates.



8
9
10
11
# File 'lib/codnar/weaver.rb', line 8

def initialize(errors, paths, templates)
  super(errors, paths)
  @templates = templates
end

Instance Method Details

#weave(template, chunk_name = @root_chunk) ⇒ Object

Weave the HTML for a named chunk.



20
21
22
23
24
25
# File 'lib/codnar/weaver.rb', line 20

def weave(template, chunk_name = @root_chunk)
  return process_file_template(template, chunk_name) if FILE_TEMPLATE_PROCESSORS.include?(template)
  @last_chunk = chunk = self[chunk_name.to_id]
  expand_chunk_html(chunk)
  return process_template(chunk, template)
end