Module: FunkyTabs
- Defined in:
- lib/funky_tabs.rb,
lib/funky_tabs/tab.rb,
lib/funky_tabs/rails.rb,
lib/funky_tabs/helpers.rb,
lib/funky_tabs/renderers.rb,
lib/funky_tabs/tab_action.rb
Defined Under Namespace
Modules: Helpers, Renderers Classes: Engine, FunkyTabsException, Tab, TabAction, UpdateController
Class Method Summary collapse
- .add_tab(string_or_hash) ⇒ Object
- .add_tabs(array_of_properties) ⇒ Object
- .ajax_fail_message ⇒ Object
- .content_path_for_tab_and_tab_action(tab, tab_action = nil, tab_action_id = nil) ⇒ Object
- .correct_path_for_location_hash?(path, location_hash) ⇒ Boolean
- .default_tab_index ⇒ Object
- .default_tabs_controller ⇒ Object
- .find_tab(tab_or_string_or_hash) ⇒ Object
- .javascript_key_array ⇒ Object
- .loading_html ⇒ Object
- .location_hash_for_content_path(path) ⇒ Object
- .location_hash_for_indices(tab_index, tab_action_index = nil) ⇒ Object
- .location_hash_for_tab_action(tab, tab_action = nil, tab_action_id = nil) ⇒ Object
- .location_hashes_for_content_paths ⇒ Object
- .missing_tab_action_path ⇒ Object
-
.reset ⇒ Object
TODO: Figure out way to reset all mattr_accessors.
- .setup {|_self| ... } ⇒ Object
- .tab(sym_or_string) ⇒ Object
- .tab_and_tab_action_from_location_hash(location_hash) ⇒ Object
- .tab_index_from_location_hash(location_hash) ⇒ Object
- .tabs ⇒ Object
Class Method Details
.add_tab(string_or_hash) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/funky_tabs.rb', line 66 def self.add_tab(string_or_hash) tab_index = find_tab(string_or_hash) if tab_index.nil? # if the tab doesnt exist, create it new_tab = FunkyTabs::Tab.new(string_or_hash) tabs << new_tab return new_tab else # if the tab exists, return it return tabs[tab_index] end raise FunkyTabsException.new("Dont know how to add this tab with #{string_or_hash.inspect}") end |
.add_tabs(array_of_properties) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/funky_tabs.rb', line 80 def self.add_tabs(array_of_properties) raise FunkyTabsException.new("dont know how to create tabs from #{array_of_properties.inspect}") unless array_of_properties.is_a?(Array) array_of_properties.each do |tab_properties| add_tab(tab_properties) end return tabs end |
.ajax_fail_message ⇒ Object
58 59 60 |
# File 'lib/funky_tabs.rb', line 58 def self. @@ajax_fail_message ||= "It appears something has gone wrong. We apologize for the inconvenience." end |
.content_path_for_tab_and_tab_action(tab, tab_action = nil, tab_action_id = nil) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/funky_tabs.rb', line 126 def self.content_path_for_tab_and_tab_action(tab,tab_action=nil,tab_action_id=nil) unless tab.is_a?(FunkyTabs::Tab) tab_index = find_tab(tab) return missing_tab_action_path if tab_index.nil? tab = tabs[tab_index] end unless tab_action.is_a?(FunkyTabs::TabAction) tab_action_index = tab.find_tab_action(tab_action||tab.default_tab_action) return missing_tab_action_path if tab_action_index.nil? tab_action = tab.tab_actions[tab_action_index] end unless tab_action.content_path.blank? return tab_action.content_path if tab_action_id.nil? return tab_action.content_path+"&id=#{tab_action_id}" if tab_action.content_path.include?("?") return tab_action.content_path+"?id=#{tab_action_id}" end if tab_action.name.downcase == "index" content_path = "/#{default_tabs_controller}/#{tab.name.gsub(/\s/,"_").downcase}_index" else content_path = "/#{default_tabs_controller}/#{tab_action.name.gsub(/\s/,"_").downcase}_#{tab.name.gsub(/\s/,"_").downcase}" end return content_path if tab_action_id.nil? return "#{content_path}/#{tab_action_id}" end |
.correct_path_for_location_hash?(path, location_hash) ⇒ Boolean
178 179 180 181 182 183 184 |
# File 'lib/funky_tabs.rb', line 178 def self.correct_path_for_location_hash?(path,location_hash) return false if path.blank? || location_hash.blank? path = path.split("?").first tab,tab_action,tab_action_id = tab_and_tab_action_from_location_hash(location_hash) return path == content_path_for_tab_and_tab_action(tab,tab_action) end |
.default_tab_index ⇒ Object
40 41 42 |
# File 'lib/funky_tabs.rb', line 40 def self.default_tab_index @@default_tab_index ||= 0 end |
.default_tabs_controller ⇒ Object
44 45 46 |
# File 'lib/funky_tabs.rb', line 44 def self.default_tabs_controller @@default_tabs_controller ||= "funky_tabs/update" end |
.find_tab(tab_or_string_or_hash) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/funky_tabs.rb', line 94 def self.find_tab(tab_or_string_or_hash) return nil if tab_or_string_or_hash.blank? || tabs.blank? tab_or_string_or_hash = tab_or_string_or_hash.to_s if tab_or_string_or_hash.is_a?(Symbol) return tabs.index {|tab| tab.name.downcase == tab_or_string_or_hash.downcase} if tab_or_string_or_hash.is_a?(String) return tabs.index {|action| action.name == tab_or_string_or_hash[:name] } if tab_or_string_or_hash.is_a?(Hash) return tabs.index(tab_or_string_or_hash) if tab_or_string_or_hash.is_a?(FunkyTabs::Tab) raise FunkyTabsException.new("dont know how to find tab with #{tab_or_string_or_hash.inspect}") end |
.javascript_key_array ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/funky_tabs.rb', line 191 def self.javascript_key_array js_array = "var path_from_hash_arr = {" location_hashes_for_content_paths.each do |path,location_hash| if path.include?("?") path = path + "&funky_tabs=true" else path = path + "?funky_tabs=true" end js_array = js_array + "'#{location_hash}':'#{path}'," end js_array = js_array.chomp(",")+"};" end |
.loading_html ⇒ Object
54 55 56 |
# File 'lib/funky_tabs.rb', line 54 def self.loading_html @@loading_html ||= "Loading..." end |
.location_hash_for_content_path(path) ⇒ Object
186 187 188 189 |
# File 'lib/funky_tabs.rb', line 186 def self.location_hash_for_content_path(path) path = path.split("?").first return location_hashes_for_content_paths[path] rescue nil end |
.location_hash_for_indices(tab_index, tab_action_index = nil) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/funky_tabs.rb', line 117 def self.location_hash_for_indices(tab_index,tab_action_index=nil) tab_index = tab_index.to_i tab_action_index = tab_action_index.to_i unless tab_action_index.nil? tab = tab_index.nil? ? nil : tabs[tab_index] tab_action = nil tab_action = tab.tab_actions[tab_action_index] unless tab.nil? || tab_action_index.nil? return location_hash_for_tab_action(tab,tab_action) end |
.location_hash_for_tab_action(tab, tab_action = nil, tab_action_id = nil) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/funky_tabs.rb', line 103 def self.location_hash_for_tab_action(tab,tab_action=nil,tab_action_id=nil) return nil if tab.nil? tab_index = find_tab(tab) return nil if tab_index.nil? tab_action_index = tabs[tab_index].find_tab_action(tab_action) default_index = tabs[tab_index].find_tab_action(tabs[tab_index].default_tab_action) return tab_index.to_s if tab_action_index.nil? || tab_action_index == default_index return "#{tab_index}-#{tab_action_index}" if tab_action_id.nil? return "#{tab_index}-#{tab_action_index}-#{tab_action_id}" end |
.location_hashes_for_content_paths ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/funky_tabs.rb', line 24 def self.location_hashes_for_content_paths return @@location_hashes_for_content_paths unless @@location_hashes_for_content_paths.blank? path_hash = {} tabs.each do |tab| tab.tab_actions.each do |tab_action| location_hash = location_hash_for_tab_action(tab,tab_action) path = content_path_for_tab_and_tab_action(tab,tab_action) path_hash[path] = location_hash end end @@location_hashes_for_content_paths = path_hash end |
.missing_tab_action_path ⇒ Object
48 49 50 |
# File 'lib/funky_tabs.rb', line 48 def self.missing_tab_action_path @@missing_tab_action_path ||= "/funky_tabs/update/missing_tab" end |
.reset ⇒ Object
TODO: Figure out way to reset all mattr_accessors
205 206 207 208 |
# File 'lib/funky_tabs.rb', line 205 def self.reset tabs.clear tab_root = "" end |
.setup {|_self| ... } ⇒ Object
62 63 64 |
# File 'lib/funky_tabs.rb', line 62 def self.setup yield self end |
.tab(sym_or_string) ⇒ Object
88 89 90 91 92 |
# File 'lib/funky_tabs.rb', line 88 def self.tab(sym_or_string) tab_index = find_tab(sym_or_string.to_s) return tabs[tab_index] unless tab_index.nil? return nil end |
.tab_and_tab_action_from_location_hash(location_hash) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/funky_tabs.rb', line 151 def self.tab_and_tab_action_from_location_hash(location_hash) return nil,nil,nil if tabs.blank? return tabs[default_tab_index],nil,nil if location_hash.blank? indices = location_hash.to_s.split("-") return nil,nil,nil if indices.first.nil? tab_index = indices.first.to_i tab = tabs[tab_index] return nil,nil,nil if tab.nil? tab_action_index = indices[1].to_i return tab,nil,nil if tab_action_index.nil? return tab,nil,nil if tab_action_index.to_i >= tab.tab_actions.length tab_action = tab.tab_actions[tab_action_index] tab_action_id = indices[2] return tab,tab_action,tab_action_id end |
.tab_index_from_location_hash(location_hash) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/funky_tabs.rb', line 169 def self.tab_index_from_location_hash(location_hash) return default_tab_index if tabs.blank? || location_hash.blank? indices = location_hash.to_s.split("-"); return default_tab_index if indices.first.nil? tab = tabs[indices.first.to_i] return default_tab_index if tab.nil? return indices.first end |
.tabs ⇒ Object
19 20 21 |
# File 'lib/funky_tabs.rb', line 19 def self.tabs @@tabs ||= [] end |