Project

tilt-prawn

0.0
No commit activity in last 3 years
No release in over 3 years
tilt-prawn integrates prawn with tilt
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0

Runtime

< 3.0, >= 1.0
< 3.0, >= 1.4
 Project Readme

tilt-prawn Build Status

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request