Class: Moka::SiteTree::GroupNode
- Defined in:
- lib/commands/lib/site_tree.rb
Instance Attribute Summary collapse
-
#site ⇒ Object
Returns the value of attribute site.
Attributes inherited from TreeNode
Instance Method Summary collapse
-
#find_page(page_name) ⇒ Object
Looks for a page in the group having the name equal to the string passed as argument.
-
#initialize(name, params = {}, parent = nil) ⇒ GroupNode
constructor
A new instance of GroupNode.
-
#pages ⇒ Object
Returns a NodeArray object containing all the pages in the group (its children nodes).
-
#save ⇒ Object
Save group variables in the variables.yml file.
Methods inherited from TreeNode
#children, #find_child, #params, #variables, #vars
Constructor Details
#initialize(name, params = {}, parent = nil) ⇒ GroupNode
Returns a new instance of GroupNode.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/commands/lib/site_tree.rb', line 118 def initialize(name, params = {}, parent = nil) super(name, params, parent) @site = parent if File.exist? File.("project/site/#{name}/variables.yml", MOKA_ROOT) group_vars = YAML.load_file(File.("project/site/#{name}/variables.yml", MOKA_ROOT)) || {} else group_vars = {} end @site.variables.merge(group_vars).each do |key, value| unless RESERVED_NAMES.include? key self.instance_variable_set "@#{key}", value @variables[key.to_s] = value if group_vars.keys.include? key.to_s self.create_method(key) do self.instance_variable_get("@#{key}") end self.create_method("#{key}=") do |v| self.instance_variable_set("@#{key}", v); @variables[key.to_s] = v end end end params.each do |key, value| key.gsub!(/\s/, "_") if value.is_a?(Hash) self.instance_variable_set "@#{key}", PageNode.new(key, value, self) @children << instance_eval("@#{key}") else self.instance_variable_set "@#{key}", value @params[key.to_s] = value end self.create_method(key) do self.instance_variable_get("@#{key}") end end end |
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site.
116 117 118 |
# File 'lib/commands/lib/site_tree.rb', line 116 def site @site end |
Instance Method Details
#find_page(page_name) ⇒ Object
Looks for a page in the group having the name equal to the string passed as argument. Returns the page or nil if no such page was found.
155 156 157 |
# File 'lib/commands/lib/site_tree.rb', line 155 def find_page(page_name) children.find(page_name) end |
#pages ⇒ Object
Returns a NodeArray object containing all the pages in the group (its children nodes)
150 151 152 |
# File 'lib/commands/lib/site_tree.rb', line 150 def pages self.children end |