Skip to content

Commit ff5ad17

Browse files
committed
Updated documentation.
1 parent 68cd6fb commit ff5ad17

File tree

3 files changed

+33
-52
lines changed

3 files changed

+33
-52
lines changed

AUTHORS

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Bruno Deferrari (tizoc)
2+
* Cyril David (cyx)
3+
* Michel Martens (soveran)

README.markdown

+29-52
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ Minimum Operational Template.
66
Description
77
-----------
88

9-
Mote is the little brother of ERB. It only provides a subset of ERB's
10-
features, but praises itself of being simple--both internally and externally--
11-
and super fast. It was born out of experimentations while discussing
12-
[NOLATE](https://github.com/antirez/nolate), another small library with the
13-
same goals and more features.
9+
Mote is very simple and fast template engine that praises itself of being
10+
simple--both internally and externally-- and super fast.
1411

1512
Usage
1613
-----
@@ -23,37 +20,43 @@ Usage is very similar to that of ERB:
2320
Silly example, you may say, and I would agree. What follows is a short list of
2421
the different use cases you may face:
2522

23+
24+
% if user == "Bruno"
25+
${user} rhymes with Piano
26+
% elsif user == "Brutus"
27+
${user} rhymes with Opus
28+
% end
29+
30+
## Control flow
31+
32+
Lines that start with `%` are evaluated as Ruby code.
33+
2634
## Assignment
2735

28-
example = Mote.parse("<%= \"***\" %>")
29-
assert_equal "***", example.call
36+
Whatever it is between `${` and `}` gets printed in the template.
3037

31-
## Comment
38+
## Comments
3239

33-
example = Mote.parse("*<%# \"*\" %>*")
34-
assert_equal "**", example.call
40+
There's nothing special about comments, it's just a `#` inside your Ruby code:
3541

36-
## Control flow
42+
% # This is a comment.
3743

38-
example = Mote.parse("<% if false %>*<% else %>***<% end %>")
39-
assert_equal "***", example.call
4044

4145
## Block evaluation
4246

43-
example = Mote.parse("<% 3.times { %>*<% } %>")
44-
assert_equal "***", example.call
47+
As with control instructions, it happens naturally:
48+
49+
% 3.times do |i|
50+
${i}
51+
% end
4552

4653
## Parameters
4754

48-
example = Mote.parse("<% params[:n].times { %>*<% } %>")
49-
assert_equal "***", example[n: 3]
50-
assert_equal "****", example[n: 4]
55+
The values passed to the template are available as local variables:
5156

52-
Two things are worth noting in the last example: the first is that as the
53-
returned value is a `Proc`, you can call it with square brackets and anything
54-
you put inside becomes a parameter. Second, that within the template you have
55-
access to those parameters through the `params` hash, instead of the usual
56-
approach of converting each key to a local variable.
57+
example = Mote.parse("Hello ${name}")
58+
assert_equal "Hello world", example.call(name: "world")
59+
assert_equal "Hello Bruno", example.call(name: "Bruno")
5760

5861
# Helpers
5962

@@ -69,46 +72,20 @@ Here are the available helpers:
6972
The `mote` helper receives a template string and returns the rendered version
7073
of it:
7174

72-
assert_equal "1 2 3", mote("1 <%= 2 %> 3")
75+
assert_equal "1 2 3", mote("1 ${2} 3")
7376

7477
It works with parameters too:
7578

76-
assert_equal "1 2 3", mote("1 <%= params[:n] %> 3", :n => 2)
79+
assert_equal "1 2 3", mote("1 ${n} 3", n: 2)
7780

7881
## mote_file
7982

8083
The `mote_file` helper receives a file name and returns the rendered version of
8184
its content. The compiled template is cached for subsequent calls.
8285

83-
assert_equal "***\n", mote_file("test/basic.erb", :n => 3)
86+
assert_equal "***\n", mote_file("test/basic.erb", n: 3)
8487

8588
Installation
8689
------------
8790

8891
$ gem install mote
89-
90-
License
91-
-------
92-
93-
Copyright (c) 2011 Michel Martens
94-
95-
Permission is hereby granted, free of charge, to any person
96-
obtaining a copy of this software and associated documentation
97-
files (the "Software"), to deal in the Software without
98-
restriction, including without limitation the rights to use,
99-
copy, modify, merge, publish, distribute, sublicense, and/or sell
100-
copies of the Software, and to permit persons to whom the
101-
Software is furnished to do so, subject to the following
102-
conditions:
103-
104-
The above copyright notice and this permission notice shall be
105-
included in all copies or substantial portions of the Software.
106-
107-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
108-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
109-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
110-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
111-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
112-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
113-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
114-
OTHER DEALINGS IN THE SOFTWARE.

mote.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
1010
s.homepage = "https://github.com/soveran/mote"
1111
s.files = Dir[
1212
"LICENSE",
13+
"AUTHORS",
1314
"README.markdown",
1415
"Rakefile",
1516
"lib/**/*.rb",

0 commit comments

Comments
 (0)