Class: JqmHelper::NavBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper, JqmHelper
Defined in:
lib/jqm_helper/nav_builder.rb

Constant Summary collapse

ACTIVE_CLASS =
'ui-btn-active'

Instance Method Summary collapse

Methods included from JqmHelper

#back_button, #backward_button, #dialog_button, #forward_button, #jqm_button, #jqm_page, #make_options, #nav_for, #slider_tag

Constructor Details

#initialize(active_action = '') ⇒ NavBuilder

Returns a new instance of NavBuilder.



24
25
26
27
28
# File 'lib/jqm_helper/nav_builder.rb', line 24

def initialize(active_action = '')
  self.reverse_animation_direction = true
  @active_action = active_action.to_s
  # someday: we may be able to replace with rails current_page helper
end

Instance Method Details

#button(action, options, title = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jqm_helper/nav_builder.rb', line 30

def button(action, options, title = nil)

  if active = action.to_s == @active_action
    self.reverse_animation_direction = false
  end

  defaults = {
      :class => active ? ACTIVE_CLASS : '',
      :data => {
          :icon => action,
      }
  }

  # commented from trouble including named routes =/
  #defaults[:href] = method("#{action}_path").call unless options[:href] # incase method 404

  defaults[:data][:direction] = 'reverse' if self.reverse_animation_direction

  jqm_button(title || action.capitalize, '', make_options(defaults, options))
end