GithubHelp home page GithubHelp logo

hrysd / buoys Goto Github PK

View Code? Open in Web Editor NEW

This project forked from muryoimpl/buoys

0.0 1.0 0.0 48 KB

A Ruby on Rails breadcrumb plugin.

License: MIT License

Ruby 79.80% Logos 0.79% HTML 15.91% JavaScript 1.63% CSS 1.87%

buoys's Introduction

Build Status

Buoys

Buoys is a Ruby on Rails breadcrumb plugin like gretel.

Motivation

I like gretel and respect its idea, but I want to create simpler breadcrumb library like gretel using I18n.

Installation

In your Gemfile

gem 'buoys'

And run:

$ bundle install

Example

Start by generating configuration and example files.

$ bin/rails g buoys:install
  create  config/locale/buoys.en.yml
  create  app/views/breadcrumbs/_buoys.html.erb
  create  config/buoys/breadcrumbs.rb

Then, in config/buoys/breadcrumbs.rb

buoy :stories do
  link 'Stories', stories_path
end

# 'crumb' is the alias of 'buoy'
# ex)
crumb :stories do
  link 'Stories', stories_path
end

# link's first argument, it is used as I18n key and defalt value.
# The key is searched in the scope of 'buoys.breadcrumbs'.
# ex)
buoy :story do |story|
  link :story, story_path(story)
  # same as `link I18n.t('story', scope: 'buoys.breadcrumbs', default: 'story'), story_path(story)`
end

# You can alse override Buoys configuration
# ex)
buoy :story_tasks do |story|
  link :story_tasks, story_tasks_path
  pre_buoy :story, story, {link_current: true}
end

# You can use 'pre_buoy' as parent. 'parent' is the alias of re_buoy`
# ex)
buoy :story_tasks do |story|
  link :story_tasks, story_tasks_path
  parent :story, story
end

Then, set the current buoy(breadcrumb) at the top of view file (like app/views/stories/index.html.erb).

<% buoy :stories %>

Then, in app/views/layouts/application.html.erb.

<%= render partial: 'breadcrumbs/buoys' %>

Then, You can build and change breadcrumb app/views/breadcrumbs/_buoys.html.erb

<% if buoys.any? %>
  <ul>
    <% buoys.each do |link| %>
      <li>
        <%# if 'link.current?' is true, link.options includes {class: 'current'}. %>
        <%= link_to link.url, link.options do %>
          <span><%= link.text %></span>
        <% end %>
        <% if !link.current? %>
          <span> &gt;</span>
        <% end %>
      </li>
    <% end %>
  </ul>
<% end %>

Options

option description default
:link_current whether current buoy(breadcrumb) should be linked to false
:current_class CSS class for current link. if you set nil, it is not set CSS class 'active'

Copyright (c) 2016 muryoimpl Released under the MIT license

buoys's People

Contributors

muryoimpl avatar

Watchers

 avatar

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.