Class: Moka::SiteTree::PageNode
- Defined in:
- lib/commands/lib/site_tree.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
Attributes inherited from TreeNode
Instance Method Summary collapse
-
#initialize(name, params = {}, parent = nil) ⇒ PageNode
constructor
A new instance of PageNode.
-
#save ⇒ Object
Save page variables in the variables.yml file.
Methods inherited from TreeNode
#children, #find_child, #params, #variables, #vars
Constructor Details
#initialize(name, params = {}, parent = nil) ⇒ PageNode
Returns a new instance of PageNode.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/commands/lib/site_tree.rb', line 172 def initialize(name, params = {}, parent = nil) super(name, params, parent) @group = parent if File.exist? File.("project/site/#{@group.name}/#{name}/variables.yml", MOKA_ROOT) page_vars = YAML.load_file(File.("project/site/#{@group.name}/#{name}/variables.yml", MOKA_ROOT)) || {} else page_vars = {} end @group.variables.merge(page_vars).each do |key, value| unless RESERVED_NAMES.include? key self.instance_variable_set("@#{key}", value) @variables[key.to_s] = value if page_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/, "_") self.instance_variable_set "@#{key}", value @params[key.to_s] = value self.create_method(key) do self.instance_variable_get("@#{key}") end end end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
170 171 172 |
# File 'lib/commands/lib/site_tree.rb', line 170 def group @group end |