Module: Card::Set::All::Bootstrap::Tabs::HtmlFormat
- Extended by:
- Card::Set::AbstractFormat
- Defined in:
- tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb
Instance Method Summary collapse
-
#lazy_loading_tabs(tabs, active_name, active_content = "", args = {}, &block) ⇒ HTML
beginning tab; other tabs get loaded via ajax when selected.
- #lazy_tab_button(tab_name, id, url, active_tab) ⇒ Object
- #lazy_tab_pane(id, tab_name, active_tab, active_content, args) ⇒ Object
- #standardize_tabs(tabs, active_name) ⇒ Object
-
#static_tabs(tabs, active_name = nil, tab_type = "tabs", args = {}) ⇒ HTML
beginning (default is the first).
- #tab_button(target, text, active = false, link_attr = {}) ⇒ Object
- #tab_button_link(target, text, link_attr = {}) ⇒ Object
- #tab_id(tab_name) ⇒ Object
- #tab_pane(id, tab_name, content, active = false, args = nil) ⇒ Object
- #tab_panel(tab_buttons, tab_panes, tab_type = "tabs", args = nil) ⇒ Object
- #tab_title_and_url(tab_details, tab_view_name) ⇒ Object
Instance Method Details
#lazy_loading_tabs(tabs, active_name, active_content = "", args = {}, &block) ⇒ HTML
beginning tab; other tabs get loaded via ajax when selected
52 53 54 55 56 57 58 59 60 61 62 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 52 def lazy_loading_tabs tabs, active_name, active_content="", args={}, &block = "" tab_panes = "" standardize_tabs(tabs, active_name) do |tab_name, url, id, active_tab| += tab_name, id, url, active_tab tab_panes += lazy_tab_pane id, tab_name, active_tab, active_content, args[:pane_args], &block end tab_type = args.delete(:type) || "tabs" tab_panel , tab_panes, tab_type, args[:panel_args] end |
#lazy_tab_button(tab_name, id, url, active_tab) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 64 def tab_name, id, url, active_tab return wrap_with(:li, tab_name, role: "presentation") unless url ( "##{id}", tab_name, active_tab, "data-url" => url.html_safe, class: (active_tab ? nil : "load") ) end |
#lazy_tab_pane(id, tab_name, active_tab, active_content, args) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 73 def lazy_tab_pane id, tab_name, active_tab, active_content, args tab_content = if active_tab block_given? ? yield : active_content else "" end tab_pane(id, tab_name, tab_content, active_tab, args) end |
#standardize_tabs(tabs, active_name) ⇒ Object
83 84 85 86 87 88 89 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 83 def standardize_tabs tabs, active_name tabs.each do |tab_view_name, tab_details| tab_title, url = tab_title_and_url(tab_details, tab_view_name) active_tab = (active_name == tab_view_name) yield tab_title, url, tab_id(tab_view_name), active_tab end end |
#static_tabs(tabs, active_name = nil, tab_type = "tabs", args = {}) ⇒ HTML
beginning (default is the first)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 16 def static_tabs tabs, active_name=nil, tab_type="tabs", args={} = "" tab_panes = "" tabs.each do |tab_name, tab_content| active_name ||= tab_name active_tab = (tab_name == active_name) id = tab_id tab_name tab_content, = if tab_content.is_a?(Hash) [tab_content[:content], tab_content[:button_attr]] else [tab_content, {}] end += ("##{id}", tab_name, active_tab, ) tab_panes += tab_pane(id, tab_name, tab_content, active_tab, args[:pane]) end tab_panel , tab_panes, tab_type end |
#tab_button(target, text, active = false, link_attr = {}) ⇒ Object
117 118 119 120 121 122 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 117 def target, text, active=false, link_attr={} add_class link_attr, "active" if active link = target, text, link_attr li_args = { role: :presentation, class: "nav-item" } wrap_with :li, link, li_args end |
#tab_button_link(target, text, link_attr = {}) ⇒ Object
124 125 126 127 128 129 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 124 def target, text, link_attr={} add_class link_attr, "nav-link" link_to text, link_attr.merge( path: target, role: "tab", "data-toggle" => "tab" ) end |
#tab_id(tab_name) ⇒ Object
113 114 115 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 113 def tab_id tab_name "#{unique_id}-#{tab_name.to_name.safe_key}" end |
#tab_pane(id, tab_name, content, active = false, args = nil) ⇒ Object
131 132 133 134 135 136 137 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 131 def tab_pane id, tab_name, content, active=false, args=nil pane_args = { role: :tabpanel, id: id } pane_args.merge! args if args.present? add_class pane_args, "tab-pane tab-pane-#{tab_name.to_name.safe_key}" add_class pane_args, "active" if active wrap_with :div, content, pane_args end |
#tab_panel(tab_buttons, tab_panes, tab_type = "tabs", args = nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 100 def tab_panel , tab_panes, tab_type="tabs", args=nil args ||= {} add_class args, "tabbable" args.reverse_merge! role: "tabpanel" wrap_with :div, args do [ wrap_with(:ul, , class: "nav nav-#{tab_type}", role: "tablist"), wrap_with(:div, tab_panes, class: "tab-content") ] end end |
#tab_title_and_url(tab_details, tab_view_name) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/tabs.rb', line 91 def tab_title_and_url tab_details, tab_view_name if tab_details.is_a? Hash tab_details[:html] || [tab_details[:title], tab_details[:path] || path(tab_details[:view])] else [tab_details, path(view: tab_view_name)] end end |