Class: Elegant::Document

Inherits:
Prawn::Document
  • Object
show all
Defined in:
lib/elegant/document.rb

Overview

A wrapper around Prawn::Document that enforces an elegant layout, setting nice dimensions and margins so that each page can fit up to three sections of content properly aligned along the vertical axis.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Document

Creates a new Elegant Document. available, plus the following extra options.

Parameters:

  • options. (Hash)

    All the options of Prawn::Document are

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :header (Hash) — default: {}

    The options for the header. Accepted values are :text (the title to write in the top-right corner) and :logo (a Hash with a :url key with the location of the logo image and

    optional :width and :height, which default to 50x50).
    
  • :footer (Hash) — default: {}

    The options for the footer. Accepted values are :text (the text in the bottom-center of the page which may include a link which will be formatted inline).

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/elegant/document.rb', line 22

def initialize(options = {}, &block)
  options = options.dup
  @header = Header.new self, options.delete(:header) {{}}
  @footer = Footer.new self, options.delete(:footer) {{}}

  super(with_elegant options) do
    Typography.new(self).set_fonts
    @header.render

    if block
      block.arity < 1 ? instance_eval(&block) : block[self]
    end

    @footer.render
  end
end

Instance Method Details

#header_heightObject

Determines the total height occupied by the header



53
54
55
# File 'lib/elegant/document.rb', line 53

def header_height
  50
end

#title(text, options = {}) ⇒ Object

An additional method provided by Elegant::Document to render a title with an elegant font and padding above and below.



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

def title(text, options = {})
  move_down 10

  width = bounds.width - @header.title_padding
  title = text_options.merge text: text.upcase, color: '556270', size: 14
  options = {width: width, height: 30, at: [0, cursor]}
  formatted_text_box [title], options

  move_down 30
end