No release in over 3 years
Low commit activity in last 3 years
Minimalistic templates engine
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

< 3, >= 2.12.8
>= 0
>= 0
 Project Readme

Build Status No Maintenance Intended

⚠️ Warning: This library has been deprecated and is no longer maintained. It will not receive any further security patches, features, or bug fixes and is preserved here at GitHub for archival purposes. If you want to use it, we suggest forking the repository and auditing the codebase before use. For more information, contact us at info@stackbuilders.com.

DEPRECATED - simple_templates

simple_templates is a minimalistic templates engine. This gem allows you to work with several types of templates.

Installation

Clone the project

git@github.com:stackbuilders/simple_templates.git

Install the dependencies

bundle install

Run the tests

rake test

Quick Start

The basic use of the library can be seen like this:

You can send a String with the raw input that includes your placeholders and a list of String containing the allowed placeholders, if it is nil, then all the placeholders are allowed.

A example without errors, that allows us to call the method render

  template = SimpleTemplates.parse("Hi <name>", %w[name])
  template.render({ name: "Bob" }) if template.errors.empty?
  => "Hi Bob"
  template.remaining_tokens
  => []

An example with errors. Since the allowed placeholder is not in the raw input. So we get are going to get a list of errors when parsing

  template = SimpleTemplates.parse("Hi <name>", %w[date])
  template.errors
  => [...] # unknown placeholder

Serialization Support

You can serialize a template out of the box by calling the method to_json.

  template = SimpleTemplates.parse("Hi <name>", %w[name])
  template.to_json
  # => "{\"ast\":[{\"contents\":\"Hi...

You can also deserialize a serialized template.

  SimpleTemplates::Template.from_json(template.to_json)
  # => #<SimpleTemplates::Template:0x007fad96056ae0...

Tasks

The default task executed by rake is only

rake test

Additionally you can generate the documentation by running

rake docs

License

MIT. See LICENSE


Stack Builders
Check out our libraries | Join our team