The roda-papercraft Roda plugin adds some methods to let you render
Papercraft templates in your Roda app.
This plugin lets you either define templates inline inside your Roda router, or
load templates from files. This repository includes an example directory with an
example Roda app showing typical use.
To use Papercraft with Roda, do the following:
In your Gemfile, add the following line:
gem "roda-papercraft"In your Roda app, load roda-papercraft:
require "roda-papercraft"Then load the plugin inside your app:
class App < Roda
plugin :papercraft
...
endBy default, the template root is "templates" (relative to the working
directory). To change the template root, you can configure the plugin:
class App < Roda
plugin :papercraft
...
endYour template files are normal Ruby source files. Each file should contain a single lambda. Here's an example:
# templates/hello.rb
-> {
h1 "Hello from Papercraft"
}To render the template, first load it using the #template method, and then run
#render on it:
route do |r|
r.get "hello" do
template("hello").render
end
...
endIf the template takes arguments, you can pass them through the #render call:
# templates/greet.rb
->(name) {
h1 "Hello, #{name}!"
}
# in your app
route do |r|
r.get "greet", String do |name|
template("greet").render(name)
end
...
endTo render templates inline, just use #render directly.
route do |r|
r.get "hello" do
render {
h1 "Hello from Papercraft"
}
end
endI gladly accept contributions to roda-papercraft. Please feel free to open issues or PRs.