Class: Booky::Layout::Base::NumberedList

Inherits:
Element
  • Object
show all
Includes:
Helpers
Defined in:
lib/booky/layout/base/numbered_list.rb

Constant Summary collapse

OPTIONS =
{
  :align => :justify,
  :size => 12,
  :inline_format => true
}

Instance Attribute Summary

Attributes inherited from Element

#ast, #document, #index, #options

Instance Method Summary collapse

Methods included from Helpers

#add_to_toc, #is_first_rendering?, #update_levels

Methods inherited from Element

#initialize, #method_missing, #next_option, #previous_option

Constructor Details

This class inherits a constructor from Booky::Layout::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Booky::Layout::Element

Instance Method Details

#make_page_breakObject



11
12
13
# File 'lib/booky/layout/base/numbered_list.rb', line 11

def make_page_break
  start_new_page if cursor + 2.cm < bounds.absolute_bottom
end

#to_prawnObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/booky/layout/base/numbered_list.rb', line 15

def to_prawn
  @levels = Hash.new(0)
  @last_level = 0
  
  @options[:items].each do |item|
    indention = 1.cm * (item[:level] + 1)
    
    make_page_break
    
    @levels[item[:level]] += 1
    @levels.each{ |level, number| number = 0 if level > item[:level] }
    
    chain = (0..item[:level]).collect{ |level| @levels[level] } * "."
    current_level = "#{chain}."
    
    fill_color Booky::Layout::Base::COLORS[1]
    text_box current_level, :at => [indention - 2.1.cm, cursor], :width => 2.cm, :style => :italic, :align => :right
    fill_color Booky::Layout::Base::COLORS[0]
    
    span(bounds.width - indention, :position => indention) do
      text item[:text], OPTIONS
    end
    
    move_down 0.2.cm
  end
  
  move_down 0.5.cm
end