Class: OMF::Web::Rack::TabMapper
Instance Method Summary
collapse
#_logger, #debug, #error, #fatal, #info, init_log, logger, set_environment, #warn
Constructor Details
#initialize(opts = {}) ⇒ TabMapper
Returns a new instance of TabMapper.
17
18
19
20
21
22
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 17
def initialize(opts = {})
@opts = opts
@tab_opts = opts[:tabs] || {}
@tabs = {}
find_tabs()
end
|
Instance Method Details
#_component_name(path) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 55
def _component_name(path)
unless comp_name = path[1]
comp_name = ((@opts[:tabs] || [])[0] || {})[:id]
end
comp_name = comp_name.to_sym if comp_name
comp_name
end
|
#call(env) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 34
def call(env)
req = ::Rack::Request.new(env)
OMF::Web::Theme.require 'page'
body, = render_page(req)
if .kind_of? String
= {"Content-Type" => }
end
[200, , [body]] end
|
#find_tabs ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 24
def find_tabs()
tabs = OMF::Web::Widget.toplevel_widgets(@opts[:use_tabs])
@enabled_tabs = {}
tabs.each do |t|
name = t[:id].to_sym
@enabled_tabs[name] = t
end
@opts[:tabs] = tabs
end
|
92
93
94
95
96
97
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 92
def find_top_widget(tab, req)
sid = req.params['sid']
tab_id = tab[:id]
@tabs[tab_id] ||= OMF::Web::Widget.create_widget(tab_id)
end
|
#render_card(req) ⇒ Object
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
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 63
def render_card(req)
opts = @opts.dup
opts[:prefix] = req.script_name
opts[:request] = req
opts[:path] = req.path_info
path = req.path_info.split('/')
unless comp_name = _component_name(path)
return render_no_card(opts)
end
opts[:component_name] = comp_name.to_sym
tab = @enabled_tabs[comp_name]
unless tab
warn "Request for unknown component '#{comp_name.inspect}':(#{@enabled_tabs.keys.inspect})"
return render_unknown_card(comp_name, opts)
end
opts[:tab] = tab_id = tab[:id]
widget = find_top_widget(tab, req)
OMF::Web::Theme.require 'page'
page = OMF::Web::Theme::Page.new(widget, opts)
[page.to_html, 'text/html']
end
|
#render_no_card(popts) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 107
def render_no_card(popts)
popts[:active_id] = 'unknown'
popts[:flash] = {:alert => %{There are no components defined for this site.}}
popts[:tabs] = []
[OMF::Web::Theme::Page.new(nil, popts).to_html, 'text/html']
end
|
#render_page(req) ⇒ Object
114
115
116
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 114
def render_page(req)
render_card(req)
end
|
#render_unknown_card(comp_name, popts) ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/omf-web/rack/tab_mapper.rb', line 99
def render_unknown_card(comp_name, popts)
popts[:flash] = {:alert => %{Unknonw component '#{comp_name}'. To select any of the available
components, please click on one of the tabs above.}}
[OMF::Web::Theme::Page.new(nil, popts).to_html, 'text/html']
end
|