rails_bootstrap_easy_navbar 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_bootstrap_navbar_helper.gemspec
4
+ gemspec
5
+
6
+ gem "rails"
7
+ gem "rake"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mitchell Lane[DATACOM]
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # RailsBootstrapEasyNavbar
2
+
3
+ RailsBootstrapEasyNavbar is a Ruby on Rails gem for creating a simple navigation bar with twitter-bootstrap styling. It suits rapid prototyping as it can be setup within minutes.
4
+
5
+ Make sure you have the twitter bootstrap stylesheets and javascript files installed. They can be installed in anyway. Either via gems or raw stylesheets and javascript files. For easy installation check out these gems: 'bootstrap-sass' & 'twitter-bootstrap-rails'
6
+
7
+ The navigation bar may only be a maximum of two levels.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'rails_bootstrap_easy_navbar'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails_bootstrap_easy_navbar
22
+
23
+ ## Usage
24
+ With RailsBootstrapEasyNavbar you can create a bootstrap styled navbar with one method call containing your current page name and a JSON object.
25
+
26
+ From within a view create a navbar with:
27
+ <pre>
28
+ create_navbar(@current_page, @navbar_tabs)
29
+ </pre>
30
+ The current page variable is the title of the current tab in string format
31
+
32
+ The navbar_tabs JSON object is a hash of name, path pairs.
33
+
34
+ An example of a JSON object describing 3 main tabs:
35
+ <pre>
36
+ {
37
+ "Login" => login_path,
38
+ "Tasks" => tasks_path,
39
+ "Project" => projects_path
40
+ }
41
+ </pre>
42
+ To include subtabs simply create a key named after the main tab with a value of a hash describing each of the sub tabs. Only one level of subtabs is supported.
43
+
44
+ Here is an example of a JSON object describing 3 main tabs and 2 subtabs:
45
+ <pre>
46
+ {
47
+ "Login" => login_path,
48
+ "Tasks" => tasks_path,
49
+ "Project" => {
50
+ "Open Projects" => projects_open_path,
51
+ "Closed Projects" => projects_closed_path
52
+ }
53
+ }
54
+ </pre>
55
+ You can create a responsive collapsible navbar with:
56
+ <pre>
57
+ create_collapsible_navbar(@current_page, @navbar_tabs)
58
+ </pre>
59
+ ## Extension & Styling
60
+ The creation methods take an optional hash for styling and exending the navbar.
61
+
62
+ Add a brand to the navbar with:
63
+ <pre>
64
+ create_navbar(@current_page, @navbar_tabs, brand: "Website Title")
65
+ </pre>
66
+ Add a link for when the brand is clicked with:
67
+ <pre>
68
+ create_navbar(@current_page, @navbar_tabs, brand: "Website Title", brand_path: '/projects')
69
+ </pre>
70
+ Change the Navbar class (Check out http://twitter.github.com/bootstrap/components.html#navbar for different classes) :
71
+ <pre>
72
+ create_navbar(@current_page, @navbar_tabs, navbar_class: 'navbar navbar-inverse')
73
+ </pre>
74
+ Add raw html inside the non collapsible nav bar area:
75
+ <pre>
76
+ create_navbar(@current_page, @navbar_tabs, navbar_raw_html: @navbar_raw_html)
77
+ </pre>
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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
+ # 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]
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
33
+
34
+ #inject raw html if requested
35
+ contents << options[:navbar_raw_html] if options[:navbar_raw_html]
36
+
37
+ #create inner navbar
38
+ content_tag(:div, content_tag(:div, contents.join('').html_safe, class: 'container-fluid'), class: 'navbar-inner')
39
+ end
40
+
41
+ # Creates HTML for a list of clickable tabs
42
+ 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
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
@@ -0,0 +1,8 @@
1
+ require 'rails_bootstrap_easy_navbar/navbar_helper'
2
+ module RailsBootstrapEasyNavbar
3
+ class Railtie < Rails::Railtie
4
+ initializer "rails_bootstrap_easy_navbar.navbar_helper" do
5
+ ActionView::Base.send :include, NavbarHelper
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module RailsBootstrapEasyNavbar
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "rails_bootstrap_easy_navbar/version"
2
+ require 'rails_bootstrap_easy_navbar/railtie' if defined? (Rails)
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_bootstrap_easy_navbar/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rails_bootstrap_easy_navbar"
8
+ gem.version = RailsBootstrapEasyNavbar::VERSION
9
+ gem.authors = ["Mitchell Lane"]
10
+ gem.email = ["Mitchell.Lane52@gmail.com"]
11
+ gem.description = %q{With RailsBootstrapEasyNavbar you can create a simple navigation bar with twitter-bootstrap styling from a given JSON object. The navigation bar may only be a maximum of two levels.}
12
+ gem.summary = %q{With RailsBootstrapEasyNavbar you can create a simple navigation bar with twitter-bootstrap styling in only minutes.}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "rake"
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_bootstrap_easy_navbar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mitchell Lane
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: With RailsBootstrapEasyNavbar you can create a simple navigation bar
31
+ with twitter-bootstrap styling from a given JSON object. The navigation bar may
32
+ only be a maximum of two levels.
33
+ email:
34
+ - Mitchell.Lane52@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - .rspec
41
+ - Gemfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - lib/rails_bootstrap_easy_navbar.rb
46
+ - lib/rails_bootstrap_easy_navbar/navbar_helper.rb
47
+ - lib/rails_bootstrap_easy_navbar/railtie.rb
48
+ - lib/rails_bootstrap_easy_navbar/version.rb
49
+ - rails_bootstrap_easy_navbar.gemspec
50
+ homepage: ''
51
+ licenses:
52
+ - MIT
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: With RailsBootstrapEasyNavbar you can create a simple navigation bar with
75
+ twitter-bootstrap styling in only minutes.
76
+ test_files: []