Class: Prawn::ManualBuilder::Chapter

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

Instance Attribute Summary

Attributes inherited from Part

#auto_render, #manual, #page_number, #path

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Chapter

Returns a new instance of Chapter.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/prawn/manual_builder/chapter.rb', line 11

def initialize(&block)
  super

  if block
    instance_eval(&block)
  else
    warn "Chapter defined in #{__FILE__} has no content"
  end

  self.auto_render = true
  at_exit do
    if self.auto_render
      execute_example
    end
  end
end

Instance Method Details

#eval_example?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/prawn/manual_builder/chapter.rb', line 63

def eval_example?
  @eval_example
end

#example(source = NOT_SET, axes: false, new_page: false, eval: true, standalone: false, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/prawn/manual_builder/chapter.rb', line 45

def example(source = NOT_SET, axes: false, new_page: false, eval: true, standalone: false, &block)
  if source == NOT_SET && !block_given?
    @example
  elsif source != NOT_SET && block_given?
    raise ArgumentError, "Example can't be specified both as a block and as a string"
  else
    if source != NOT_SET
      @example = source
    else
      @example = block
    end
    @example_axes = axes
    @eval_example = eval
    @standalone_example = standalone
    @new_page_example = new_page
  end
end

#example_axes?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/prawn/manual_builder/chapter.rb', line 75

def example_axes?
  @example_axes
end

#new_page_example?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/prawn/manual_builder/chapter.rb', line 71

def new_page_example?
  @new_page_example
end

#render(doc) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/prawn/manual_builder/chapter.rb', line 79

def render(doc)
  doc.start_new_page(margin: PAGE_MARGIN)
  @page_number = doc.page_number

  chapter_header(doc)

  inner_box(doc) do
    TextRenderer.new(doc, &text).render
  end

  example_source(doc)

  if eval_example? && !standalone_example?
    eval_example(doc)
  end

  unless eval_example?
    standalone_example(doc)
  end
end

#standalone_example?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/prawn/manual_builder/chapter.rb', line 67

def standalone_example?
  @standalone_example
end

#text(&block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/prawn/manual_builder/chapter.rb', line 37

def text(&block)
  if !block_given?
    @text
  else
    @text = block
  end
end

#title(title = NOT_SET) ⇒ Object

Chapter DSL



29
30
31
32
33
34
35
# File 'lib/prawn/manual_builder/chapter.rb', line 29

def title(title = NOT_SET)
  if title == NOT_SET
    @title
  else
    @title = title
  end
end

#to_sObject



100
101
102
# File 'lib/prawn/manual_builder/chapter.rb', line 100

def to_s
  super[-2, 0] = " path: #{path}"
end