mote 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mote.rb +20 -16
  3. data/test/mote_test.rb +10 -0
  4. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bf64ea0a8637abd44b6e4ffe5c8307849171e7d
4
- data.tar.gz: df273253e96dca30b70aa34b0f5b02fe6be78a2b
3
+ metadata.gz: 530e8a86da4e1fcb06a1bebd2e953a4a6b5be56c
4
+ data.tar.gz: 18eed6501b852ae5bb4540980a5bfa6e8cc527f4
5
5
  SHA512:
6
- metadata.gz: 28f751114df86a5345052b7fec958e3c08fcdeedd9bfb71a7278e2bc0eba77ca3c8aa3a2ca97ce946b80ce09442bed017c9f642cd9e42d22c9ba4d6e7d6a7ec5
7
- data.tar.gz: d2d889b1f9d050089adb4c126e63ccaa1497ad9cf62b5e33dbdce893c091b7fc9ed4159f0a93ebfa0b3f42585039fc93caa93656bc6899a552fbe4f011b36135
6
+ metadata.gz: 9d9ebffd32633732750fe63bb190f7e2c81bf7438c8a7bf8bb975b21012b130bf40a20f027ae69c980aced146296b065912948deb563ccf2d14ea991f0fbc407
7
+ data.tar.gz: 63cae29cdfeae148549e82a531fef12bbc72b07c58562058046b5201e5a74af6c7b310001d19f1d525bd6c54428614792f998acc844cc1538867484ef51999a0
@@ -18,40 +18,44 @@
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.4"
21
+ VERSION = "1.2.0"
22
22
 
23
- PATTERN = /^[^\S\n]*(%)[^\S\n]*(.*?)(?:\n|\Z)|(<\?)\s+(.*?)\s+\?>|(\{\{)(.*?)\}\}/m
23
+ # The regex have three alternative blocks that capture the embedded Ruby code,
24
+ # the rest is left as is.
25
+ PATTERN = /
26
+ ^[^\S\n]*(%)[^\S\n]*(.*?)(?:\n|\Z) | # Ruby evaluated lines
27
+ (<\?)\s+(.*?)\s+\?> | # Multiline Ruby blocks
28
+ (\{\{)(.*?)\}\} # Ruby evaluated to strings
29
+ /mx
24
30
 
25
- def self.parse(template, context = self, vars = [])
31
+ def self.parse(template, context = self, vars = [], name = "template")
26
32
  terms = template.split(PATTERN)
27
33
 
28
- parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
34
+ code = "Proc.new do |params, __o| params ||= {}; __o ||= '';"
29
35
 
30
36
  vars.each do |var|
31
- parts << "%s = params[%p]\n" % [var, var]
37
+ code << "%s = params[%p];" % [var, var]
32
38
  end
33
39
 
34
40
  while (term = terms.shift)
35
41
  case term
36
- when "<?" then parts << "#{terms.shift}\n"
37
- when "%" then parts << "#{terms.shift}\n"
38
- when "{{" then parts << "__o << (#{terms.shift}).to_s\n"
39
- else parts << "__o << #{term.dump}\n"
42
+ when "<?" then code << "#{terms.shift}\n"
43
+ when "%" then code << "#{terms.shift}\n"
44
+ when "{{" then code << "__o << (#{terms.shift}).to_s\n"
45
+ else code << "__o << #{term.dump}\n"
40
46
  end
41
47
  end
42
48
 
43
- parts << "__o; end"
49
+ code << "__o; end"
44
50
 
45
- compile(context, parts)
46
- end
47
-
48
- def self.compile(context, parts)
49
- context.instance_eval(parts)
51
+ context.instance_eval(code, name, -1)
50
52
  end
51
53
 
52
54
  module Helpers
53
55
  def mote(file, params = {}, context = self)
54
- mote_cache[file] ||= Mote.parse(File.read(file), context, params.keys)
56
+ template = File.read(file)
57
+
58
+ mote_cache[file] ||= Mote.parse(template, context, params.keys, file)
55
59
  mote_cache[file][params]
56
60
  end
57
61
 
@@ -139,6 +139,16 @@ scope do
139
139
  mote_cache.clear
140
140
  end
141
141
 
142
+ test "syntax errors" do
143
+ begin
144
+ mote("test/error.mote")
145
+ rescue SyntaxError => error
146
+ end
147
+
148
+ assert_equal SyntaxError, error.class
149
+ assert error.message["test/error.mote:4: syntax error"]
150
+ end
151
+
142
152
  test "helpers" do
143
153
  assert_equal " *\n *\n *\n", mote("test/basic.mote", :n => 3)
144
154
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-15 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Mote is a very simple and fast template engine.
@@ -32,13 +32,13 @@ executables:
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - LICENSE
36
35
  - AUTHORS
36
+ - LICENSE
37
37
  - README.md
38
+ - bin/mote
38
39
  - lib/mote.rb
39
40
  - mote.gemspec
40
41
  - test/mote_test.rb
41
- - bin/mote
42
42
  homepage: http://github.com/soveran/mote
43
43
  licenses: []
44
44
  metadata: {}
@@ -48,17 +48,17 @@ require_paths:
48
48
  - lib
49
49
  required_ruby_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.0.14
61
+ rubygems_version: 2.4.5.1
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Minimum Operational Template.