mote 0.2.4 → 1.0.0.rc1
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.
- data/README.md +2 -0
- data/bin/mote +2 -0
- data/lib/mote.rb +5 -5
- data/test/mote_test.rb +4 -6
- metadata +7 -7
data/README.md
CHANGED
@@ -66,6 +66,8 @@ assert_equal "Hello world", example.call(name: "world")
|
|
66
66
|
assert_equal "Hello Bruno", example.call(name: "Bruno")
|
67
67
|
```
|
68
68
|
|
69
|
+
Please note that the keys in the parameters hash must be symbols.
|
70
|
+
|
69
71
|
# Helpers
|
70
72
|
|
71
73
|
There's a helper available in the `Mote::Helpers` module, and you are
|
data/lib/mote.rb
CHANGED
@@ -18,11 +18,11 @@
|
|
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.
|
21
|
+
VERSION = "1.0.0.rc1"
|
22
22
|
|
23
23
|
PATTERN = /^\s*(%)(.*?)$|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
|
24
24
|
|
25
|
-
def self.parse(template,
|
25
|
+
def self.parse(template, vars = [])
|
26
26
|
terms = template.split(PATTERN)
|
27
27
|
|
28
28
|
parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
|
@@ -42,16 +42,16 @@ class Mote
|
|
42
42
|
|
43
43
|
parts << "__o; end"
|
44
44
|
|
45
|
-
compile(
|
45
|
+
compile(TOPLEVEL_BINDING, parts)
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.compile(context, parts)
|
49
|
-
context.
|
49
|
+
context.eval(parts)
|
50
50
|
end
|
51
51
|
|
52
52
|
module Helpers
|
53
53
|
def mote(filename, params = {})
|
54
|
-
mote_cache[filename] ||= Mote.parse(File.read(filename),
|
54
|
+
mote_cache[filename] ||= Mote.parse(File.read(filename), params.keys)
|
55
55
|
mote_cache[filename][params]
|
56
56
|
end
|
57
57
|
|
data/test/mote_test.rb
CHANGED
@@ -65,16 +65,14 @@ scope do
|
|
65
65
|
|
66
66
|
test "context" do
|
67
67
|
context = Object.new
|
68
|
-
context.
|
68
|
+
def context.user; "Bruno"; end
|
69
69
|
|
70
|
-
example = Mote.parse("{{
|
71
|
-
assert_equal "Bruno", example.call
|
70
|
+
example = Mote.parse("{{ context.user }}", [:context])
|
71
|
+
assert_equal "Bruno", example.call(context: context)
|
72
72
|
end
|
73
73
|
|
74
74
|
test "locals" do
|
75
|
-
|
76
|
-
|
77
|
-
example = Mote.parse("{{ user }}", context, [:user])
|
75
|
+
example = Mote.parse("{{ user }}", [:user])
|
78
76
|
assert_equal "Bruno", example.call(user: "Bruno")
|
79
77
|
end
|
80
78
|
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michel Martens
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cutest
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152390280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152390280
|
25
25
|
description: Mote is a very simple and fast template engine.
|
26
26
|
email:
|
27
27
|
- michel@soveran.com
|
@@ -54,9 +54,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
|
-
- - ! '
|
57
|
+
- - ! '>'
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 1.3.1
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
62
|
rubygems_version: 1.8.11
|