Create custom file extensions in Sinatra and other Tilt compatible frameworks that transform HTML via the HTML Pipeline.
Add this line to your application's Gemfile:
gem 'tilt-html-pipeline', require: 'tilt/html/pipeline'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tilt-html-pipeline
Say you're building an API documentation site in Sinatra and you want all of your markdown to be rendered with a table of contents and code highlighting. Just invent your own apidoc
file extension!
require 'sinatra'
require 'html/pipeline'
require 'tilt/html/pipeline'
Tilt.register_html_pipeline :apidoc, [
HTML::Pipeline::MarkdownFilter,
HTML::Pipeline::SyntaxHighlightFilter,
HTML::Pipeline::TableOfContentsFilter
]
# Renders ./views/index.apidoc
get "/" do
render(:apidoc, :index)
end
Any file that ends in .apidoc
will be filtered by HTML::Filter
. Since Tilt lets you chain templates, you could get crazy and include stuff like A/B testing via index.ab-test.apidoc.erb
.
Pretty cool, huh?
- Fork it ( https://github.com/bradgessler/tilt-html-pipeline/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
You may also contribute HTML Pipeline filters at https://github.com/jch/html-pipeline.