Class: ChiliPDF::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/chili_pdf/formatter.rb

Constant Summary collapse

8
DEFAULT_MARGIN =
'0.5in'
DEFAULT_PAGE_SIZE =
"Letter"
DEFAULT_PAGE_TITLE =
"Untitled"
DEFAULT_LAYOUT =
'pdf.pdf.erb'
DEFAULT_VIEW_TEMPLATE =
'extended_wiki/show.pdf.html.erb'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, title = nil, render_html_version = nil) ⇒ Formatter

Returns a new instance of Formatter.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chili_pdf/formatter.rb', line 18

def initialize(filename, title = nil, render_html_version = nil)
  @page_title = title
  @filename = filename
  @allow_debugging = render_html_version

  # TODO: Hack...need to come up with better approach for this...
  TokenManager.add_token_definition do
    {:page_title => {:replacement_object => (@page_title || DEFAULT_PAGE_TITLE),
                     :description        => "The project & wiki page name (eg: 'My Project, Wiki Page Title')"}}
  end
end

Instance Attribute Details

#page_titleObject (readonly)

Returns the value of attribute page_title.



10
11
12
# File 'lib/chili_pdf/formatter.rb', line 10

def page_title
  @page_title
end

Instance Method Details

#render_optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chili_pdf/formatter.rb', line 30

def render_options
  default_options = {
    :pdf => @filename,
    :template => view_template,
    :page_size => DEFAULT_PAGE_SIZE,
    :show_as_html => render_as_html?,
    :margin => {
      :top    => DEFAULT_MARGIN,
      :bottom => DEFAULT_MARGIN,
      :left   => DEFAULT_MARGIN,
      :right  => DEFAULT_MARGIN
    },
    :layout => DEFAULT_LAYOUT
  }

  default_options.merge!(footer_options) if ChiliPDF::Config.footer_enabled?
  default_options.merge!(header_options) if ChiliPDF::Config.header_enabled?
  default_options
end