Class: Tungsten::ToggleNavHelper::ToggleNav
- Defined in:
- app/helpers/tungsten/toggle_nav_helper.rb
Direct Known Subclasses
Instance Method Summary collapse
- #display(body) ⇒ Object
- #display_tag(tag, options, body) ⇒ Object
-
#initialize(tag = :div, options = {}) ⇒ ToggleNav
constructor
A new instance of ToggleNav.
- #option(label = nil, options = {}, &block) ⇒ Object
- #set_toggle_options(options) ⇒ Object
Constructor Details
#initialize(tag = :div, options = {}) ⇒ ToggleNav
Returns a new instance of ToggleNav.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/tungsten/toggle_nav_helper.rb', line 5 def initialize(tag = :div, = {}) if tag.is_a? Hash = tag tag = :div end [:tag] = tag @options = @options[:name] ||= "radio-group-#{rand(10000)}-#{rand(10000)}" @count = 0 end |
Instance Method Details
#display(body) ⇒ Object
31 32 33 34 35 36 |
# File 'app/helpers/tungsten/toggle_nav_helper.rb', line 31 def display(body) = @options .delete(:name) display_tag .delete(:tag), , body end |
#display_tag(tag, options, body) ⇒ Object
38 39 40 41 42 |
# File 'app/helpers/tungsten/toggle_nav_helper.rb', line 38 def display_tag(tag, , body ) [:class] = "toggle-nav #{@options[:class]}" [:class] << " #{[:type]}" if [:type] content_tag(tag, ) { body } end |
#option(label = nil, options = {}, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/tungsten/toggle_nav_helper.rb', line 44 def option(label = nil, = {}, &block) if label.is_a? Hash = label label = .delete(:label) end checked = .delete(:checked) || false name = .delete(:name) || @options[:name] label_text = content_tag(:span, class: 'label-text') { label } if label label_class = "#{.delete(:class)} toggle-nav-label" label_id = "#{name}_#{@count += 1}" # The label should have an active class # when the radio is active [:add_class] = "active; ##{label_id}& #{[:add_clss]}" = () content_tag(:label, class: label_class, id: label_id ) { concat (name, true, checked, ) concat capture(&block).html_safe if block_given? concat label_text } end |
#set_toggle_options(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/tungsten/toggle_nav_helper.rb', line 19 def ( ) [:data] ||= {} [:data] = [:data].merge({ show: .delete(:show), hide: .delete(:hide), add_class: .delete(:add_class), remove_class: .delete(:remove_class) }) end |