mote 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +6 -6
  2. data/lib/mote.rb +3 -3
  3. data/test/mote_test.rb +10 -5
  4. metadata +4 -4
@@ -22,9 +22,9 @@ the different use cases you may face:
22
22
 
23
23
 
24
24
  % if user == "Bruno"
25
- ${user} rhymes with Piano
25
+ {{user}} rhymes with Piano
26
26
  % elsif user == "Brutus"
27
- ${user} rhymes with Opus
27
+ {{user}} rhymes with Opus
28
28
  % end
29
29
 
30
30
  ## Control flow
@@ -33,7 +33,7 @@ Lines that start with `%` are evaluated as Ruby code.
33
33
 
34
34
  ## Assignment
35
35
 
36
- Whatever it is between `${` and `}` gets printed in the template.
36
+ Whatever it is between `{{` and `}}` gets printed in the template.
37
37
 
38
38
  ## Comments
39
39
 
@@ -47,14 +47,14 @@ There's nothing special about comments, it's just a `#` inside your Ruby code:
47
47
  As with control instructions, it happens naturally:
48
48
 
49
49
  % 3.times do |i|
50
- ${i}
50
+ {{i}}
51
51
  % end
52
52
 
53
53
  ## Parameters
54
54
 
55
55
  The values passed to the template are available as local variables:
56
56
 
57
- example = Mote.parse("Hello ${name}")
57
+ example = Mote.parse("Hello {{name}}")
58
58
  assert_equal "Hello world", example.call(name: "world")
59
59
  assert_equal "Hello Bruno", example.call(name: "Bruno")
60
60
 
@@ -75,4 +75,4 @@ version of its content. The compiled template is cached for subsequent calls.
75
75
  Installation
76
76
  ------------
77
77
 
78
- $ gem install mote
78
+ $ gem install mote
@@ -18,10 +18,10 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
  class Mote
21
- VERSION = "0.1.0"
21
+ VERSION = "0.2.0"
22
22
 
23
23
  def self.parse(template, context = self, vars = [])
24
- terms = template.split(/^\s*(%)(.*?)$|(\$\{)(.*?)\}/)
24
+ terms = template.split(/^\s*(%)(.*?)$|(\{\{)(.*?)\}\}/)
25
25
 
26
26
  parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
27
27
 
@@ -32,7 +32,7 @@ class Mote
32
32
  while term = terms.shift
33
33
  case term
34
34
  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"
36
36
  else parts << "__o << #{term.inspect}\n"
37
37
  end
38
38
  end
@@ -2,7 +2,7 @@ require File.expand_path("../lib/mote", File.dirname(__FILE__))
2
2
 
3
3
  scope do
4
4
  test "assignment" do
5
- example = Mote.parse("${ \"***\" }")
5
+ example = Mote.parse("{{ \"***\" }}")
6
6
  assert_equal "***", example.call
7
7
  end
8
8
 
@@ -54,7 +54,7 @@ scope do
54
54
  end
55
55
 
56
56
  test "multiline" do
57
- example = Mote.parse("The\nMan\nAnd\n${\"The\"}\nSea")
57
+ example = Mote.parse("The\nMan\nAnd\n{{\"The\"}}\nSea")
58
58
  assert_equal "The\nMan\nAnd\nThe\nSea", example[:n => 3]
59
59
  end
60
60
 
@@ -67,16 +67,21 @@ scope do
67
67
  context = Object.new
68
68
  context.instance_variable_set(:@user, "Bruno")
69
69
 
70
- example = Mote.parse("${ @user }", context)
70
+ example = Mote.parse("{{ @user }}", context)
71
71
  assert_equal "Bruno", example.call
72
72
  end
73
73
 
74
74
  test "locals" do
75
75
  context = Object.new
76
76
 
77
- example = Mote.parse("${ user }", context, [:user])
77
+ example = Mote.parse("{{ user }}", context, [:user])
78
78
  assert_equal "Bruno", example.call(user: "Bruno")
79
79
  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
80
85
  end
81
86
 
82
87
  include Mote::Helpers
@@ -85,4 +90,4 @@ scope do
85
90
  test "helpers" do
86
91
  assert_equal "\n *\n\n *\n\n *\n\n", mote("test/basic.erb", :n => 3)
87
92
  end
88
- end
93
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-23 00:00:00.000000000 -07:00
12
+ date: 2011-08-24 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: cutest
17
- requirement: &2152242200 !ruby/object:Gem::Requirement
17
+ requirement: &2153612340 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2152242200
25
+ version_requirements: *2153612340
26
26
  description: Mote is the little brother of ERB. It only provides a subset of ERB's
27
27
  features, but praises itself of being simple--both internally and externally--and
28
28
  super fast.