rails_bootstrap_easy_navbar 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,12 +2,12 @@ module RailsBootstrapEasyNavbar
2
2
  module NavbarHelper
3
3
  DEFAULT_NAVBAR_CLASS = 'navbar'
4
4
  DEFAULT_BRAND_PATH = "/"
5
-
5
+
6
6
  def create_navbar(current_tab, nav_items, options={})
7
7
  options[:navbar_class] ||= DEFAULT_NAVBAR_CLASS
8
8
  content_tag(:div, navbar_inner(current_tab, nav_items, options), class: options[:navbar_class])
9
9
  end
10
-
10
+
11
11
  def create_collapsible_navbar(current_tab, nav_items, options={})
12
12
  options[:navbar_class] ||= DEFAULT_NAVBAR_CLASS
13
13
  options[:navbar_collapsible] = true
@@ -15,55 +15,57 @@ module RailsBootstrapEasyNavbar
15
15
  end
16
16
 
17
17
  private
18
- # Creates the navbar wrapper optionally containing a brand on the left hand side
19
- def navbar_inner(current_tab, nav_items, options={})
20
- #create responsive collapsible layout if requested
21
- contents = [
22
- content_tag(:a, (content_tag(:span, nil, class: "icon-bar")*3).html_safe, class: "btn btn-navbar", 'data-toggle' => "collapse", 'data-target' => '.nav-collapse'),
23
- content_tag(:div, content_tag(:ul, tabs(current_tab, nav_items), id: "tabs", class: "nav"), id: "navbar", class: 'nav-collapse collapse')
24
- ] if options[:navbar_collapsible]
25
- # skip responsive layout and create tabs if not requested
26
- contents = [content_tag(:ul, tabs(current_tab, nav_items), id: "tabs", class: "nav")] if !options[:navbar_collapsible]
18
+
19
+ # Creates the navbar wrapper optionally containing a brand on the left hand side
20
+ def navbar_inner(current_tab, nav_items, options={})
21
+ unless nav_items.blank?
22
+ #create responsive collapsible layout if requested
23
+ contents = [
24
+ content_tag(:a, (content_tag(:span, nil, class: "icon-bar")*3).html_safe, class: "btn btn-navbar", 'data-toggle' => "collapse", 'data-target' => '.nav-collapse'),
25
+ content_tag(:div, content_tag(:ul, tabs(current_tab, nav_items), id: "tabs", class: "nav"), id: "navbar", class: 'nav-collapse collapse')
26
+ ] if options[:navbar_collapsible]
27
27
 
28
- #create brand
29
- if options[:brand]
30
- options[:brand_path] ||= DEFAULT_BRAND_PATH
31
- contents.insert(0, (content_tag(:a, options[:brand], href: options[:brand_path], class: "brand")))
32
- end
28
+ # skip responsive layout and create tabs if not requested
29
+ contents = [content_tag(:ul, tabs(current_tab, nav_items), id: "tabs", class: "nav")] if !options[:navbar_collapsible]
30
+ end
33
31
 
34
- #inject raw html if requested
35
- contents << options[:navbar_raw_html] if options[:navbar_raw_html]
32
+ #create brand
33
+ if options[:brand]
34
+ options[:brand_path] ||= DEFAULT_BRAND_PATH
35
+ contents.insert(0, (content_tag(:a, options[:brand], href: options[:brand_path], class: "brand")))
36
+ end
36
37
 
37
- #create inner navbar
38
- content_tag(:div, content_tag(:div, contents.join('').html_safe, class: 'container-fluid'), class: 'navbar-inner')
39
- end
38
+ #inject raw html if requested
39
+ contents << options[:navbar_raw_html] if options[:navbar_raw_html]
40
40
 
41
- # Creates HTML for a list of clickable tabs
41
+ #create inner navbar
42
+ content_tag(:div, content_tag(:div, contents.join('').html_safe, class: 'container-fluid'), class: 'navbar-inner')
43
+ end
44
+
45
+ # Creates HTML for a list of clickable tabs
42
46
  def tabs(current_tab, nav_items)
43
- nav_items.map do |tab_name, path|
44
- # A Hash here means the tab is made up of multiple links -> dropdown
45
- if path.is_a? Hash
46
- content_tag(:li, drop_down_tab(tab_name, path), class: "dropdown")
47
- # construct and add a link to the list of tabs
48
- else
49
- args = [:li, (link_to tab_name, path)]
50
- args << {class: "active"} if tab_name == current_tab
51
- content_tag(*args)
52
- end
53
- end.join(separator).html_safe
47
+ nav_items.map do |tab_name, path|
48
+ if path.is_a? Hash # A Hash here means the tab is made up of multiple links -> dropdown
49
+ content_tag(:li, drop_down_tab(tab_name, path), class: "dropdown")
50
+ else # construct and add a link to the list of tabs
51
+ args = [:li, (link_to tab_name, path)]
52
+ args << {class: "active"} if tab_name == current_tab
53
+ content_tag(*args)
54
+ end
55
+ end.join(separator).html_safe
54
56
  end
55
57
 
56
58
  def separator
57
59
  content_tag(:li, nil, class: "divider-vertical")
58
60
  end
59
61
 
62
+ # Creates HTML for a dropdown list of clickable items
60
63
  def drop_down_tab(title, items)
61
64
  [content_tag(:a, dropdown_title(title), href: "#", class: "dropdown-toggle", 'data-toggle' => "dropdown"),
62
65
  content_tag(:ul, drop_down_links(items), class: "dropdown-menu")
63
66
  ].join("").html_safe
64
67
  end
65
68
 
66
-
67
69
  def drop_down_links(items)
68
70
  items.map do |tab_name, path|
69
71
  content_tag(:li, (link_to tab_name, path))
@@ -74,4 +76,4 @@ module RailsBootstrapEasyNavbar
74
76
  dropdown_title = (title + " "+content_tag(:b, nil, class: "caret")).html_safe
75
77
  end
76
78
  end
77
- end
79
+ end
@@ -0,0 +1,77 @@
1
+ module RailsBootstrapEasyNavbar
2
+ module NavbarHelper
3
+ DEFAULT_NAVBAR_CLASS = 'navbar'
4
+ DEFAULT_BRAND_PATH = "/"
5
+
6
+ def create_navbar(current_tab, nav_items, options={})
7
+ options[:navbar_class] ||= DEFAULT_NAVBAR_CLASS
8
+ content_tag(:div, navbar_inner(current_tab, nav_items, options), class: options[:navbar_class])
9
+ end
10
+
11
+ def create_collapsible_navbar(current_tab, nav_items, options={})
12
+ options[:navbar_class] ||= DEFAULT_NAVBAR_CLASS
13
+ options[:navbar_collapsible] = true
14
+ content_tag(:div, navbar_inner(current_tab, nav_items, options), class: options[:navbar_class])
15
+ end
16
+
17
+ private
18
+
19
+ # Creates the navbar wrapper optionally containing a brand on the left hand side
20
+ def navbar_inner(current_tab, nav_items, options={})
21
+ #create responsive collapsible layout if requested
22
+ contents = [
23
+ content_tag(:a, (content_tag(:span, nil, class: "icon-bar")*3).html_safe, class: "btn btn-navbar", 'data-toggle' => "collapse", 'data-target' => '.nav-collapse'),
24
+ content_tag(:div, content_tag(:ul, tabs(current_tab, nav_items), id: "tabs", class: "nav"), id: "navbar", class: 'nav-collapse collapse')
25
+ ] if options[:navbar_collapsible]
26
+
27
+ # skip responsive layout and create tabs if not requested
28
+ contents = [content_tag(:ul, tabs(current_tab, nav_items), id: "tabs", class: "nav")] if !options[:navbar_collapsible]
29
+
30
+ #create brand
31
+ if options[:brand]
32
+ options[:brand_path] ||= DEFAULT_BRAND_PATH
33
+ contents.insert(0, (content_tag(:a, options[:brand], href: options[:brand_path], class: "brand")))
34
+ end
35
+
36
+ #inject raw html if requested
37
+ contents << options[:navbar_raw_html] if options[:navbar_raw_html]
38
+
39
+ #create inner navbar
40
+ content_tag(:div, content_tag(:div, contents.join('').html_safe, class: 'container-fluid'), class: 'navbar-inner')
41
+ end
42
+
43
+ # Creates HTML for a list of clickable tabs
44
+ def tabs(current_tab, nav_items)
45
+ nav_items.map do |tab_name, path|
46
+ if path.is_a? Hash # A Hash here means the tab is made up of multiple links -> dropdown
47
+ content_tag(:li, drop_down_tab(tab_name, path), class: "dropdown")
48
+ else # construct and add a link to the list of tabs
49
+ args = [:li, (link_to tab_name, path)]
50
+ args << {class: "active"} if tab_name == current_tab
51
+ content_tag(*args)
52
+ end
53
+ end.join(separator).html_safe
54
+ end
55
+
56
+ def separator
57
+ content_tag(:li, nil, class: "divider-vertical")
58
+ end
59
+
60
+ def drop_down_tab(title, items)
61
+ [content_tag(:a, dropdown_title(title), href: "#", class: "dropdown-toggle", 'data-toggle' => "dropdown"),
62
+ content_tag(:ul, drop_down_links(items), class: "dropdown-menu")
63
+ ].join("").html_safe
64
+ end
65
+
66
+
67
+ def drop_down_links(items)
68
+ items.map do |tab_name, path|
69
+ content_tag(:li, (link_to tab_name, path))
70
+ end.join("").html_safe
71
+ end
72
+
73
+ def dropdown_title(title)
74
+ dropdown_title = (title + " "+content_tag(:b, nil, class: "caret")).html_safe
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapEasyNavbar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_easy_navbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -44,6 +44,7 @@ files:
44
44
  - Rakefile
45
45
  - lib/rails_bootstrap_easy_navbar.rb
46
46
  - lib/rails_bootstrap_easy_navbar/navbar_helper.rb
47
+ - lib/rails_bootstrap_easy_navbar/navbar_helper.rb~
47
48
  - lib/rails_bootstrap_easy_navbar/railtie.rb
48
49
  - lib/rails_bootstrap_easy_navbar/version.rb
49
50
  - rails_bootstrap_easy_navbar.gemspec