Class: Booky::Layout::Base::Image

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

Constant Summary collapse

OPTIONS =
{
  :align => :left,
  :size => 12
}

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

#create_headingObject



10
11
12
13
14
15
16
17
# File 'lib/booky/layout/base/image.rb', line 10

def create_heading
  return unless @options[:title]
  
  fill_color Booky::Layout::Base::COLORS[1]
  text @options[:title], OPTIONS
  fill_color Booky::Layout::Base::COLORS[0]
  move_down 0.2.cm
end

#create_imageObject



19
20
21
22
23
24
25
# File 'lib/booky/layout/base/image.rb', line 19

def create_image
  width = bounds.width * (@options[:width].to_f / 100)
  path = File.join(File.dirname(Booky.source), @options[:src])
  image path, :position => :left, :width => width
  
  move_down 1.cm
end

#start_new_page_if_neededObject



27
28
29
# File 'lib/booky/layout/base/image.rb', line 27

def start_new_page_if_needed
  start_new_page if cursor < (bounds.bottom + 4.cm)
end

#to_prawnObject



31
32
33
34
35
36
# File 'lib/booky/layout/base/image.rb', line 31

def to_prawn
  start_new_page_if_needed
  
  create_heading
  create_image
end