Module: Flutterby::Node::Staging

Included in:
Flutterby::Node
Defined in:
lib/flutterby/node.rb

Instance Method Summary collapse

Instance Method Details

#extend_all(nodes, *mods, &blk) ⇒ Object

Extend all of the specified ‘nodes` with the specified module(s). If a block is given, the nodes will be extended with the code found in the block.



313
314
315
316
317
318
319
320
321
# File 'lib/flutterby/node.rb', line 313

def extend_all(nodes, *mods, &blk)
  if block_given?
    mods << NodeExtension.new(&blk)
  end

  nodes.each do |n|
    n.extend(*mods)
  end
end

#extend_parent(*mods, &blk) ⇒ Object

Extend this node’s parent. See #extend_all.



305
306
307
# File 'lib/flutterby/node.rb', line 305

def extend_parent(*mods, &blk)
  extend_all([parent], *mods, &blk)
end

#extend_siblings(*mods, &blk) ⇒ Object

Extend all of this node’s siblings. See #extend_all.



299
300
301
# File 'lib/flutterby/node.rb', line 299

def extend_siblings(*mods, &blk)
  extend_all(siblings, *mods, &blk)
end

#perform_setup!Object

Perform setup for this node. The setup step is run after the tree has been built up completely. It allows you to perform one-time setup operations that, for example, modify the tree (like sorting blog posts into date-specific subnodes.)

Your nodes (or their extensions) may overload this method, but you may also simply use the ‘setup { … }` syntax in a node extension to define a block of code to be run at setup time.



291
292
293
294
295
# File 'lib/flutterby/node.rb', line 291

def perform_setup!
  _setup_procs.each do |p|
    instance_exec(&p)
  end
end

#stage!Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/flutterby/node.rb', line 263

def stage!
  # First of all, we want to make sure all initializers
  # (`_init.rb` files) are executed, starting at the top of the tree.
  #
  TreeWalker.walk_tree(self) do |node|
    if node.full_name == "_init.rb"
      logger.debug "Executing initializer #{node.url}"
      node.instance_eval(node.render)
    end
  end

  # In a second pass, walk the tree to invoke any available
  # setup methods.
  #
  TreeWalker.walk_tree(self) do |node|
    node.perform_setup!
  end
end