https://github.com/fengb/tilt-prawn
https://github.com/fengb/tilt-prawn
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fengb/tilt-prawn
- Owner: fengb
- License: mit
- Created: 2014-07-08T05:54:23.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-06-01T05:32:41.000Z (about 11 years ago)
- Last Synced: 2025-03-28T17:21:44.110Z (about 1 year ago)
- Language: Ruby
- Size: 158 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tilt-prawn [](https://travis-ci.org/fengb/tilt-prawn)
Adds support for rendering [Prawn](http://prawn.majesticseacreature.com/) templates using [Tilt](https://github.com/rtomayko/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`:
```ruby
pdf.text "Hello #{name}"
```
Then, render the template with Ruby:
```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:
```ruby
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:
```ruby
pdf.date_text(Date.today)
```
If you defined an external class as a base template, you may use it instead of
the default class:
```ruby
class CustomEngine < Prawn::Document
end
Tilt::PrawnTemplate.engine = CustomEngine
```
Alternatively, may be passed in as an argument to the template constructor:
```ruby
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