Adds support for rendering Prawn templates using Tilt.
Installation
Add this line to your application's Gemfile:
gem 'tilt-prawn'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tilt-prawn
Usage
Create a Prawn template file with a .prawn
extension
Example, in hello.prawn
:
pdf.text "Hello #{name}"
Then, render the template with Ruby:
require 'tilt/prawn'
template = Tilt.new('hello.prawn')
puts template.render(nil, name: 'Bob')
Customization
Additional convenience methods may be added to the rendering engine:
Tilt::PrawnTemplate.extend_engine do
def date_text(date)
text date.strftime('%b %d, %Y')
end
end
date_text
is now available as an instance method on the renderer:
pdf.date_text(Date.today)
If you defined an external class as a base template, you may use it instead of the default class:
class CustomEngine < Prawn::Document
end
Tilt::PrawnTemplate.engine = CustomEngine
Alternatively, may be passed in as an argument to the template constructor:
template = Tilt.new('hello.prawn', engine: CustomEngine)
puts template.render
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request