Class: OMF::Web::Rack::WidgetMapper
Instance Method Summary
collapse
#_logger, #debug, #error, #fatal, #info, init_log, logger, set_environment, #warn
Constructor Details
#initialize(opts = {}) ⇒ WidgetMapper
Returns a new instance of WidgetMapper.
14
15
16
17
|
# File 'lib/omf-web/rack/widget_mapper.rb', line 14
def initialize(opts = {})
@opts = opts
@tabs = {}
end
|
Instance Method Details
#call(env) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/omf-web/rack/widget_mapper.rb', line 19
def call(env)
req = ::Rack::Request.new(env)
sessionID = req.params['sid']
if sessionID.nil? || sessionID.empty?
sessionID = "s#{(rand * 10000000).to_i}"
end
Thread.current["sessionID"] = sessionID
body, = render_page(req)
if .kind_of? String
= {"Content-Type" => , "Access-Control-Allow-Origin" => "*"}
end
[200, , [body]]
end
|
#render_page(req) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/omf-web/rack/widget_mapper.rb', line 34
def render_page(req)
opts = @opts.dup
opts[:prefix] = req.script_name
opts[:request] = req
opts[:path] = req.path_info
p = req.path_info
p = '/' if p.empty?
widget_name = p.split('/')[1]
unless widget_name
return render_widget_list(opts)
end
widget_name = opts[:widget_name] = widget_name.to_sym
begin
widget = OMF::Web::Widget.create_widget(widget_name)
page = OMF::Web::Theme::WidgetPage.new(widget, opts)
return [page.to_html, 'text/html']
rescue Exception => ex
warn "Request for unknown widget '#{widget_name}':(#{ex})"
opts[:flash] = {:alert => %{Unknonw widget '#{widget_name}'.}}
[OMF::Web::Theme::WidgetPage.new(nil, opts).to_html, 'text/html']
end
end
|
59
60
61
62
|
# File 'lib/omf-web/rack/widget_mapper.rb', line 59
def render_widget_list(popts)
wlist = OMF::Web::Widget.registered_widgets
[wlist.to_json, 'application/json']
end
|