Module: TabHelper
- Defined in:
- lib/cd2_tabs/tab_helper.rb
Instance Method Summary collapse
- #tab(control_name, *args, &block) ⇒ Object
- #tab_controller(control_name, checked = nil) ⇒ Object
- #tab_head(control_name, text = nil) ⇒ Object
- #tabs(group_name = nil, &block) ⇒ Object
Instance Method Details
#tab(control_name, *args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cd2_tabs/tab_helper.rb', line 15 def tab control_name, *args, &block opts = args. tab_name = opts.delete(:tab_head) { args[0] } checked = opts.delete(:checked) { args[1] } condition = opts.delete(:if) { args[2] } return if condition.present? && condition.call==false if checked.nil? && !!tab_name==tab_name checked, tab_name = tab_name, nil end tab_controller control_name, checked tab_head control_name, tab_name opts[:class] ||= [] opts[:class] = [opts[:class]].flatten(1) opts[:class].push('tab_panel') content = capture(&block) if block content_for "tab_panels_#{@tab_group_name.last}", content_tag(:div, content, opts) end |
#tab_controller(control_name, checked = nil) ⇒ Object
3 4 5 6 7 |
# File 'lib/cd2_tabs/tab_helper.rb', line 3 def tab_controller control_name, checked=nil checked ||= true if !content_for?("tab_controllers_#{@tab_group_name.last}") content = ("tab_#{@tab_group_name.last}", control_name, (checked || params[:tab]==control_name.to_s), class: 'tab_controller') content_for "tab_controllers_#{@tab_group_name.last}", content end |
#tab_head(control_name, text = nil) ⇒ Object
10 11 12 13 |
# File 'lib/cd2_tabs/tab_helper.rb', line 10 def tab_head control_name, text=nil text ||= control_name.to_s.humanize content_for "tab_heads_#{@tab_group_name.last}", label_tag("tab_#{@tab_group_name.last}_#{control_name}", text, class: control_name) end |
#tabs(group_name = nil, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cd2_tabs/tab_helper.rb', line 39 def tabs group_name=nil, &block @tab_group_name ||= [] @tab_group_name.push group_name || rand content = capture &block if block tab_controllers = @view_flow.content.delete "tab_controllers_#{@tab_group_name.last}" tab_heads = @view_flow.content.delete "tab_heads_#{@tab_group_name.last}" tab_panels = @view_flow.content.delete "tab_panels_#{@tab_group_name.last}" @tab_group_name.pop return unless tab_controllers content_tag :div, class: 'tabs_container' do tab_controllers + content_tag(:div, tab_heads, class: 'tab_heads_container') + content_tag(:div, tab_panels, class: 'tab_panels_container') end end |