Project

feather

0.0
No commit activity in last 3 years
No release in over 3 years
A simple light-weight text templating system
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

feather

A simple text template system inspired by Mustache for generating output for a variety of uses including plain-text, HTML, and JavaScript.

Examples

The straight-forward usage is substitutions:

template = Feather::Template.new("This {{noun}} is {{adjective}}")

template.render(:noun => 'shoe', :adjective => 'red')
# => "This shoe is red"

If required, the content can be HTML-escaped automatically:

template = Feather::Template.new(
  "This {{noun}} is {{adjective}}",
  :escape => :html
)

template.render(:noun => 'goose', :adjective => '<em>blue</em>')
# => "This goose is &lt;em&gt;blue&lt;/em&gt;"

This can also be engaged on a case-by-case basis:

template = Feather::Template.new("This {{&noun}} is {{adjective}}")

template.render(:noun => '<b>goose</b>', :adjective => '<em>blue</em>')
# => "This &lt;b&gt;goose&lt;/b&gt; is <em>blue</em>"

Also available is URI encoding for links:

template = Feather::Template.new(
  "<a href='/home?user_id={{%user_id}}'>{{&label}}</a>"
)

template.render(:user_id => 'joe&2', :label => 'Joe&2')
# => "<a href='/home?user_id=joe%262'>Joe&amp;2</a>"

A sample template is located in:

notes/example.ft

A number of other usage cases are described in test/test_feather_template.rb as a reference.

Copyright

Copyright (c) 2011-2019 Scott Tadman, PostageApp Ltd. See LICENSE.txt for further details.