Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 2d3c62072a8883510c5ffed01d42c9aa15dd9273 @manuelmeurer manuelmeurer committed Jul 13, 2013
@@ -0,0 +1,7 @@
+language: ruby
+rvm:
+ - 1.9.2
+ - 1.9.3
+ - 2.0.0
+ - jruby-19mode
+ - rbx-19mode
@@ -0,0 +1,3 @@
+source 'https://rubygems.org/'
+
+gemspec
@@ -0,0 +1,9 @@
+guard 'rspec', cli: '--drb --profile', all_after_pass: false do
+ # Specs
+ watch(%r(^spec/.+_spec\.rb$))
+ watch('spec/spec_helper.rb') { 'spec' }
+ watch(%r(^spec/support/(.+)\.rb$)) { 'spec' }
+
+ # Files
+ watch(%r(^lib/(.+)\.rb$)) { |m| "spec/#{m[1]}_spec.rb" }
+end
@@ -0,0 +1,22 @@
+Copyright (c) 2013 kraut computing UG (haftungsbeschränkt)
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
+# BootstrapNavbar
+
+[![Gem Version](https://badge.fury.io/rb/bootstrap_navbar.png)](http://badge.fury.io/rb/bootstrap_navbar)
+[![Build Status](https://secure.travis-ci.org/krautcomputing/bootstrap_navbar.png)](http://travis-ci.org/krautcomputing/bootstrap_navbar)
+[![Dependency Status](https://gemnasium.com/krautcomputing/bootstrap_navbar.png)](https://gemnasium.com/krautcomputing/bootstrap_navbar)
+[![Code Climate](https://codeclimate.com/github/krautcomputing/bootstrap_navbar.png)](https://codeclimate.com/github/krautcomputing/bootstrap_navbar)
+
+Helpers to generate a Twitter Bootstrap style navbar
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'bootstrap_navbar'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install bootstrap_navbar
+
+## Usage
+
+### Set current_url_method
+
+BootstrapNavbar has to be able to query for the current URL, e.g. to determine if a menu item is active or not. Since the way the current URL is determined varies depending on whether you use Rails, Sinatra etc., this has to be set beforehand in some kind of initializer:
+
+```ruby
+# For Rails
+BootstrapNavbar.current_url_method = -> { '' }
+```
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1,5 @@
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task default: :spec
@@ -0,0 +1,28 @@
+# encoding: utf-8
+
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+
+require 'bootstrap_navbar/version'
+
+Gem::Specification.new do |gem|
+ gem.name = 'bootstrap_navbar'
+ gem.version = BootstrapNavbar::VERSION
+ gem.platform = Gem::Platform::RUBY
+ gem.authors = ['Manuel Meurer']
+ gem.email = 'manuel.meurer@gmail.com'
+ gem.summary = 'Helpers to generate a Twitter Bootstrap style navbar'
+ gem.description = 'Helpers to generate a Twitter Bootstrap style navbar'
+ gem.homepage = 'https://github.com/krautcomputing/bootstrap_navbar'
+ gem.license = 'MIT'
+
+ gem.files = `git ls-files`.split($/)
+ gem.executables = gem.files.grep(%r(^bin/)).map { |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r(^(test|spec|features)/))
+ gem.require_paths = ['lib']
+
+ gem.add_development_dependency 'rake', '>= 10.0.0'
+ gem.add_development_dependency 'rspec', '~> 2.13.0'
+ gem.add_development_dependency 'rspec-html-matchers', '~> 0.4.1'
+ gem.add_development_dependency 'guard-rspec', '~> 3.0'
+end
@@ -0,0 +1,14 @@
+require 'bootstrap_navbar/version'
+
+module BootstrapNavbar
+ def self.current_url_method=(value)
+ raise StandardError, '`current_url_method` must be an object that responds to `#call`' unless value.respond_to?(:call)
+ @current_url_method = value
+ end
+
+ def self.current_url_method
+ @current_url_method
+ end
+end
+
+require 'bootstrap_navbar/helpers'
@@ -0,0 +1,143 @@
+module BootstrapNavbar::Helpers
+ def nav_bar(options = {}, &block)
+ nav_bar_div options do
+ navbar_inner_div do
+ container_div options[:brand], options[:brand_link], options[:responsive], options[:fluid], &block
+ end
+ end
+ end
+
+ def menu_group(pull = nil, &block)
+ css_classes = %w(nav).tap do |css_classes|
+ css_classes << "pull-#{pull}" if pull
+ end
+ <<-HTML
+<ul class="#{css_classes.join(' ')}">
+ #{block.call if block_given?}
+</ul>
+HTML
+ end
+
+ def menu_item(name, path = '#', options = {})
+ css_class = path.sub(%r(/\z), '') == current_url.sub(%r(/\z), '') ? 'active' : nil
+ options_string = options.map { |k, v| %(#{k}="#{v}") }
+ <<-HTML
+<li class="#{css_class}">
+ <a href="#{path}" #{options_string}>
+ #{name}
+ </a>
+</li>
+HTML
+ end
+
+ def drop_down(name, &block)
+ <<-HTML
+<li class="dropdown">
+ <a href="#" class="dropdown-toggle", data-toggle="dropdown">
+ #{name} <b class="caret"></b>
+ </a>
+ <ul class="dropdown-menu">
+ #{block.call if block_given?}
+ </ul>
+</li>
+HTML
+ end
+
+ def drop_down_divider
+ %(<li class="divider"></li>)
+ end
+
+ def drop_down_header(text)
+ %(<li class="nav-header">#{text}</li>)
+ end
+
+ def menu_divider
+ %(<li class="divider-vertical"></li>)
+ end
+
+ def menu_text(text = nil, pull = nil, &block)
+ css_classes = %w(navbar-text).tap do |css_classes|
+ css_classes << "pull-#{pull}" if pull
+ end
+ <<-HTML
+<p class="#{css_classes.join(' ')}">
+ #{block_given? ? block.call : text}
+</p>
+HTML
+ end
+
+ def brand_link(name, url = nil)
+ %(<a href="#{url || '/'}" class="brand">#{name}</a>)
+ end
+
+ private
+
+ def nav_bar_div(options, &block)
+ position = case
+ when options.has_key?(:static)
+ "static-#{options[:static]}"
+ when options.has_key?(:fixed)
+ "fixed-#{options[:fixed]}"
+ end
+
+ css_classes = %w(navbar).tap do |css_classes|
+ css_classes << "navbar-#{position}" if position
+ css_classes << 'navbar-inverse' if options[:inverse]
+ end
+
+ <<-HTML
+<div class="#{css_classes.join(' ')}">
+ #{block.call if block_given?}
+</div>
+HTML
+ end
+
+ def navbar_inner_div(&block)
+ <<-HTML
+<div class="navbar-inner">
+ #{block.call if block_given?}
+</div>
+HTML
+ end
+
+ def container_div(brand, brand_link, responsive, fluid, &block)
+ css_class = fluid ? 'container-fluid' : 'container'
+ content = [].tap do |content|
+ content << responsive_button if responsive
+ content << brand_link(brand, brand_link) if brand || brand_link
+ content << if responsive
+ responsive_wrapper(&block)
+ else
+ block.call if block_given?
+ end
+ end
+ <<-HTML
+<div class="#{css_class}">
+ #{content.join("\n")}
+</div>
+HTML
+ end
+
+ def responsive_wrapper(&block)
+ <<-HTML
+<div class="nav-collapse collapse">
+ #{block.call if block_given?}
+</div>
+HTML
+ end
+
+ def responsive_button
+ <<-HTML
+<a class="btn btn-navbar", data-toggle="collapse" data-target=".nav-collapse">
+ <span class='icon-bar'></span>
+ <span class='icon-bar'></span>
+ <span class='icon-bar'></span>
+</div>
+HTML
+ end
+
+ def current_url
+ raise StandardError, 'current_url_method is not defined.' if BootstrapNavbar.current_url_method.nil?
+ BootstrapNavbar.current_url_method.call
+ end
+end
@@ -0,0 +1,3 @@
+module BootstrapNavbar
+ VERSION = '0.0.1'
+end
Oops, something went wrong.

0 comments on commit 2d3c620

Please sign in to comment.