nm 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -89,7 +89,7 @@ node 'slideshow' do
89
89
  node 'start_slide', start_slide
90
90
  node 'slides' do
91
91
  map slides do |slide|
92
- partial 'slide.json', :slide => slide
92
+ partial '_slide.json', :slide => slide
93
93
  end
94
94
  end
95
95
  end
@@ -2,7 +2,7 @@ node 'slideshow' do
2
2
  node 'start_slide', view.start_slide
3
3
  node 'slides' do
4
4
  map view.slides do |slide|
5
- partial 'slide', :slide => slide
5
+ partial '_slide', :slide => slide
6
6
  end
7
7
  end
8
8
  end
data/lib/nm/source.rb CHANGED
@@ -21,9 +21,7 @@ module Nm
21
21
  Template.new(self, source_file_path(file_name), locals || {}).__data__
22
22
  end
23
23
 
24
- def partial(file_name, locals = nil)
25
- Template.new(self, partial_file_path(file_name), locals || {}).__data__
26
- end
24
+ alias_method :partial, :render
27
25
 
28
26
  private
29
27
 
@@ -31,11 +29,6 @@ module Nm
31
29
  self.root.join("#{file_name}#{EXT}").to_s
32
30
  end
33
31
 
34
- def partial_file_path(file_name)
35
- basename = File.basename(file_name.to_s)
36
- source_file_path(file_name.to_s.sub(/#{basename}\Z/, "_#{basename}"))
37
- end
38
-
39
32
  end
40
33
 
41
34
  class DefaultSource < Source
data/lib/nm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nm
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/script/bench_all.rb CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require 'script/bench_rabl'
4
4
  require 'script/bench_nm'
5
+ require 'script/bench_nm_partials'
5
6
  require 'script/bench_nm_re_source'
@@ -56,19 +56,8 @@ class Nm::Source
56
56
  assert_equal exp, subject.render(@file_name, @file_locals)
57
57
  end
58
58
 
59
- end
60
-
61
- class PartialTests < InitTests
62
- desc "`partial` method"
63
-
64
- setup do
65
- @file_name = "locals"
66
- @file_locals = { 'key' => 'a-value' }
67
- @file_path = Factory.template_file("_#{@file_name}#{Nm::Source::EXT}")
68
- end
69
-
70
- should "render a template for the given file name and return its data" do
71
- exp = Nm::Template.new(subject, @file_path, @file_locals).__data__
59
+ should "alias `render` as `partial`" do
60
+ exp = subject.render(@file_name, @file_locals)
72
61
  assert_equal exp, subject.partial(@file_name, @file_locals)
73
62
  end
74
63
 
@@ -216,31 +216,33 @@ class Nm::Template
216
216
  class PartialMethodTests < RenderTests
217
217
  desc "`partial` method"
218
218
  setup do
219
+ @partial_obj_file_name = "_obj"
219
220
  @partial_obj = {
220
221
  'a' => 'Aye',
221
222
  'b' => 'Bee',
222
223
  'c' => 'See'
223
224
  }
225
+ @partial_list_file_name = "_list"
224
226
  @partial_list = @list
225
227
  end
226
228
 
227
229
  should "render a template for the given partial name and add its data" do
228
230
  t = Nm::Template.new(@source)
229
- assert_equal @partial_obj, t.__partial__(@obj_file_name).__data__
231
+ assert_equal @partial_obj, t.__partial__(@partial_obj_file_name).__data__
230
232
  end
231
233
 
232
234
  should "be aliased as `render`, `_render` and `r`" do
233
235
  t = Nm::Template.new(@source)
234
- assert_equal @partial_obj, t.__partial__(@obj_file_name).__data__
236
+ assert_equal @partial_obj, t.__partial__(@partial_obj_file_name).__data__
235
237
 
236
238
  t = Nm::Template.new(@source)
237
- assert_equal @partial_obj, t.partial(@obj_file_name).__data__
239
+ assert_equal @partial_obj, t.partial(@partial_obj_file_name).__data__
238
240
 
239
241
  t = Nm::Template.new(@source)
240
- assert_equal @partial_obj, t._partial(@obj_file_name).__data__
242
+ assert_equal @partial_obj, t._partial(@partial_obj_file_name).__data__
241
243
 
242
244
  t = Nm::Template.new(@source)
243
- assert_equal @partial_obj, t.p(@obj_file_name).__data__
245
+ assert_equal @partial_obj, t.p(@partial_obj_file_name).__data__
244
246
  end
245
247
 
246
248
  should "merge if call returns an obj and called after a `__node__` call" do
@@ -248,14 +250,14 @@ class Nm::Template
248
250
  t.__node__('1', 'One')
249
251
 
250
252
  exp = {'1' => 'One'}.merge(@partial_obj)
251
- assert_equal exp, t.__partial__(@obj_file_name).__data__
253
+ assert_equal exp, t.__partial__(@partial_obj_file_name).__data__
252
254
  end
253
255
 
254
256
  should "complain if call returns an obj and called after a `__map__` call" do
255
257
  t = Nm::Template.new(@source)
256
258
  t.__map__([1,2,3])
257
259
  assert_raises Nm::InvalidError do
258
- t.__partial__(@obj_file_name).__data__
260
+ t.__partial__(@partial_obj_file_name).__data__
259
261
  end
260
262
  end
261
263
 
@@ -264,7 +266,7 @@ class Nm::Template
264
266
  t.__map__([1,2,3])
265
267
 
266
268
  exp = [1,2,3].concat(@partial_list)
267
- assert_equal exp, t.__partial__(@list_file_name).__data__
269
+ assert_equal exp, t.__partial__(@partial_list_file_name).__data__
268
270
  end
269
271
 
270
272
  should "complain if call returns a list and called after a `__node__` call" do
@@ -272,7 +274,7 @@ class Nm::Template
272
274
  t.__node__('1', 'One')
273
275
 
274
276
  assert_raises Nm::InvalidError do
275
- t.__partial__(@list_file_name).__data__
277
+ t.__partial__(@partial_list_file_name).__data__
276
278
  end
277
279
  end
278
280
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Kelly Redding
@@ -10,17 +16,22 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2014-06-04 00:00:00 Z
19
+ date: 2014-11-12 00:00:00 Z
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
17
24
  requirements:
18
25
  - - ~>
19
26
  - !ruby/object:Gem::Version
27
+ hash: 23
28
+ segments:
29
+ - 2
30
+ - 10
20
31
  version: "2.10"
21
32
  type: :development
22
- version_requirements: *id001
23
33
  name: assert
34
+ version_requirements: *id001
24
35
  prerelease: false
25
36
  description: Data templating system.
26
37
  email:
@@ -79,28 +90,35 @@ files:
79
90
  homepage: http://github.com/redding/nm
80
91
  licenses:
81
92
  - MIT
82
- metadata: {}
83
-
84
93
  post_install_message:
85
94
  rdoc_options: []
86
95
 
87
96
  require_paths:
88
97
  - lib
89
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
90
100
  requirements:
91
- - &id002
92
- - ">="
101
+ - - ">="
93
102
  - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
94
106
  version: "0"
95
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
96
109
  requirements:
97
- - *id002
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
98
116
  requirements: []
99
117
 
100
118
  rubyforge_project:
101
- rubygems_version: 2.2.2
119
+ rubygems_version: 1.8.25
102
120
  signing_key:
103
- specification_version: 4
121
+ specification_version: 3
104
122
  summary: Data templating system.
105
123
  test_files:
106
124
  - test/helper.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA512:
3
- metadata.gz: d389b30bc53c3293e4e428b9126c64838124a270d3f535ce360ca3cf984466537f2707a2c149b8ae3d1cbcb231f685a24af6b5ed41f12f0a2b22b7d207f2db09
4
- data.tar.gz: 9be9ce99e660a80fe20d6e034de82511081b9ad00cf30dbd0b879ff2ec0ebb671279f30611572ffc00e7be77bea456af5d09b1108147f63a9e2c4d7da4e4d461
5
- SHA1:
6
- metadata.gz: 6e4b7a81896c762b7c9dea9b642f4eb3c4137967
7
- data.tar.gz: 579835a684d21fde132b8ab12bd0423381629f44