Class: Prawn::ManualBuilder::ExamplePackage

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/manual_builder/example_package.rb

Overview

The Prawn::ManualBuilder::ExamplePackage class is a utility class to handle the packaging of individual examples within a hierarchy when building the manual.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_name) ⇒ ExamplePackage

Returns a new instance of ExamplePackage.



11
12
13
14
# File 'lib/prawn/manual_builder/example_package.rb', line 11

def initialize(folder_name)
  @folder_name = folder_name
  @hierarchy = []
end

Instance Attribute Details

#folder_nameObject (readonly)

Returns the value of attribute folder_name.



9
10
11
# File 'lib/prawn/manual_builder/example_package.rb', line 9

def folder_name
  @folder_name
end

#intro_blockObject (readonly)

Returns the value of attribute intro_block.



9
10
11
# File 'lib/prawn/manual_builder/example_package.rb', line 9

def intro_block
  @intro_block
end

Instance Method Details

#example(filename, options = {}) ⇒ Object

Stores a new ExampleFile in the hierarchy



26
27
28
# File 'lib/prawn/manual_builder/example_package.rb', line 26

def example(filename, options={})
  @hierarchy << ExampleFile.new(self, "#{filename}.rb", options)
end

#intro(&block) ⇒ Object

Stores a block with code to be evaluated when rendering the package cover



32
33
34
# File 'lib/prawn/manual_builder/example_package.rb', line 32

def intro(&block)
  @intro_block = block
end

#nameObject

Returns a human friendly version of the package name



38
39
40
# File 'lib/prawn/manual_builder/example_package.rb', line 38

def name
  @name ||= @folder_name.gsub("_", " ").capitalize
end

#render(pdf) ⇒ Object

Renders a cover page for the package to a pdf and iterates the examples hierarchy delegating the examples and sections to be rendered as well



45
46
47
48
49
50
51
# File 'lib/prawn/manual_builder/example_package.rb', line 45

def render(pdf)
  pdf.render_package_cover(self)
  
  @hierarchy.each do |node|
    node.render(pdf)
  end
end

#section(name) {|s| ... } ⇒ Object

Stores a new ExampleSection in the hierarchy and yields it to a block

Yields:

  • (s)


18
19
20
21
22
# File 'lib/prawn/manual_builder/example_package.rb', line 18

def section(name)
  s = ExampleSection.new(self, name)
  yield s
  @hierarchy << s
end