nm 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- data.tar.gz: cbd3cdb0ce766948af48d6a1c502f0efd972666d
4
- metadata.gz: adabe344f116f0b43fc0c525e2f074b6dda71de8
5
2
  SHA512:
6
- data.tar.gz: 69bf2f992a72ffa1fb4d0920f932e25bfbaab7352bf5cd76aaa46dd39d96d1d9aa12cbee217155b32eb2184f4bb94dfa1d047447700423936a8d7b236508ee9a
7
- metadata.gz: 58e61ae563a80584e393272ef1bbb4d2f7bfe5778bd784c40073378679bd9b678edc34633cb9a9b475a7a1122fc17794dd15f1e5a3b61a5dca1e6193b9830bd5
3
+ metadata.gz: 31eb095487432e3c6b60cbb023624cce4b902371692cea5312d52d0bcd6a57d98ad2ca4171110f66e2bd4028fdf449c6eee00442d769fc260abd7ab76f8f15cb
4
+ data.tar.gz: 43ec476c3b63ec379f30edc5b75989f56843eab905e90a0a2b4422022102f2cbd5931cc3b09bbe7f3aeeacf26280a130dc6a8875af9cfd83b4ed903dcfeda5c8
5
+ SHA1:
6
+ metadata.gz: 79b11e40bec9d04eed9c4590c06ee9acc2a74ba9
7
+ data.tar.gz: 2a6984f912b917b14c9ab9ba5a524c310f8f7648
data/README.md CHANGED
@@ -94,6 +94,29 @@ There are two main markup methods:
94
94
  * `node`: create a named attribute on a hash object
95
95
  * `map`: create a list object mapped from a given list
96
96
 
97
+ ### Default render value
98
+
99
+ Nm templates render an empty object (ie `::Hash.new`) if no source is given or no markup methods are called in the template source. The idea is that the templates should always return *something* and avoid `nil` values as much as possible.
100
+
101
+ This is also more consistent with rendering mapped lists vs reduced objects. Say your are mapping a list of objects in your template (using the `map` markup method):
102
+
103
+ ```ruby
104
+ map incoming_list do |item|
105
+ node 'name', item.name
106
+ node 'value', item.value
107
+ end
108
+ ```
109
+
110
+ If there are no items in the incoming list, the template render produces an empty list. Now say you are reducing an incoming list to a single object:
111
+
112
+ ```ruby
113
+ incoming_list.each do |item|
114
+ node item.name, item.value
115
+ end
116
+ ```
117
+
118
+ If there are no items in the incoming list, no markup methods are called, but the template render still produces an empty object b/c that is the default value.
119
+
97
120
  ### Partials
98
121
 
99
122
  **Note**: using partials negatively impacts template rendering performance.
@@ -6,7 +6,7 @@ module Nm
6
6
  class Template
7
7
 
8
8
  def initialize(*args)
9
- @__dstack__ = [ nil ]
9
+ @__dstack__ = [nil]
10
10
 
11
11
  # apply any given locals to template scope as methods
12
12
  metaclass = class << self; self; end
@@ -34,7 +34,7 @@ module Nm
34
34
  end
35
35
 
36
36
  def __data__
37
- @__dstack__.last
37
+ @__dstack__.last || ::Hash.new
38
38
  end
39
39
 
40
40
  def __node__(key, value = nil, &block)
@@ -1,3 +1,3 @@
1
1
  module Nm
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -25,8 +25,8 @@ class Nm::Template
25
25
  should have_imeths :render, :_render, :r
26
26
  should have_imeths :partial, :_partial, :p
27
27
 
28
- should "have no data if no source file is given" do
29
- assert_nil subject.__data__
28
+ should "have empty data if no markup meths called or no source given" do
29
+ assert_equal ::Hash.new, subject.__data__
30
30
  end
31
31
 
32
32
  should "return itself when its markup methods are called" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-06-10 00:00:00 Z
13
+ date: 2016-09-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  requirements: []
81
81
 
82
82
  rubyforge_project:
83
- rubygems_version: 2.6.4
83
+ rubygems_version: 2.6.6
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Data templating system.