Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Minimum Operational Template
Ruby VimL HTML

This branch is 1 commit ahead, 30 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
benchmarks
bin
extras
lib
test
.gems
.gitignore
AUTHORS
LICENSE
README.md
Rakefile
mote.gemspec

README.md

Mote

Minimum Operational Template.

Description

Mote is a very simple and fast template engine.

Usage

Usage is very similar to that of ERB:

template = Mote.parse("This is a template")
template.call #=> "This is a template"

Silly example, you may say, and I would agree. What follows is a short list of the different use cases you may face:

% if user == "Bruno"
  {{user}} rhymes with Piano
% elsif user == "Brutus"
  {{user}} rhymes with Opus
% end

Control flow

Lines that start with % are evaluated as Ruby code.

Assignment

Whatever it is between {{ and }} gets printed in the template.

Comments

There's nothing special about comments, it's just a # inside your Ruby code:

% # This is a comment.

Block evaluation

As with control instructions, it happens naturally:

% 3.times do |i|
  {{i}}
% end

Parameters

The values passed to the template are available as local variables:

example = Mote.parse("Hello {{name}}")
assert_equal "Hello world", example.call(name: "world")
assert_equal "Hello Bruno", example.call(name: "Bruno")

Helpers

There's a helper available in the Mote::Helpers module, and you are free to include it in your code. To do it, just type:

include Mote::Helpers

mote

The mote helper receives a file name and a hash and returns the rendered version of its content. The compiled template is cached for subsequent calls.

assert_equal "***\n", mote("test/basic.mote", n: 3)

Installation

As usual, you can install it using rubygems.

$ gem install mote
Something went wrong with that request. Please try again.