Class: ERBook::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/erbook/document.rb

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format_name, input_text, input_file, options = {}) ⇒ Document

Parameters

format_name

Either the short-hand name of a built-in format or the path to a format specification file.

input_text

The body of the input document.

input_file

Name of the file from which the input document originated.

Options

:unindent

If true, all node content is unindented hierarchically.



42
43
44
45
46
47
48
49
50
# File 'lib/erbook/document.rb', line 42

def initialize format_name, input_text, input_file, options = {}
  load_format format_name

  @input_text = input_text
  @input_file = input_file
  @options    = options

  process_input_document
end

Instance Attribute Details

#formatObject (readonly)

Data from the format specification file.



13
14
15
# File 'lib/erbook/document.rb', line 13

def format
  @format
end

#nodesObject (readonly)

All nodes in the document.



19
20
21
# File 'lib/erbook/document.rb', line 19

def nodes
  @nodes
end

#nodes_by_typeObject (readonly)

All nodes in the document arranged by node type.



22
23
24
# File 'lib/erbook/document.rb', line 22

def nodes_by_type
  @nodes_by_type
end

#rootsObject (readonly)

All root nodes in the document.



16
17
18
# File 'lib/erbook/document.rb', line 16

def roots
  @roots
end

Instance Method Details

#to_sObject

Returns the output of this document.



55
56
57
58
# File 'lib/erbook/document.rb', line 55

def to_s
  Template.new("#{@format_file}:output", @format['output'].to_s).
  render_with(@template_vars.merge(:@content => @evaluated_document.join))
end