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.



318
319
320
321
322
323
324
325
326
# File 'lib/flutterby/node.rb', line 318

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.



310
311
312
# File 'lib/flutterby/node.rb', line 310

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.



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

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.



296
297
298
299
300
# File 'lib/flutterby/node.rb', line 296

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

#stage!Object



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/flutterby/node.rb', line 268

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