Class: Vitae::Nodes::Node
- Inherits:
-
Object
- Object
- Vitae::Nodes::Node
show all
- Includes:
- Haml::Helpers, Helpers
- Defined in:
- lib/vitae/server/node.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#content_tag, #current_theme, #include_theme_css, #include_theme_js, #link_to, #tag
Constructor Details
#initialize(data, name = nil, level = 1, parent_path = []) ⇒ Node
Returns a new instance of Node.
34
35
36
37
38
39
40
41
|
# File 'lib/vitae/server/node.rb', line 34
def initialize(data, name=nil, level=1, parent_path=[])
@data = data
@name = name
@level = level
@path = parent_path << name
init_haml_helpers
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7
8
9
|
# File 'lib/vitae/server/node.rb', line 7
def data
@data
end
|
#level ⇒ Object
Returns the value of attribute level.
7
8
9
|
# File 'lib/vitae/server/node.rb', line 7
def level
@level
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/vitae/server/node.rb', line 7
def name
@name
end
|
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'lib/vitae/server/node.rb', line 7
def path
@path
end
|
Class Method Details
.set(option, value = self, &block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/vitae/server/node.rb', line 10
def set(option, value=self, &block)
value = block if block
if value.kind_of?(Proc)
define_method option, &value
elsif value == self && option.respond_to?(:each)
option.each { |k,v| set(k, v) }
else
set option, Proc.new{value}
end
self
end
|
Instance Method Details
#child_node_class(key, value) ⇒ Object
107
108
109
|
# File 'lib/vitae/server/node.rb', line 107
def child_node_class(key, value)
child_node_class_from_yaml(value) || default_child_node_class || child_node_class_from_name(key)
end
|
#child_node_class_from_name(name) ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/vitae/server/node.rb', line 99
def child_node_class_from_name(name)
case name
when /expertise/i then TagCloudNode
when /projects/i then ProjectListNode
else Node
end
end
|
#child_node_class_from_yaml(value) ⇒ Object
95
96
97
|
# File 'lib/vitae/server/node.rb', line 95
def child_node_class_from_yaml(value)
Node.types[value["node_type"]] if value.is_a? Hash
end
|
#collection_wrapper(&block) ⇒ Object
72
73
74
75
|
# File 'lib/vitae/server/node.rb', line 72
def collection_wrapper &block
return block.call unless collection_tag
haml_tag collection_tag, &block
end
|
#html ⇒ Object
49
50
51
52
|
# File 'lib/vitae/server/node.rb', line 49
def html
haml_tag "h#{level}", name if name
show_data
end
|
#node_wrapper(&block) ⇒ Object
77
78
79
80
|
# File 'lib/vitae/server/node.rb', line 77
def node_wrapper &block
return block.call unless node_tag
haml_tag node_tag, &block
end
|
#output_data ⇒ Object
54
55
56
|
# File 'lib/vitae/server/node.rb', line 54
def output_data
data.except(%w[node_type intro extro])
end
|
#show_data ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/vitae/server/node.rb', line 58
def show_data
case data
when Hash
haml_tag ".intro", data["intro"] if data["intro"]
show_hash
haml_tag ".extro", data["extro"] if data["extro"]
when Array
haml_concat "Array!"
else
haml_concat data
end
end
|
#show_hash ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/vitae/server/node.rb', line 84
def show_hash
collection_wrapper do
output_data.each do |key, value|
node_class = child_node_class(key, value)
node_wrapper do
haml_concat node_class.new(value, key, level+1, path)
end
end
end
end
|
#to_s ⇒ Object
43
44
45
46
47
|
# File 'lib/vitae/server/node.rb', line 43
def to_s
capture_haml do
html
end
end
|