Skip to content

Commit 235050c

Browse files
author
Cyril David
committed
Replace ${ } with {{ }} (via @tizoc, @soveran).
1 parent e3e9cec commit 235050c

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

README.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ the different use cases you may face:
2222

2323

2424
% if user == "Bruno"
25-
${user} rhymes with Piano
25+
{{user}} rhymes with Piano
2626
% elsif user == "Brutus"
27-
${user} rhymes with Opus
27+
{{user}} rhymes with Opus
2828
% end
2929

3030
## Control flow
@@ -33,7 +33,7 @@ Lines that start with `%` are evaluated as Ruby code.
3333

3434
## Assignment
3535

36-
Whatever it is between `${` and `}` gets printed in the template.
36+
Whatever it is between `{{` and `}}` gets printed in the template.
3737

3838
## Comments
3939

@@ -47,14 +47,14 @@ There's nothing special about comments, it's just a `#` inside your Ruby code:
4747
As with control instructions, it happens naturally:
4848

4949
% 3.times do |i|
50-
${i}
50+
{{i}}
5151
% end
5252

5353
## Parameters
5454

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

57-
example = Mote.parse("Hello ${name}")
57+
example = Mote.parse("Hello {{name}}")
5858
assert_equal "Hello world", example.call(name: "world")
5959
assert_equal "Hello Bruno", example.call(name: "Bruno")
6060

@@ -75,4 +75,4 @@ version of its content. The compiled template is cached for subsequent calls.
7575
Installation
7676
------------
7777

78-
$ gem install mote
78+
$ gem install mote

benchmarks/src/complex.mote

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<title>Simple Benchmark</title>
66
</head>
77
<body>
8-
<h1>${ params[:header] }</h1>
8+
<h1>{{ params[:header] }}</h1>
99
% unless params[:item].empty?
1010
<ul>
1111
% for i in params[:item]
1212
% if i[:current]
13-
<li><strong>${ i[:name] }</strong></li>
13+
<li><strong>{{ i[:name] }}</strong></li>
1414
% else
15-
<li><a href="${ i[:url] }">${ i[:name] }</a></li>
15+
<li><a href="{{ i[:url] }}">{{ i[:name] }}</a></li>
1616
% end
1717
% end
1818
</ul>

lib/mote.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
# THE SOFTWARE.
2020
class Mote
21-
VERSION = "0.1.0"
21+
VERSION = "0.0.2"
2222

2323
def self.parse(template, context = self, vars = [])
24-
terms = template.split(/^\s*(%)(.*?)$|(\$\{)(.*?)\}/)
24+
terms = template.split(/^\s*(%)(.*?)$|(\{\{)(.*?)\}\}/)
2525

2626
parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
2727

@@ -32,7 +32,7 @@ def self.parse(template, context = self, vars = [])
3232
while term = terms.shift
3333
case term
3434
when "%" then parts << "#{terms.shift}\n"
35-
when "${" then parts << "__o << (#{terms.shift}).to_s\n"
35+
when "{{" then parts << "__o << (#{terms.shift}).to_s\n"
3636
else parts << "__o << #{term.inspect}\n"
3737
end
3838
end
@@ -52,4 +52,4 @@ def mote_cache
5252
Thread.current[:_mote_cache] ||= {}
5353
end
5454
end
55-
end
55+
end

test/mote_test.rb

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
scope do
44
test "assignment" do
5-
example = Mote.parse("${ \"***\" }")
5+
example = Mote.parse("{{ \"***\" }}")
66
assert_equal "***", example.call
77
end
88

@@ -54,7 +54,7 @@
5454
end
5555

5656
test "multiline" do
57-
example = Mote.parse("The\nMan\nAnd\n${\"The\"}\nSea")
57+
example = Mote.parse("The\nMan\nAnd\n{{\"The\"}}\nSea")
5858
assert_equal "The\nMan\nAnd\nThe\nSea", example[:n => 3]
5959
end
6060

@@ -67,16 +67,21 @@
6767
context = Object.new
6868
context.instance_variable_set(:@user, "Bruno")
6969

70-
example = Mote.parse("${ @user }", context)
70+
example = Mote.parse("{{ @user }}", context)
7171
assert_equal "Bruno", example.call
7272
end
7373

7474
test "locals" do
7575
context = Object.new
7676

77-
example = Mote.parse("${ user }", context, [:user])
77+
example = Mote.parse("{{ user }}", context, [:user])
7878
assert_equal "Bruno", example.call(user: "Bruno")
7979
end
80+
81+
test "curly bug" do
82+
example = Mote.parse("{{ [1, 2, 3].map { |i| i * i }.join(',') }}")
83+
assert_equal "1,4,9", example.call
84+
end
8085
end
8186

8287
include Mote::Helpers
@@ -85,4 +90,4 @@
8590
test "helpers" do
8691
assert_equal "\n *\n\n *\n\n *\n\n", mote("test/basic.erb", :n => 3)
8792
end
88-
end
93+
end

0 commit comments

Comments
 (0)