Module: BlueTree::Node
- Defined in:
- lib/blue_tree/node.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#child_nodes ⇒ Object
readonly
Returns the value of attribute child_nodes.
-
#parent_node ⇒ Object
readonly
Returns the value of attribute parent_node.
-
#root_node ⇒ Object
readonly
Returns the value of attribute root_node.
Class Method Summary collapse
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #initialize(template_symbol) ⇒ Object
- #render ⇒ Object
- #render_template(template_symbol) ⇒ Object
- #set_parent_node(parent) ⇒ Object
- #set_root_node(root_node) ⇒ Object
- #template_contents(template_symbol) ⇒ Object
- #template_ext ⇒ Object
- #template_path ⇒ Object
Instance Attribute Details
#child_nodes ⇒ Object (readonly)
Returns the value of attribute child_nodes.
5 6 7 |
# File 'lib/blue_tree/node.rb', line 5 def child_nodes @child_nodes end |
#parent_node ⇒ Object (readonly)
Returns the value of attribute parent_node.
5 6 7 |
# File 'lib/blue_tree/node.rb', line 5 def parent_node @parent_node end |
#root_node ⇒ Object (readonly)
Returns the value of attribute root_node.
5 6 7 |
# File 'lib/blue_tree/node.rb', line 5 def root_node @root_node end |
Class Method Details
.included(base) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/blue_tree/node.rb', line 25 def self.included(base) base.extend ClassMethods base.use_template_path( File.(File.join(File.dirname(__FILE__), '..', '..', 'templates')) ) base.use_template_ext '.html.erb' end |
Instance Method Details
#add_child(child) ⇒ Object
52 53 54 55 56 |
# File 'lib/blue_tree/node.rb', line 52 def add_child(child) child.set_root_node(@root_node || self) child.set_parent_node self @child_nodes << child end |
#initialize(template_symbol) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/blue_tree/node.rb', line 33 def initialize(template_symbol) @template = template_contents(template_symbol) @child_nodes = [] @parent_node = nil @root_node = nil end |
#render ⇒ Object
67 68 69 |
# File 'lib/blue_tree/node.rb', line 67 def render ERB.new(@template, nil, '-').result(binding) end |
#render_template(template_symbol) ⇒ Object
71 72 73 |
# File 'lib/blue_tree/node.rb', line 71 def render_template(template_symbol) ERB.new(template_contents(template_symbol), nil, '-').result(binding) end |
#set_parent_node(parent) ⇒ Object
63 64 65 |
# File 'lib/blue_tree/node.rb', line 63 def set_parent_node(parent) @parent_node = parent end |
#set_root_node(root_node) ⇒ Object
58 59 60 61 |
# File 'lib/blue_tree/node.rb', line 58 def set_root_node(root_node) @root_node = root_node child_nodes.each { |child| child.set_root_node(root_node) } end |
#template_contents(template_symbol) ⇒ Object
48 49 50 |
# File 'lib/blue_tree/node.rb', line 48 def template_contents(template_symbol) File.read(File.join(template_path, "#{template_symbol}#{template_ext}")) end |
#template_ext ⇒ Object
44 45 46 |
# File 'lib/blue_tree/node.rb', line 44 def template_ext self.class.template_ext end |
#template_path ⇒ Object
40 41 42 |
# File 'lib/blue_tree/node.rb', line 40 def template_path self.class.template_path end |