Class: Clot::LinkItem
Instance Method Summary
collapse
Methods included from TagHelper
#resolve_value, #split_params
#delete_link, #edit_link, #gen_delete_link, #gen_delete_onclick, #index_link, #new_link, #stylesheet_link, #view_link
Methods included from UrlFilters
#delete_link, #edit_link, #get_nested_edit_url, #get_nested_url, #index_link, #object_url, #stylesheet_url, #view_link
Constructor Details
#initialize(name, params, tokens) ⇒ LinkItem
Returns a new instance of LinkItem.
30
31
32
33
|
# File 'lib/clot/nav_bar.rb', line 30
def initialize(name, params, tokens)
@params = split_params(params)
super
end
|
Instance Method Details
#apply_params(params, context) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/clot/nav_bar.rb', line 48
def apply_params(params, context)
params.each do |pair|
pair_data = pair.split ":"
case pair_data[0]
when "label" then
@label = pair_data[1]
when "new" then
@label ||= "Create"
@link = "/#{pair_data[1]}/new"
when "index" then
@label ||= "Index"
@link = "/#{pair_data[1]}"
when "view" then
@label ||= "View"
obj = context[pair_data[1]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}"
when "nested_index" then
@label ||= "Index"
obj = context[pair_data[1]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}/#{pair_data[2]}"
when "nested_new" then
@label ||= "Create"
obj = context[pair_data[1]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}/#{pair_data[2]}/new"
when "nested_show" then
@label ||= "Show"
obj = context[pair_data[1]]
obj2 = context[pair_data[2]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}/#{obj2.dropped_class.to_s.tableize}/#{obj2.id}"
when "nested_edit" then
@label ||= "Edit"
obj = context[pair_data[1]]
obj2 = context[pair_data[2]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}/#{obj2.dropped_class.to_s.tableize}/#{obj2.id}/edit"
when "nested_delete" then
@label ||= "Delete"
obj = context[pair_data[1]]
obj2 = context[pair_data[2]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}/#{obj2.dropped_class.to_s.tableize}/#{obj2.id}"
@context = context
@onclick = " onclick=\"#{gen_delete_onclick}\""
when "edit" then
@label ||= "Edit"
obj = context[pair_data[1]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}/edit"
when "delete" then
@label ||= "Delete"
obj = context[pair_data[1]]
@link = "/#{obj.dropped_class.to_s.tableize}/#{obj.id}"
@context = context
@onclick = " onclick=\"#{gen_delete_onclick}\""
end
end
end
|
#raw_link ⇒ Object
43
44
45
46
|
# File 'lib/clot/nav_bar.rb', line 43
def raw_link
@onclick ||= ""
"<a href=\"#{@link}\"#{@onclick}>#{@label}</a>"
end
|
#render(context) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/clot/nav_bar.rb', line 10
def render(context)
@tag_factory = context['tag_factory']
tag_generator(@params, context)
LinkItem.has_predecessor ||= {}
separator = ""
if LinkItem.has_predecessor[context['block_id']]
separator = @tag_factory[:list_item_separator] || ""
end
prefix = @tag_factory[:list_item_open_tag] || ""
postfix = @tag_factory[:list_item_close_tag] || ""
link = separator + prefix + raw_link + postfix
filter = @tag_factory[:link_filter] || lambda{|link,context| link}
tag = filter.call link, context
unless tag.blank? || !tag
LinkItem.has_predecessor[context['block_id']] = true
link
end
end
|
#tag_generator(params, context) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/clot/nav_bar.rb', line 35
def tag_generator(params, context)
unless params[0].match /:/
@label = params.shift
@link = "/#{@label}"
end
apply_params(params, context)
end
|