Class: Kramdown::Converter::Pdf
- Inherits:
-
Base
- Object
- Base
- Kramdown::Converter::Pdf
- Includes:
- Prawn::Measurements
- Defined in:
- lib/kramdown/converter/pdf.rb
Overview
Converts an element tree to a PDF using the prawn PDF library.
This basic version provides a nice starting point for customizations but can also be used directly.
There can be the following two methods for each element type: render_TYPE(el, opts) and TYPE_options(el, opts) where el
is a kramdown element and opts
an hash with rendering options.
The render_TYPE(el, opts) is used for rendering the specific element. If the element is a span element, it should return a hash or an array of hashes that can be used by the #formatted_text method of Prawn::Document. This method can then be used in block elements to actually render the span elements.
The rendering options are passed from the parent to its child elements. This allows one to define general options at the top of the tree (the root element) that can later be changed or amended.
Currently supports the conversion of all elements except those of the following types:
:html_element, :img, :footnote
Defined Under Namespace
Modules: PrawnDocumentExtension
Constant Summary collapse
- VERSION =
'1.0.6'
- DISPATCHER_RENDER =
:nodoc:
Hash.new {|h, k| h[k] = "render_#{k}" }
- DISPATCHER_OPTIONS =
:nodoc:
Hash.new {|h, k| h[k] = "#{k}_options" }
Instance Method Summary collapse
-
#apply_template_after? ⇒ Boolean
Returns
false
. -
#apply_template_before? ⇒ Boolean
PDF templates are applied before conversion.
-
#convert(el, opts = {}) ⇒ Object
Invoke the special rendering method for the given element
el
. -
#initialize(root, options) ⇒ Pdf
constructor
A new instance of Pdf.
Constructor Details
Instance Method Details
#apply_template_after? ⇒ Boolean
Returns false
.
63 64 65 |
# File 'lib/kramdown/converter/pdf.rb', line 63 def apply_template_after? false end |
#apply_template_before? ⇒ Boolean
PDF templates are applied before conversion. They should contain code to augment the converter object (i.e. to override the methods).
58 59 60 |
# File 'lib/kramdown/converter/pdf.rb', line 58 def apply_template_before? true end |
#convert(el, opts = {}) ⇒ Object
Invoke the special rendering method for the given element el
.
A PDF destination is also added at the current location if th element has an ID or if the element is of type :header and the :auto_ids option is set.
74 75 76 77 78 79 80 81 82 |
# File 'lib/kramdown/converter/pdf.rb', line 74 def convert(el, opts = {}) id = el.attr['id'] id = generate_id(el.[:raw_text]) if !id && @options[:auto_ids] && el.type == :header if !id.to_s.empty? && !@dests.key?(id) @pdf.add_dest(id, @pdf.dest_xyz(0, @pdf.y)) @dests[id] = @pdf.dest_xyz(0, @pdf.y) end send(DISPATCHER_RENDER[el.type], el, opts) end |