flutterby 0.0.14 → 0.0.15

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
2
  SHA1:
3
- metadata.gz: 98bf6013901069664a2281251125dbc4f2b82bf1
4
- data.tar.gz: 677647c5e11088fbf5091fe7aa3e5a121a48c37a
3
+ metadata.gz: 999c3198c2142accdf16e2ceb75e3bed0d2c1465
4
+ data.tar.gz: d2b5a2573131d8275baf6b64ed0def712befc72f
5
5
  SHA512:
6
- metadata.gz: cd149d0e3efa73a1692fc9b940f09dbaef6379864721c396b6f7103d624973477da40fcdab67e600051b7d5c53b5cc9445a871b4f37136a60506c5c2929410a1
7
- data.tar.gz: 94648d86b9e989b8dc523a345aa4b655e54c13e1faf6fa58766a2174faffde2eeefb9458968e3496cc69207f462ea8328256fefaa38f1f4d9946b50594088dd4
6
+ metadata.gz: 9dbfa0722dab9e0bc5b50bc0f436cf7e5ae55c2c51732d44baaff615e667f61d86248d7f3075f3c0fd5e2bab3e483d3182386caadd90aaaba0dfccc1bfbd00f0
7
+ data.tar.gz: 1410e3505211430225a98f0093a9dc1045e841b8b50a0820c2142cf38a8784206de90f1e72d7361f365a0a3f21e1330d129872e40709ea43fd48803a1161fbc3
@@ -3,7 +3,7 @@ require 'benchmark'
3
3
  module Flutterby
4
4
  class Node
5
5
  attr_accessor :parent, :ext, :source, :body
6
- attr_reader :name, :filters, :fs_path, :data, :children, :paths
6
+ attr_reader :name, :filters, :fs_path, :children, :paths
7
7
 
8
8
  def initialize(name, parent: nil, fs_path: nil, source: nil)
9
9
  @fs_path = fs_path ? ::File.expand_path(fs_path) : nil
@@ -139,7 +139,7 @@ module Flutterby
139
139
 
140
140
  def reload!
141
141
  @body = nil
142
- @data = {}
142
+ @data = nil
143
143
  @children = []
144
144
  @paths = {}
145
145
 
@@ -159,7 +159,6 @@ module Flutterby
159
159
  #
160
160
  walk_tree do |node|
161
161
  node.render_body! if node.should_prerender?
162
- node.extract_data!
163
162
  node.register! if node.should_publish?
164
163
  end
165
164
  end
@@ -183,9 +182,11 @@ module Flutterby
183
182
  end
184
183
 
185
184
  def extract_data!
185
+ @data ||= {}
186
+
186
187
  # Extract date from name
187
188
  if name =~ %r{^(\d\d\d\d\-\d\d?\-\d\d?)\-}
188
- data['date'] = Time.parse($1)
189
+ @data['date'] = Time.parse($1)
189
190
  end
190
191
 
191
192
  # Read remaining data from frontmatter. Data in frontmatter
@@ -222,10 +223,19 @@ module Flutterby
222
223
  end
223
224
 
224
225
  def body
225
- render_body! if @body.nil?
226
+ if @body.nil?
227
+ data # make sure data is lazy-loaded
228
+ render_body!
229
+ end
230
+
226
231
  @body
227
232
  end
228
233
 
234
+ def data
235
+ extract_data! if @data.nil?
236
+ @data
237
+ end
238
+
229
239
  def render(layout: true)
230
240
  (layout && apply_layout?) ? apply_layout(body) : body
231
241
  end
@@ -253,25 +263,27 @@ module Flutterby
253
263
  #
254
264
 
255
265
  def parse_frontmatter!
266
+ @data || {}
267
+
256
268
  if @source
257
269
  # YAML Front Matter
258
270
  if @source.sub!(/\A\-\-\-\n(.+)\n\-\-\-\n/m, "")
259
- data.merge! YAML.load($1)
271
+ @data.merge! YAML.load($1)
260
272
  end
261
273
 
262
274
  # TOML Front Matter
263
275
  if @source.sub!(/\A\+\+\+\n(.+)\n\+\+\+\n/m, "")
264
- data.merge! TOML.parse($1)
276
+ @data.merge! TOML.parse($1)
265
277
  end
266
278
  end
267
279
  end
268
280
 
269
281
  def read_json!
270
- data.merge!(JSON.parse(body))
282
+ @data.merge!(JSON.parse(body))
271
283
  end
272
284
 
273
285
  def read_yaml!
274
- data.merge!(YAML.load(body))
286
+ @data.merge!(YAML.load(body))
275
287
  end
276
288
 
277
289
 
@@ -1,3 +1,3 @@
1
1
  module Flutterby
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flutterby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Mans