Skip to content

fengb/tilt-prawn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages