Class: Flutterby::Node
- Inherits:
-
Object
- Object
- Flutterby::Node
- Defined in:
- lib/flutterby/node.rb
Defined Under Namespace
Modules: Paths, Reading, Rendering, Staging, Tree
Instance Attribute Summary collapse
-
#_setup_procs ⇒ Object
readonly
Returns the value of attribute _setup_procs.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#ext ⇒ Object
Returns the value of attribute ext.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#fs_path ⇒ Object
readonly
Returns the value of attribute fs_path.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #copy(new_name, data = {}) ⇒ Object
-
#create(name, **args) ⇒ Object
included
from Tree
Creates a new node, using the specified arguments, as a child of this node.
- #data ⇒ Object included from Reading
- #emit_child(name) ⇒ Object included from Tree
-
#extend_all(nodes, *mods, &blk) ⇒ Object
included
from Staging
Extend all of the specified ‘nodes` with the specified module(s).
-
#extend_parent(*mods, &blk) ⇒ Object
included
from Staging
Extend this node’s parent.
-
#extend_siblings(*mods, &blk) ⇒ Object
included
from Staging
Extend all of this node’s siblings.
- #file? ⇒ Boolean
- #find(path, opts = {}) ⇒ Object included from Tree
-
#find!(path, *args) ⇒ Object
included
from Tree
Like Tree#find, but raises an exception when the specified node could not be found.
-
#find_child(name, opts = {}) ⇒ Object
included
from Tree
Among this node’s children, find a node by its name.
- #folder? ⇒ Boolean
- #full_name ⇒ Object
-
#initialize(name, parent: nil, fs_path: nil, source: nil) ⇒ Node
constructor
A new instance of Node.
-
#layout ⇒ Object
Returns the layout(s) configured for this node.
- #logger ⇒ Object
- #page? ⇒ Boolean
-
#pages ⇒ Object
included
from Tree
Returns all children that will compile to a HTML page.
- #parent=(new_parent) ⇒ Object included from Tree
-
#perform_setup! ⇒ Object
included
from Staging
Perform setup for this node.
-
#reload! ⇒ Object
included
from Reading
(Re-)loads the node from the filesystem, if it’s a filesystem based node.
-
#render(opts = {}) ⇒ Object
included
from Rendering
Creates a new View instance and uses it to render this node.
-
#root ⇒ Object
included
from Tree
Returns the tree’s root node.
-
#root? ⇒ Boolean
included
from Tree
Returns true if this node is also the tree’s root node.
- #should_publish? ⇒ Boolean
- #sibling(name) ⇒ Object included from Tree
-
#siblings ⇒ Object
included
from Tree
Returns this node’s siblings (ie. other nodes within the same folder node.).
- #stage! ⇒ Object included from Staging
-
#title ⇒ Object
Returns the node’s title.
- #to_s ⇒ Object
- #tree_size ⇒ Object included from Tree
-
#url ⇒ Object
included
from Paths
Returns the node’s URL.
Constructor Details
#initialize(name, parent: nil, fs_path: nil, source: nil) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flutterby/node.rb', line 10 def initialize(name, parent: nil, fs_path: nil, source: nil) @fs_path = fs_path ? ::File.(fs_path) : nil @source = source @_setup_procs = [] # Extract name, extension, and filters from given name parts = name.split(".") @name = parts.shift @ext = parts.shift @filters = parts.reverse # Register this node with its parent if parent self.parent = parent end reload! end |
Instance Attribute Details
#_setup_procs ⇒ Object (readonly)
Returns the value of attribute _setup_procs.
8 9 10 |
# File 'lib/flutterby/node.rb', line 8 def _setup_procs @_setup_procs end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/flutterby/node.rb', line 6 def children @children end |
#ext ⇒ Object
Returns the value of attribute ext.
5 6 7 |
# File 'lib/flutterby/node.rb', line 5 def ext @ext end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
6 7 8 |
# File 'lib/flutterby/node.rb', line 6 def filters @filters end |
#fs_path ⇒ Object (readonly)
Returns the value of attribute fs_path.
6 7 8 |
# File 'lib/flutterby/node.rb', line 6 def fs_path @fs_path end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/flutterby/node.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/flutterby/node.rb', line 6 def parent @parent end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/flutterby/node.rb', line 7 def prefix @prefix end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
7 8 9 |
# File 'lib/flutterby/node.rb', line 7 def slug @slug end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/flutterby/node.rb', line 5 def source @source end |
Instance Method Details
#copy(new_name, data = {}) ⇒ Object
393 394 395 396 397 398 399 |
# File 'lib/flutterby/node.rb', line 393 def copy(new_name, data = {}) dup.tap do |c| c.name = new_name c.data.merge!(data) parent.children << c end end |
#create(name, **args) ⇒ Object Originally defined in module Tree
Creates a new node, using the specified arguments, as a child of this node.
#data ⇒ Object Originally defined in module Reading
#emit_child(name) ⇒ Object Originally defined in module Tree
#extend_all(nodes, *mods, &blk) ⇒ Object Originally defined in module Staging
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.
#extend_parent(*mods, &blk) ⇒ Object Originally defined in module Staging
Extend this node’s parent. See #extend_all.
#extend_siblings(*mods, &blk) ⇒ Object Originally defined in module Staging
Extend all of this node’s siblings. See #extend_all.
#file? ⇒ Boolean
377 378 379 |
# File 'lib/flutterby/node.rb', line 377 def file? !folder? && should_publish? end |
#find(path, opts = {}) ⇒ Object Originally defined in module Tree
#find!(path, *args) ⇒ Object Originally defined in module Tree
Like #find, but raises an exception when the specified node could not be found.
#find_child(name, opts = {}) ⇒ Object Originally defined in module Tree
Among this node’s children, find a node by its name. If the name passed as an argument includes a dot, the name will match against the full name of the children; otherwise, just the base name.
Examples:
# returns the first child called "index"
find_child("index")
# returns the child called "index" with extension "html"
find_child("index.html")
#folder? ⇒ Boolean
373 374 375 |
# File 'lib/flutterby/node.rb', line 373 def folder? children.any? end |
#full_name ⇒ Object
369 370 371 |
# File 'lib/flutterby/node.rb', line 369 def full_name [name, ext].compact.join(".") end |
#layout ⇒ Object
Returns the layout(s) configured for this node. This is sourced from the node’s Flutterby::Node::Reading#data attribute, so it can be set from front matter.
361 362 363 |
# File 'lib/flutterby/node.rb', line 361 def layout data[:layout] end |
#logger ⇒ Object
389 390 391 |
# File 'lib/flutterby/node.rb', line 389 def logger Flutterby.logger end |
#page? ⇒ Boolean
381 382 383 |
# File 'lib/flutterby/node.rb', line 381 def page? file? && ext == "html" end |
#pages ⇒ Object Originally defined in module Tree
Returns all children that will compile to a HTML page.
#parent=(new_parent) ⇒ Object Originally defined in module Tree
#perform_setup! ⇒ Object Originally defined in module Staging
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.
#reload! ⇒ Object Originally defined in module Reading
(Re-)loads the node from the filesystem, if it’s a filesystem based node.
#render(opts = {}) ⇒ Object Originally defined in module Rendering
Creates a new View instance and uses it to render this node. Returns the rendered page as a string.
#root ⇒ Object Originally defined in module Tree
Returns the tree’s root node.
#root? ⇒ Boolean Originally defined in module Tree
Returns true if this node is also the tree’s root node.
#should_publish? ⇒ Boolean
385 386 387 |
# File 'lib/flutterby/node.rb', line 385 def should_publish? !name.start_with?("_") end |
#sibling(name) ⇒ Object Originally defined in module Tree
#siblings ⇒ Object Originally defined in module Tree
Returns this node’s siblings (ie. other nodes within the same folder node.)
#stage! ⇒ Object Originally defined in module Staging
#title ⇒ Object
Returns the node’s title. If there is a ‘:title` key in Flutterby::Node::Reading#data, its value will be used; otherwise, as a fallback, it will generate a human-readable title from #slug.
354 355 356 |
# File 'lib/flutterby/node.rb', line 354 def title data[:title] || slug.try(:titleize) end |
#to_s ⇒ Object
365 366 367 |
# File 'lib/flutterby/node.rb', line 365 def to_s "<#{self.class} #{self.url}>" end |
#tree_size ⇒ Object Originally defined in module Tree
#url ⇒ Object Originally defined in module Paths
Returns the node’s URL.