tempeh 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17deec681294c1e4063e5d17506291cc84f0a565
4
- data.tar.gz: 8a20e0ec8b46118a008db617b56e242fca4e3091
3
+ metadata.gz: 8c303f5b3f50f5fa4fd133911a2339c3f3abd300
4
+ data.tar.gz: 9dcc173c50c4ae67ba6d0a838ca62f4a917511f6
5
5
  SHA512:
6
- metadata.gz: 53d84b831ce14d0155e56b84f2608af0cd3ed843a9cdb304de5bd3b4d875ec4400dff52cd32d8e80a19dae9d5291f3f1d762a4ed588de361f5c9a0a966b0cc83
7
- data.tar.gz: 0e646e35b1542b1b36fdae9861b224be95eed88056767155ff72038791ccdd617a0bb6bd168582485f0ef7624e8caecece01f074499d7705222b9c38e7f2fd87
6
+ metadata.gz: c01c92e496791dfdf055409061a1b5007004faa20aecf6aa1ec70eab49f764dee0c364622bf85dff4b903c7f075c3312c7230d631350850bb53d37039cb00c81
7
+ data.tar.gz: 6b2e65109cc5b562af9bfb772874dc74b3c1db3defe44514b4395713bb5089e78d84d96dd30f34c39f0b5cebfafb2606c1e1ebdf0bdc214b26876ae9b90760f4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tempeh (0.1.0)
4
+ tempeh (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -18,4 +18,4 @@ DEPENDENCIES
18
18
  tempeh!
19
19
 
20
20
  BUNDLED WITH
21
- 1.14.6
21
+ 1.15.1
@@ -4,7 +4,6 @@
4
4
  {{ 'hello world' }}
5
5
  % end %
6
6
 
7
- % # multiline blocks work as well %
8
7
  % [
9
8
  'foo',
10
9
  'bar',
@@ -1 +1,7 @@
1
- % 3.times do %{{ name }}% end %
1
+ %
2
+ # Compiled templates accept a single (optional) argument "args".
3
+ # This is useful for providing extra data that isn't bound
4
+ # to the evaluating context.
5
+ %
6
+
7
+ % 3.times do %{{ args[:name] || name }}% end %
@@ -1,5 +1,5 @@
1
1
  module Tempeh
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
 
4
4
  BLK_OPEN = "%"
5
5
 
@@ -36,7 +36,8 @@ module Tempeh
36
36
 
37
37
  def compile(str)
38
38
  terms = str.split(PATTERN)
39
- parts = "proc { __o = '';"
39
+
40
+ parts = "proc { |args| __o = '';"
40
41
 
41
42
  while (term = terms.shift)
42
43
  case term
@@ -57,9 +58,18 @@ module Tempeh
57
58
  end
58
59
  end
59
60
 
61
+ def test
62
+ b = binding
63
+ p = proc { b.eval("a = 22") }
64
+ p.call
65
+ puts a
66
+ end
67
+
60
68
  module Helpers
61
- def render(path)
62
- instance_eval &tempeh_template_for(path)
69
+ DEFAULT_ARGS = {}.freeze
70
+
71
+ def render(path, args = DEFAULT_ARGS)
72
+ instance_exec args, &tempeh_template_for(path)
63
73
  end
64
74
 
65
75
  def tempeh_template_for(path)
@@ -49,6 +49,12 @@ test 'contextual rendering' do
49
49
  assert_equal "bar", context.instance_eval(&template)
50
50
  end
51
51
 
52
+ test 'passes optional `args` variable' do
53
+ template = Tempeh.compile("{{ args[:foo] }}")
54
+
55
+ assert_equal "bar", instance_exec({ foo: "bar" }, &template)
56
+ end
57
+
52
58
  class View
53
59
  include Tempeh::Helpers
54
60
 
@@ -66,11 +72,13 @@ setup do
66
72
  end
67
73
 
68
74
  test 'helpers' do |view|
69
- path = './test/basic.tempeh'
75
+ path = './examples/basic.tempeh'
70
76
 
71
77
  assert Tempeh.cache[path].nil?, 'template is already cached'
72
78
 
73
- assert_equal 'stevestevesteve', view.render('./examples/basic.tempeh')
79
+ assert_equal "\n\nstevestevesteve", view.render(path)
74
80
 
75
81
  assert Tempeh.cache[path], 'template was not cached'
82
+
83
+ assert_equal "\n\nnotstevenotstevenotsteve", view.render(path, name: 'notsteve')
76
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempeh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Weiss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-04 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest