Project

tmplt

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Interpolate values from a hash or array into a template string.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

Tmplt.rb Gem Version Build Status Coverage Status

A Ruby gem for interpolating values from a hash or array into a template string.

Usage

Straight-up substitution, nothing more. Here’s a slightly contrived example:

require 'tmplt'

tmpl = "{{ foo }}, {{ baz.qux }}!"
data = {
  :foo => "Hello",
  :bar => "World",
  :baz => {
    :qux => Proc.new {|d| "#{d[:bar]}" }
  }
}
puts Tmplt.render(tmpl, data) #=> "Hello, World!"

More usage examples are in the tests.

API

Tmplt.render(tmpl, data)

Interpolates values from data into the tmpl string.

  • tmpl is a string with tags enclosed in double braces. Use a dot-delimited tag to reference nested values in data.

  • data can be a hash or array, with arbitrary nesting. If a proc in data is referenced in tmpl, it will be invoked, and its return value will be substituted into tmpl. The proc takes a single argument, namely the data object itself.

Installation

Install via RubyGems:

$ gem install tmplt

License

MIT license