Module: NavbarHelper

Includes:
ActionView::Helpers, FormatHelper
Defined in:
app/helpers/navbar_helper.rb

Instance Method Summary collapse

Methods included from FormatHelper

#parse_content_or_options, #prepend_class, #squeeze_n_strip

Instance Method Details

#horizontal(options = {}, &block) ⇒ Object



36
37
38
39
40
# File 'app/helpers/navbar_helper.rb', line 36

def horizontal(options={}, &block)
  prepend_class(options, 'collapse navbar-collapse')

   :div, options, &block
end

TODO: add navbar form support



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/navbar_helper.rb', line 6

def navbar(options={}, &block)
  style                    = options.delete(:inverse).presence ? 'navbar navbar-inverse' : 'navbar navbar-default'
  container                = options.delete(:fluid).presence ? 'container-fluid' : 'container'
  padding                  = options.delete(:padding).presence || '70px'
  position, position_style = parse_position(options.delete(:position), padding)

  prepend_class(options, style, position)
  options.deep_merge!(data: {bui: 'navbar'})

  (position_style + ( :nav, options do
     :div, class: container, &block
  end)).html_safe
end


84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/navbar_helper.rb', line 84

def navbar_brand(name = nil, options = nil, html_options = nil, &block)
  html_options, options, name = options, name, block if block_given?
  options                     ||= {}
  html_options                ||= {}

  prepend_class(html_options, 'navbar-brand')

  link_to options, html_options do
    block_given? ? (yield name) : name
  end
end


96
97
98
# File 'app/helpers/navbar_helper.rb', line 96

def navbar_dropdown(content=nil, list=[], options={})
  dropdown(content, list, options.merge({category: :navbar}))
end


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/navbar_helper.rb', line 68

def navbar_link(name = nil, options = nil, html_options = nil, &block)
  html_options, options, name = options, name, block if block_given?
  options      ||= {}
  html_options ||= {}

  prepend_class(html_options, 'navbar-link')
  active = 'active' if html_options.delete(:active)


   :li, class: active do
    link_to options, html_options do
      block_given? ? (yield name) : name
    end
  end
end


56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/navbar_helper.rb', line 56

def navbar_link_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options, name = options, name, block if block_given?
  options      ||= {}
  html_options ||= {}

  prepend_class(html_options, 'navbar-link')

  link_to options, html_options do
    block_given? ? (yield name) : name
  end
end


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/navbar_helper.rb', line 42

def navbar_menu(options={}, &block)
  style = case options.delete(:position).try(:to_sym)
          when :right
            'nav navbar-nav navbar-right'
          when :left
            'nav navbar-nav navbar-left'
          else
            'nav navbar-nav'
          end

  prepend_class(options, style)
   :ul, options, &block
end

#vertical(options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/navbar_helper.rb', line 20

def vertical(options={}, &block)
  prepend_class(options, 'navbar-header')

  btn_content = ("<span class='icon-bar'></span>" * 3).html_safe
  btn_options = {
    class: 'navbar-toggle collapsed',
    type:  :button,
    data:  {toggle: 'collapse'},
    aria:  {expanded: false}
  }

   :div, options do
    ( :button, btn_content, btn_options) + capture(&block)
  end
end