Native PDF generation for Spontaneous CMS.
Adds a new .prawn
template type that consists of ruby code evaluated as a
template.
Add this line to your application's Gemfile:
gem 'spontaneous_prawn'
And then execute:
$ bundle
Or install it yourself as:
$ gem install spontaneous_prawn
In your spontaneous schema, add a :pdf
output to the relevant page types
class Page < Content::Page
add_output :pdf, config: { ... }
end
Where config
is a hash of valid Prawn::Document configuration parameters (see
prawn/document.rb).
Then add the required templates, e.g. templates/layouts/page.pdf.prawn
:
# templates/layouts/page.pdf.prawn
pdf.text title
The template is evaluated in the context of the currently rendered content (as
per text/html templates). PDF layout commands are run on a pdf
instance that
is a special spontaneous-aware proxy to Prawn::Document
that translates
content objects into the right format (e.g. string fields -> strings)
See the prawn documentation for usage and commands available on the pdf
object.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
In order to test, you need a sqlite db in db
. Create using the sequel command line tool.
bundle exec sequel -m $(bundle show spontaneous)/db/migrations sqlite://db/development.sqlite3
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/spontaneous_prawn.
The gem is available as open source under the terms of the MIT License.