Giter Site home page Giter Site logo

simple_navigation_bootstrap's Introduction

SimpleNavigation Bootstrap

GitHub license GitHub release Gem Gem CI Code Climate Test Coverage

This gem adds Bootstrap renderers for Simple Navigation. For now, it is include renderers for:

With these renderers you will be able create any Bootstrap navigation elements, such as: submenu, navbar-text, divider, header. As well as add icons to menu elements, such as: Glyphicons, Font Awesome icons, even custom icons. Also you have split option for main menu containing submenu.

This gem is a fork of ShPakvel/simple_navigation_renderers. After a year of waiting for PR merge without any news from the author, I decided to fork it.

This gem is compatible with SimpleNavigation 4.x.

Installation

Add this line to your application's Gemfile:

gem 'simple_navigation_bootstrap'

and then execute:

$ bundle install

Or install it yourself as:

$ gem install simple_navigation_bootstrap

Usage

Simply set up renderer and you are done!!

There are two ways to say that you want to use any of renderers.

  1. You can specify it in you view as a parameter to render_navigation:

    ...
      <%= render_navigation(expand_all: true, renderer: :bootstrap2) %>
      # Or
      <%= render_navigation(expand_all: true, renderer: :bootstrap3) %>
    ...
  2. Or you can set it in the very navigation configuration file (e.g. config/navigation.rb):

    SimpleNavigation::Configuration.run do |navigation|
      navigation.renderer = SimpleNavigationBootstrap::Bootstrap2
      # or
      navigation.renderer = SimpleNavigationBootstrap::Bootstrap3
      # navigation itself goes here...
    end

Explicit example of using all features

I think you already using simple-navigation gem and know how to define navigation items. If not, you can always look at the configuration instructions on the Simple Navigation wiki or read comments and examples in the generated by default config/navigation.rb file.

In addition to standard options you can use ones specific for Bootstrap renderers. Lets look at the example:

SimpleNavigation::Configuration.run do |navigation|
  navigation.renderer = SimpleNavigationBootstrap::Bootstrap3

  navigation.items do |primary|
    primary.item :news, { icon: 'fa fa-fw fa-bullhorn', text: 'News' }, news_index_path
    primary.item :concerts, 'Concerts', concerts_path
    primary.item :video, 'Video', videos_path
    primary.item :divider_before_info, '#', divider: true
    primary.item :info, { icon: 'fa fa-fw fa-book', title: 'Info' }, info_index_path, split: true do |info_nav|
      info_nav.item :main_info_page, 'Main info page', info_path(:main_info_page)
      info_nav.item :about_info_page, 'About', info_path(:about_info_page)
      info_nav.item :misc_info_pages, 'Misc.' do |misc_page|
        misc_page.item :header_misc_pages, 'Misc. Pages', header: true
        Info.all.each do |info_page|
          misc_page.item :"#{info_page.permalink}", info_page.title, info_path(info_page)
        end
      end
      info_nav.item :divider_before_contact_info_page, '#', divider: true
      info_nav.item :contact_info_page, 'Contact', info_path(:contact_info_page)
    end
    primary.item :signed_in, 'Signed in as Pavel Shpak', navbar_text: true
  end
end

Features

Specific options used in the example:

Option Description
:split Use it to split first level item link with caret. If you add split: true option to item, then caret itself will toggle first level submenu and link will have standard behaviour, instead of toggle submenu. You can use :split only with first level items, for the rest it will not do anything.
:navbar_text Use it as navbar_text: true to add Bootstrap navbar-text.
:divider Use it to add Bootstrap menu divider. if you add divider: true option to first level item, then it will create li-tag with divider-vertical Bootstrap 2 class. (You can add divider-vertical class to Bootstrap 3 - see below). For the second level item and deeper it will create li tag with class divider (which exists in both, Bootstrap 2 and 3).
:header Use it as header: true to add Bootstrap menu header. You can use :header only with submenus, for the first level items it will not do anything.
:name hash Use it in place of :name if you want. Hash can have three keys: :text, :icon and :title, which is only recognized. You can use it together or separately, but at least one of :text and :icon parameters should be provided.

Example for :name hash:

  • { text: 'News', icon: 'fa fa-fw fa-bullhorn' } will create Font Awesome icon and add text after it (name of the item)
  • { icon: 'glyphicon glyphicon-book', title: 'Info' } will create Bootstrap icon with title without any text after it

Notes

  1. Bootstrap 3 has only one level submenu. If you want to use nested submenus as in example above, import bootstrap2_dropdown_submenu.css.scss file into your Sass file (e.g. application.css.scss) as following:

    @import "bootstrap2_dropdown_submenu";
  2. Bootstrap 3 has not divider-vertical class. If you want to use it as in example above, import bootstrap2_navbar_divider_vertical.css.scss file:

    @import "bootstrap2_navbar_divider_vertical";
  3. You may also want to include following file which changes some first level submenu style:

    @import "simple_navigation_bootstrap_overrides";
  4. or you can add them all together:

    @import "simple_navigation_bootstrap";

Test

Just run following commands:

$ bundle install
$ rake

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

Contributors

A big thank to them for their contribution!

simple_navigation_bootstrap's People

Contributors

gregt-home avatar n-rodriguez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simple_navigation_bootstrap's Issues

Options specified in a nav item are being lost upon rendering

Thanks for developing this package. A similar package, simple-navigation-bootstrap is looking for a maintainer. You should consider taking it over. Your code seems better organized.

I am running into a problem where options, like icon: [fa fa-ticket] to disappear when our app uses this package. That means code like this:

    primary.item :ticket,
      "Ticket",
      url_for('//mycompany/ticket'),
      link_html: { target: '_blank' },
      icon: ['fa fa-ticket'],
      if: -> { can? :create, Ticket }

Now appears to ignore the icon: ['fa fa-ticket'] option. That snippet used to render as a small ticket icon followed by the word "Ticket" now renders as just "Ticket" with no icon. No CSS for the icon is present in the view.

I am investigating the problem, but cannot promise I will be able to deliver a fix.

Bootstrap4 Renderer not registering

For some reason I haven't been able to find, the Bootstrap4 renderer is not registering in my app. To try and figure this out, I added a test for the renderer registers for Bootstrap4 and got the same:

"Uninitialized constant "SimpleNavigationBootstrap::Bootstrap4"

I have tried my best to figure out why the Boostrap4 renderer isn't registering but no luck so far. I'm sure I'm overlooking something simple and will keep trying but thought I'd go ahead and report it.

Navigation does not render correctly when using `level: 2`

I'm splitting my navigation into two seperate divs. One at the top and one as a sidebar.
simple-navigation provides a :level setting to archive this functionality (docs)

Using the Bootstrap3 renderer, the second menu is hidden (display: none;) as it is rendered like a dropdown menu.

View:

= render_navigation expand_all: true, level: 2

Navigation settings:

navigation.renderer = SimpleNavigationBootstrap::Bootstrap3
navigation.items do |primary|
    primary.item :main, 'Main', main_url do |sub_nav|
      sub_nav.item :sub, 'Sub', sub_url
    end
end

Level 2 should be rendered like level 1, level 3 like level 2 and so on.

Must click primary nav item twice to see secondary menu

I am trying to move our app away from the simple-navigation-bootstrap gem to this one and have managed to get everything working, but I have one problem: when I click on a primary item in the nav bar, I need to click it a second time to see the menu.

Is this expected behavior? Is there a way to configure it to display the menu on the first click?

Seeing Rails.logger.info messages with '#prepare_name' in development log

We use this gem in our production app and recently I noticed that every time the nav bar gets rendered a series of log messages of the form:

------------ #prepare_name: {:text=>"Inventory", :icon=>"fa fa-cube"}
------------ and is a Hash
------------ content_tag: <i class="fa fa-cube"></i> Inventory
------------ #prepare_name: Movements
------------ #prepare_name: Movements
...

I don't see this statement in the repo, but I did find it in the installed gem:

$ ack '#prepare_name'
.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/simple_navigation_bootstrap-1.0.1/lib/simple_navigation_bootstrap/bootstrap_base.rb
70:        Rails.logger.info "------------ #prepare_name: #{name}"

I am assuming it is debugging code that somehow escaped into the wild?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.