mote 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +11 -2
  4. data/lib/mote.rb +5 -5
  5. data/test/mote_test.rb +11 -15
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97237b0155b66dfbd3b2d984f21d3785895f8bab
4
- data.tar.gz: 51b922147551b06f5b3135e5f51e144c789f111f
3
+ metadata.gz: 0bf64ea0a8637abd44b6e4ffe5c8307849171e7d
4
+ data.tar.gz: df273253e96dca30b70aa34b0f5b02fe6be78a2b
5
5
  SHA512:
6
- metadata.gz: 6a034be6380e394e4732d001a2edeb32a70eb445048eac0509ce8505ab847adb4b6518256ea90cf31253f85cf8884ba6f50131d2ddc149b7a67e12902cce9901
7
- data.tar.gz: 0b2ca78c4758fdac89db5fbe499e3627388c5d71b4cf6ea5d3ee5950f0742a053c493c52e280c3c2bc8c4c60a03e256f016cd731842e6370352e05c816214626
6
+ metadata.gz: 28f751114df86a5345052b7fec958e3c08fcdeedd9bfb71a7278e2bc0eba77ca3c8aa3a2ca97ce946b80ce09442bed017c9f642cd9e42d22c9ba4d6e7d6a7ec5
7
+ data.tar.gz: d2d889b1f9d050089adb4c126e63ccaa1497ad9cf62b5e33dbdce893c091b7fc9ed4159f0a93ebfa0b3f42585039fc93caa93656bc6899a552fbe4f011b36135
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011, 2012 Michel Martens
1
+ Copyright (c) 2011-2015 Michel Martens
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -22,16 +22,26 @@ Silly example, you may say, and I would agree. What follows is a short list of
22
22
  the different use cases you may face:
23
23
 
24
24
  ```
25
+ % # This is a comment
25
26
  % if user == "Bruno"
26
27
  {{user}} rhymes with Piano
27
28
  % elsif user == "Brutus"
28
29
  {{user}} rhymes with Opus
29
30
  % end
31
+
32
+ <?
33
+ # Multiline code evaluation
34
+ lucky = [1, 3, 7, 9, 13, 15]
35
+ prime = [2, 3, 5, 7, 11, 13]
36
+ ?>
37
+
38
+ {{ lucky & prime }}
30
39
  ```
31
40
 
32
41
  ## Control flow
33
42
 
34
- Lines that start with `%` are evaluated as Ruby code.
43
+ Lines that start with `%` are evaluated as Ruby code. Anything between
44
+ `<?` and `?>`, including new lines, is also evaluated as Ruby code.
35
45
 
36
46
  ## Assignment
37
47
 
@@ -45,7 +55,6 @@ There's nothing special about comments, it's just a `#` inside your Ruby code:
45
55
  % # This is a comment.
46
56
  ```
47
57
 
48
-
49
58
  ## Block evaluation
50
59
 
51
60
  As with control instructions, it happens naturally:
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2011, 2012 Michel Martens
1
+ # Copyright (c) 2011-2015 Michel Martens
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -18,9 +18,9 @@
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 = "1.1.3"
21
+ VERSION = "1.1.4"
22
22
 
23
- PATTERN = /^(\n)|^\s*(%)\s*(.*?)(?:\n|\Z)|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
23
+ PATTERN = /^[^\S\n]*(%)[^\S\n]*(.*?)(?:\n|\Z)|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
24
24
 
25
25
  def self.parse(template, context = self, vars = [])
26
26
  terms = template.split(PATTERN)
@@ -28,10 +28,10 @@ class Mote
28
28
  parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
29
29
 
30
30
  vars.each do |var|
31
- parts << "%s = params[%s]\n" % [var, var.inspect]
31
+ parts << "%s = params[%p]\n" % [var, var]
32
32
  end
33
33
 
34
- while term = terms.shift
34
+ while (term = terms.shift)
35
35
  case term
36
36
  when "<?" then parts << "#{terms.shift}\n"
37
37
  when "%" then parts << "#{terms.shift}\n"
@@ -22,7 +22,7 @@ scope do
22
22
  end
23
23
 
24
24
  test "assignment" do
25
- example = Mote.parse("{{ \"***\" }}")
25
+ example = Mote.parse("{{ '***' }}")
26
26
  assert_equal "***", example.call
27
27
  end
28
28
 
@@ -75,7 +75,7 @@ scope do
75
75
 
76
76
  test "multiline" do
77
77
  example = Mote.parse("The\nMan\nAnd\n{{\"The\"}}\nSea")
78
- assert_equal "The\nMan\nAnd\nThe\nSea", example[:n => 3]
78
+ assert_equal "The\nMan\nAnd\nThe\nSea", example.call
79
79
  end
80
80
 
81
81
  test "quotes" do
@@ -87,8 +87,8 @@ scope do
87
87
  context = Object.new
88
88
  def context.user; "Bruno"; end
89
89
 
90
- example = Mote.parse("{{ context.user }}", context, [:context])
91
- assert_equal "Bruno", example.call(context: context)
90
+ example = Mote.parse("{{ user }}", context)
91
+ assert_equal "Bruno", example.call
92
92
  end
93
93
 
94
94
  test "locals" do
@@ -101,23 +101,19 @@ scope do
101
101
  assert_equal "", example.call(user: nil)
102
102
  end
103
103
 
104
- test "curly bug" do
105
- example = Mote.parse("{{ [1, 2, 3].map { |i| i * i }.join(',') }}")
106
- assert_equal "1,4,9", example.call
107
- end
108
-
109
104
  test "multi-line XML-style directives" do
110
105
  template = (<<-EOT).gsub(/^ /, "")
111
- <? res = ""
112
- [1, 2, 3].each_with_index do |item, idx|
113
- res << "%d. %d\n" % [idx + 1, item * item]
114
- end
106
+ <?
107
+ # Multiline code evaluation
108
+ lucky = [1, 3, 7, 9, 13, 15]
109
+ prime = [2, 3, 5, 7, 11, 13]
115
110
  ?>
116
- {{ res }}
111
+
112
+ {{ lucky & prime }}
117
113
  EOT
118
114
 
119
115
  example = Mote.parse(template)
120
- assert_equal "\n1. 1\n2. 4\n3. 9\n\n", example.call
116
+ assert_equal "\n\n[3, 7, 13]\n", example.call
121
117
  end
122
118
 
123
119
  test "preserve XML directives" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest