Class: OMF::Web::Rack::TabMapper
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::Web::Rack::TabMapper
- Defined in:
- lib/omf-web/rack/tab_mapper.rb
Instance Method Summary collapse
- #_component_name(path) ⇒ Object
- #call(env) ⇒ Object
- #find_tabs ⇒ Object
- #find_top_widget(tab, req) ⇒ Object
-
#initialize(opts = {}) ⇒ TabMapper
constructor
A new instance of TabMapper.
- #render_card(req) ⇒ Object
- #render_no_card(popts) ⇒ Object
- #render_page(req) ⇒ Object
- #render_unknown_card(comp_name, popts) ⇒ Object
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
48 49 50 51 52 53 54 55 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 48 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 #puts "PATH: #{path} - #{comp_name}" comp_name end |
#call(env) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 34 def call(env) #puts env.keys.inspect req = ::Rack::Request.new(env) debug "Requesting #{req.path}" OMF::Web::Theme.require 'page' body, headers = render_page(req) if headers.kind_of? String headers = {"Content-Type" => headers} end [200, headers, [body]] # required for ruby > 1.9.2 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.(@opts[:use_tabs]) @enabled_tabs = {} tabs.each do |t| name = t[:id].to_sym @enabled_tabs[name] = t end @opts[:tabs] = tabs end |
#find_top_widget(tab, req) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 87 def (tab, req) sid = req.params['sid'] tab_id = tab[:id] @tabs[tab_id] ||= OMF::Web::Widget.(tab_id) #inst = OMF::Web::SessionStore[tab_id, :tab] end |
#render_card(req) ⇒ Object
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 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 57 def render_card(req) #puts ">>>> REQ: #{req.path_info}::#{req.inspect}" 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) puts ">>>>> #{path} - #{opts[:tabs]}" return render_no_card(opts) end opts[:component_name] = comp_name.to_sym # action = (path[2] || 'show').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] = (tab, req) OMF::Web::Theme.require 'page' page = OMF::Web::Theme::Page.new(, opts) [page.to_html, 'text/html'] end |
#render_no_card(popts) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 102 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
109 110 111 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 109 def render_page(req) render_card(req) end |
#render_unknown_card(comp_name, popts) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/omf-web/rack/tab_mapper.rb', line 94 def render_unknown_card(comp_name, popts) #popts[:active_id] = 'unknown' 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 |