mote 1.1.2 → 1.1.3

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/README.md +47 -2
  3. data/lib/mote.rb +5 -5
  4. data/test/mote_test.rb +5 -0
  5. metadata +3 -4
  6. data/Rakefile +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26b0b54d5537850b18d7faa452776b6d079ac0da
4
- data.tar.gz: 8da3ff5b57972c1b4189561b660bb01e49457784
3
+ metadata.gz: 97237b0155b66dfbd3b2d984f21d3785895f8bab
4
+ data.tar.gz: 51b922147551b06f5b3135e5f51e144c789f111f
5
5
  SHA512:
6
- metadata.gz: b1110be61eedc588a5e1f3682c1dd6cf75c86655508d9adba51137e1936e86b69422a8a3f493546fdc19fb38ce22584dcd3be8b2d633e62dab6c6151681ad773
7
- data.tar.gz: 03be6b8178add22491fefeb362b40c737f05d3248187eddd60e864180e40d92084f40cd3ce90330152c25feedadab8b6f8c435a6ea3a5d5c0c547871f9d683a1
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
- ## mote
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
- As usual, you can install it using rubygems.
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.2"
21
+ VERSION = "1.1.3"
22
22
 
23
- PATTERN = /^(\n+)|^\s*(%)\s*(.*?)\n|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
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(filename, params = {}, context = self)
54
- mote_cache[filename] ||= Mote.parse(File.read(filename), context, params.keys)
55
- mote_cache[filename][params]
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.2
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: 2013-04-15 00:00:00.000000000 Z
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.3
61
+ rubygems_version: 2.0.14
63
62
  signing_key:
64
63
  specification_version: 4
65
64
  summary: Minimum Operational Template.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- task :test do
2
- require "cutest"
3
- Cutest.run(Dir["test/*.rb"])
4
- end
5
-
6
- task :default => :test