mote 1.0.0.rc1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mote.rb +6 -6
- data/test/mote_test.rb +22 -2
- metadata +7 -7
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 = "1.0.0
|
21
|
+
VERSION = "1.0.0"
|
22
22
|
|
23
23
|
PATTERN = /^\s*(%)(.*?)$|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
|
24
24
|
|
25
|
-
def self.parse(template, vars = [])
|
25
|
+
def self.parse(template, context = self, 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(context, parts)
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.compile(context, parts)
|
49
|
-
context.
|
49
|
+
context.instance_eval(parts)
|
50
50
|
end
|
51
51
|
|
52
52
|
module Helpers
|
53
|
-
def mote(filename, params = {})
|
54
|
-
mote_cache[filename] ||= Mote.parse(File.read(filename), params.keys)
|
53
|
+
def mote(filename, params = {}, context = self)
|
54
|
+
mote_cache[filename] ||= Mote.parse(File.read(filename), context, params.keys)
|
55
55
|
mote_cache[filename][params]
|
56
56
|
end
|
57
57
|
|
data/test/mote_test.rb
CHANGED
@@ -67,12 +67,12 @@ scope do
|
|
67
67
|
context = Object.new
|
68
68
|
def context.user; "Bruno"; end
|
69
69
|
|
70
|
-
example = Mote.parse("{{ context.user }}", [:context])
|
70
|
+
example = Mote.parse("{{ context.user }}", context, [:context])
|
71
71
|
assert_equal "Bruno", example.call(context: context)
|
72
72
|
end
|
73
73
|
|
74
74
|
test "locals" do
|
75
|
-
example = Mote.parse("{{ user }}", [:user])
|
75
|
+
example = Mote.parse("{{ user }}", TOPLEVEL_BINDING, [:user])
|
76
76
|
assert_equal "Bruno", example.call(user: "Bruno")
|
77
77
|
end
|
78
78
|
|
@@ -107,8 +107,28 @@ end
|
|
107
107
|
|
108
108
|
include Mote::Helpers
|
109
109
|
|
110
|
+
class Cutest::Scope
|
111
|
+
def foo
|
112
|
+
"foo"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
110
116
|
scope do
|
117
|
+
prepare do
|
118
|
+
mote_cache.clear
|
119
|
+
end
|
120
|
+
|
111
121
|
test "helpers" do
|
112
122
|
assert_equal "\n *\n\n *\n\n *\n\n", mote("test/basic.mote", :n => 3)
|
113
123
|
end
|
124
|
+
|
125
|
+
test "using functions in the context" do
|
126
|
+
assert_equal "foo\n", mote("test/foo.mote")
|
127
|
+
end
|
128
|
+
|
129
|
+
test "passing in a context" do
|
130
|
+
assert_raise NameError do
|
131
|
+
mote("test/foo.mote", {}, TOPLEVEL_BINDING)
|
132
|
+
end
|
133
|
+
end
|
114
134
|
end
|
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: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
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-07-
|
12
|
+
date: 2012-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cutest
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156124580 !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: *2156124580
|
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: '0'
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
62
|
rubygems_version: 1.8.11
|