mote 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -2
- data/lib/mote.rb +5 -5
- data/test/mote_test.rb +5 -0
- metadata +3 -4
- data/Rakefile +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97237b0155b66dfbd3b2d984f21d3785895f8bab
|
4
|
+
data.tar.gz: 51b922147551b06f5b3135e5f51e144c789f111f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a034be6380e394e4732d001a2edeb32a70eb445048eac0509ce8505ab847adb4b6518256ea90cf31253f85cf8884ba6f50131d2ddc149b7a67e12902cce9901
|
7
|
+
data.tar.gz: 0b2ca78c4758fdac89db5fbe499e3627388c5d71b4cf6ea5d3ee5950f0742a053c493c52e280c3c2bc8c4c60a03e256f016cd731842e6370352e05c816214626
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ free to include it in your code. To do it, just type:
|
|
77
77
|
include Mote::Helpers
|
78
78
|
```
|
79
79
|
|
80
|
-
|
80
|
+
### Using the mote helper
|
81
81
|
|
82
82
|
The `mote` helper receives a file name and a hash and returns the rendered
|
83
83
|
version of its content. The compiled template is cached for subsequent calls.
|
@@ -86,9 +86,54 @@ version of its content. The compiled template is cached for subsequent calls.
|
|
86
86
|
assert_equal "***\n", mote("test/basic.mote", n: 3)
|
87
87
|
```
|
88
88
|
|
89
|
+
### Template caching
|
90
|
+
|
91
|
+
When the `mote` helper is first called with a template name, the
|
92
|
+
file is read and parsed, and a proc is created and stored in the
|
93
|
+
current thread. The parameters passed are defined as local
|
94
|
+
variables in the template. If you want to provide more parameters
|
95
|
+
once the template was cached, you won't be able to access the
|
96
|
+
values as local variables, but you can always access the `params`
|
97
|
+
hash.
|
98
|
+
|
99
|
+
For example:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
# First call
|
103
|
+
mote("foo.mote", a: 1, b: 2)
|
104
|
+
```
|
105
|
+
|
106
|
+
## Command line tool
|
107
|
+
|
108
|
+
Mote ships with a command line tool to render mote templates. The
|
109
|
+
result is redirected to standard output.
|
110
|
+
|
111
|
+
```
|
112
|
+
mote FILE [param1 value1 ... paramN valueN]
|
113
|
+
```
|
114
|
+
|
115
|
+
The extra parameters supplied will be passed to the template.
|
116
|
+
Note that all the parameter values will be treated as strings.
|
117
|
+
|
118
|
+
### Example usage
|
119
|
+
|
120
|
+
If your template is called foo.mote, you can render it with the
|
121
|
+
following command:
|
122
|
+
|
123
|
+
mote foo.mote
|
124
|
+
|
125
|
+
To write the result to a new file, just redirect the output:
|
126
|
+
|
127
|
+
mote foo.mote > foo.html
|
128
|
+
|
129
|
+
If the template uses a local variable `bar`, you can pass a
|
130
|
+
value from the command line:
|
131
|
+
|
132
|
+
mote foo.mote bar 42
|
133
|
+
|
89
134
|
## Installation
|
90
135
|
|
91
|
-
|
136
|
+
You can install it using rubygems.
|
92
137
|
|
93
138
|
```
|
94
139
|
$ gem install mote
|
data/lib/mote.rb
CHANGED
@@ -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.
|
21
|
+
VERSION = "1.1.3"
|
22
22
|
|
23
|
-
PATTERN = /^(\n
|
23
|
+
PATTERN = /^(\n)|^\s*(%)\s*(.*?)(?:\n|\Z)|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
|
24
24
|
|
25
25
|
def self.parse(template, context = self, vars = [])
|
26
26
|
terms = template.split(PATTERN)
|
@@ -50,9 +50,9 @@ class Mote
|
|
50
50
|
end
|
51
51
|
|
52
52
|
module Helpers
|
53
|
-
def mote(
|
54
|
-
mote_cache[
|
55
|
-
mote_cache[
|
53
|
+
def mote(file, params = {}, context = self)
|
54
|
+
mote_cache[file] ||= Mote.parse(File.read(file), context, params.keys)
|
55
|
+
mote_cache[file][params]
|
56
56
|
end
|
57
57
|
|
58
58
|
def mote_cache
|
data/test/mote_test.rb
CHANGED
@@ -16,6 +16,11 @@ scope do
|
|
16
16
|
assert_equal "\n\n\n", example.call
|
17
17
|
end
|
18
18
|
|
19
|
+
test "control flow without final newline" do
|
20
|
+
example = Mote.parse("\n% if true\n\n\n% else\n\n% end")
|
21
|
+
assert_equal "\n\n\n", example.call
|
22
|
+
end
|
23
|
+
|
19
24
|
test "assignment" do
|
20
25
|
example = Mote.parse("{{ \"***\" }}")
|
21
26
|
assert_equal "***", example.call
|
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.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- LICENSE
|
36
36
|
- AUTHORS
|
37
37
|
- README.md
|
38
|
-
- Rakefile
|
39
38
|
- lib/mote.rb
|
40
39
|
- mote.gemspec
|
41
40
|
- test/mote_test.rb
|
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
58
|
version: '0'
|
60
59
|
requirements: []
|
61
60
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.0.
|
61
|
+
rubygems_version: 2.0.14
|
63
62
|
signing_key:
|
64
63
|
specification_version: 4
|
65
64
|
summary: Minimum Operational Template.
|