Giter Site home page Giter Site logo

zachinglis / crummy Goto Github PK

View Code? Open in Web Editor NEW
359.0 7.0 84.0 182 KB

Tasty breadcrumbs! Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.

Home Page: http://zachinglis.com

License: MIT License

Shell 7.38% Ruby 83.64% JavaScript 0.83% CoffeeScript 0.82% CSS 0.63% HTML 3.90% Sass 0.66% SCSS 0.31% Haml 1.82%

crummy's Introduction

Warning This is no longer maintained and hasn't been for quite some time. I no longer spend any time in the Ruby world. If you would like to maintain it, do reach out and ask.

Crummy

Gem Version Build Status Code Climate

Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.

Install

Simply add the dependency to your Gemfile:

gem "crummy", "~> 1.8.0"

Example

In your controllers you may add_crumb either like a before_filter or within a method (It is also available to views).

class ApplicationController
  add_crumb "Home", '/'
end

class BusinessController < ApplicationController
  add_crumb("Businesses") { |instance| instance.send :businesses_path }
  add_crumb("Comments", only: "comments") { |instance| instance.send :businesses_comments_path }
  before_filter :load_comment, only: "show"
  add_crumb :comment, only: "show"

  # Example for nested routes:
  add_crumb(:document) { [:account, :document] }

  def show
    add_crumb @business.display_name, @business
  end

  def load_comment
    @comment = Comment.find(params[:id])
  end
end

Then in your view:

<%= render_crumbs %>

Html options for breadcrumb link

You can set the html options with link_html_options. These are added to the a tag.

add_crumb "Home", '/', link_html_options: {title: "my link title"}

##You can set html instead text in first parameter. If tag a present in this html, tag a not be a wrapper.

add_crumb "<a class='glyphicons shield' href='/support'><i></i>Support</a>".html_safe, "", {}

Options for render_crumbs

render_crumbs renders the list of crumbs as either html or xml

The output format. Can either be :xml or :html or :html_list. Defaults to :html

format: (:html|:html_list|:xml)

The separator text. It does not assume you want spaces on either side so you must specify. Defaults to &raquo; for :html and <crumb> for :xml

separator: string

Render links in the output. Defaults to true

links: false

Render Richsnipet Default to false

microdata: true

Optionally disable linking of the last crumb, Defaults to true

last_crumb_linked: false

With this option, output will be blank if there are no breadcrumbs.

skip_if_blank: true

Examples

render_crumbs                     #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
render_crumbs separator: ' | '    #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
render_crumbs format: :xml        #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
render_crumbs format: :html_list  #=> <ol class="" id=""><li class=""><a href="/">Home</a></li><li class=""><a href="/">Businesses</a></li></ol>
render_crumbs format: :html_list, :microdata => true
                                  #=> <ol class="" id=""><li class="" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
                                  #     <a href="/" itemprop="url"><span itemprop="title">Home</span></a></li></ol>
add_crumb support_link, {:right_side => true, :links => "/support", :li_right_class => "pull-right hidden-phone"}
                                  #=> <li class="pull-right hidden-phone">
                                  #=>  <span><a class="glyphicons shield" href="/support">
                                  #=>   <i></i>Support</a>
                                  #=>  </span>
                                  #=> </li>
                                  #=> <li class="divider pull-right hidden-phone"></li>

A crumb with a nil argument for the link will output an unlinked crumb.

With format: :html_list you can specify additional params: :li_class, :ol_class, :ol_id

App-wide configuration

You have the option to pre-configure any of the Crummy options in an application-wide configuration. The options above are available to configure, with the exception of :separator, as well as many others.

The biggest difference is that :separator is not an option. Instead, you have format-specific configuration options: :html_separator, :xml_separator, and :html_list_separator. :separator can still be overridden in the view.

Insert the following in a file named config/initializers/crummy.rb:

Crummy.configure do |config|
  config.format = :xml
end

Possible parameters for configuration are:

:format
:links
:skip_if_blank
:html_separator
:xml_separator
:html_list_separator
:html_list_right_separator
:first_class
:last_class
:ol_id
:ol_class
:li_class
:li_right_class
:microdata
:last_crumb_linked
:truncate
:right_side

See lib/crummy.rb for a list of these parameters and their defaults.

###Individually for each crumb configuration:

add_crumb support_link, {:right_side => true, :links => "/support", : li_class => "my_class", :li_right_class => "pull-right hidden-phone"}

Simple add that parameter to options hash.

Live example application

An example application is available right inside this gem. That application is documented, see example/README for details about usage.

Todo

  • Accept collections of models as a single argument
  • Accept instances of models as a single argument
  • Allow for variables in names. (The workaround is to do your own before_filter for that currently)
  • Make a crumbs? type method

Credits

Copyright 2008-2013 Zach Inglis, released under the MIT license

crummy's People

Contributors

acrogenesis avatar adam-pl avatar andrew avatar bcobb avatar bhushangahire avatar billturner avatar bjeanes avatar bobbus avatar bsa7 avatar fotos avatar galfert avatar gonzalo-bulnes avatar gui avatar jasiek avatar jbrowning avatar johnmichaelbradley avatar kavu avatar kirs avatar kml avatar leshill avatar libkazz avatar michaek avatar mnaser avatar sanemat avatar sjain avatar sugilog avatar tanordheim avatar zachinglis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

crummy's Issues

html_list_separator is never used

I see the html_list_separator option in the README but cannot find where and how it's supposed to be used in the code.

Is it a work in progress ?
I'm trying to make crummy work with the twitter bootstrap and the separator seems to take place after the link, in a span.

Reversed breadcrumb.

I have a tree of categories. When I'm in the x level category the easiet way to build breadcrumb is to
create method that will add_crumb for given category and invoke it again with parent category.
This result with root category placed on the end of breadcrumb. Is there an option to reverse it while rendering?

Finding the route automatically not working for one.

Someone reported that add_crumb @foo.title, @foo is not working for people due to the @foo not automatically resolving to the correct URL.

The error was: 'undefined methodfoo_path' for #<Crummy::StandardRenderer:0x000001037ef640 @_routes=nil>'`

Manually entering it works.

Some translations do not work in add_crumb

Strange problem with translation in add_crumb.

FAIL:

add_crumb(I18n.t('my_profile'), :travels_path)

`@Mi perfil' is not allowed as an instance variable name

crummy (1.3) lib/crummy/action_controller.rb:32:in `instance_variable_get'
crummy (1.3) lib/crummy/action_controller.rb:32:in `block in add_crumb'
activesupport (3.1.1) lib/active_support/callbacks.rb:448:in     `_run__124730010797531319__process_action__4462420772137569113__callbacks'

but with other string with translation it hasn't problem:

add_crumb(I18n.t('other_translation_that_works_too'), :travels_path)

Calling Html_Safe By Default

In standard_renderer.rb, html_safe is invoked by default .

Shouldn't this be up to the user to mark which strings are html safe?

Example:

add_crumb "safe".html_safe, '/'
add_crumb not_trusted.name, 'not_safe'

For now, it is possible to manually encode text passed into add_crumb, but this seems to go against the convention of encoding by default.

duplicate breadcrumbs

if i use :

add_breadcrumb "Post Categories", :client_post_categories_path

or

add_breadcrumb ("Post Categories") {|ins| ins.client_post_categories_path}

first time i refresh the page, it's ok.
then i refresh again and again,
the breadthumb looks like:

Home << Post Categories << Post Categories << Post Categories << Post Categories << Post Categories

Last crumb is linked - but it should not. It's connected with 'with_microdata'

I'm dissapointed of linking last crumb with using "with_microdata".

How to fix it: just modify "crumb_to_html" method like that:

def crumb_to_html(crumb, links, first_class, last_class, is_first, is_last, with_microdata)
  html_classes = []
  html_classes << first_class if is_first
  html_classes << last_class if is_last
  name, url = crumb
  can_link = url && links && !is_last
  html_content = can_link ? link_to(name, url) : content_tag(:span, name)
  if with_microdata
    item_title = content_tag(:span, name, :itemprop => "title")
    html_options = {:itemscope => true, :itemtype => data_definition_url("Breadcrumb")}
    html_content = can_link ? link_to(item_title, url, :class => html_classes, :itemprop => "url") : item_title
    content_tag(:div, html_content, html_options)
  else
    can_link ? link_to(name, url, :class => html_classes) : name
  end
end

Now works for me.

Btw. I prefer "Breadcrumbs On Rails" to "Crummy" because:
a) it checks every crumb if it is current_page. If not then it's not linked :-)
b) adding crumbs is much simplier:

add_crumber 'home', :root_path

vs

add_crumb( 'home') { |instance| instance.send :root_path }

controller level add_crumb() fails

With a class level add_crumb defined as follows:

class UsersController < ApplicationController
add_crumb("User List", :except => [:index]) { |instance| instance.send :users_path }
...
end

I get following in latest master:

NoMethodError: undefined method map!' for "/users":String vendor/bundle/ruby/1.8/gems/crummy-1.3/lib/crummy/action_controller.rb:24:inadd_crumb'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.12/lib/active_support/callbacks.rb:182:in call' vendor/bundle/ruby/1.8/gems/activesupport-2.3.12/lib/active_support/callbacks.rb:182:inevaluate_method'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.12/lib/active_support/callbacks.rb:166:in call' test/functional/users_controller_test.rb:22:in__bind_1319836051_713591'

Gem install instructions mention Formtastic

On line 17 README.textile says "Then install the Formtastic gem:"

I'm assuming this is supposed to say "Then install the Crummy gem:"

Might also be useful to add installation instructions like the ones that come with Hoptoud (modified to say crummy):

"Rails 2.x

Add the crummy gem to your app. In config/environment.rb:

config.gem 'crummy_notifier'

Then from your project's RAILS_ROOT, run:

rake gems:install

Once installed, you should vendor the crummy gem.

rake gems:unpack GEM=crummy"

Empty attributes

The markup contains empty attribute values for :id and :class. These attributes should not be included if nil.

<ul class="breadcrumbs" id=""><li class=""><a href="/">Home</a></li></ul>

global settings don't work for rails 3

copy / pasting this from the readme into config/initializers/crummy.rb:

Crummy.configure do |config|
  config.format = :xml
end

results in:

/Users/nlib/data/rdfnet/config/initializers/crummy.rb:1:in <top (required)>': private methodconfigure' called for Crummy:Module (NoMethodError)

Placing separator outside of li

When setting the format to html_list, the separator string is inserted after the closing li tag. Would it be possible instead to insert the separator after the link, inside of the li? This would make the html_list format render valid HTML as well as make it more compatible with Twitter bootstrap.

Thanks!

"Seperator"

It would be bettter to call parameter 'separator', not 'seperator'.

Rails 6.1: ActionView::Template::Error: can't modify frozen Hash

I'm trying to upgrade from Rails 6.0 to 6.1 and suddenly I'm getting this error that seems related to crummy, though I can't figure out what's wrong:

ActionView::Template::Error (can't modify frozen Hash):
    1: <%= render_crumbs :last_crumb_linked => false, :format => :html_list, :ul_class => 'breadcrumb', :last_class => 'active' %>
  
app/views/layouts/_breadcrumbs.html.erb:1
app/views/articles/edit.html.erb:2

If I comment out the render_crumbs call in my template then the error goes away.

Ideas?

li class

Something like this:

= render_crumbs :format => :html_list, :ul_id => "crumbid", :ul_class => "crumbclass", :li_class => "liclass"

returns empty li class

this:

= render_crumbs :format => :html_list, :ul_id => "crumbid", :ul_class => "crumbclass", :li_class => "liclass", :first_class => "first", :last_class => "last"

retrurns li.first, li.liclass, li.last (for three crumbs)

active_li_class not working also

and if I install gem, it installs version 1.6.0 without microdata

explicitly calling url_for is necessary?

I'm getting the error arguments passed to url_for can't be handled. Please require routes or provide your own implementation when my view uses <%= render_crumbs %>

My controller looks like this:

class SitesController < ApplicationController
  before_action :set_site, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!
  add_crumb 'Sites', :sites_url

  # GET /sites/1
  # GET /sites/1.json
  def show
    add_crumb @site.title, @site
  end

  # ...

  private
    def set_site
      @site = Site.find(params[:id])
    end
end

I figured out that if I change:

add_crumb @site.title, @site

to

add_crumb @site.title, url_for(@site)

then it works.

But your README shows a similar example without using url_for:

add_crumb @business.display_name, @business

Why is this?

New to rails & crummy (sorry if this is a dumb question).

Render more HTML inside the HTML list links (e.g. dropdown lists)

Hi:

Using bootstrap I've come up with a breadcrumb which contains dropdown lists at the same time. So with the current implementation I'm not sure it's possible to indicate what content goes inside the <a> link, aside from plain text. It would be neat to be able to indicate a template (view) partial.

If this is not already integrated. Is this something easy to achieve?

Cheers!

Manual passing with "add_crumb" results with additional, auto-generated elements

Hello,

I stumbled upon a very strange behaviour. What I want to do is to pass some breadcrumb elements and then render them at once with render_crumb:

add_crumb "All categories", url_for(page_params)
add_crumb "Some category", url_for(page_params)

When I check the @_crumbs variable content I get:

[["Alle Kategorien", "/catalog"], ["Some category", "/c/category"], ["Page", nil]]

Then when I want to render the breadcrumb in the view, I check it again and it contains:

[["Alle Kategorien", "/catalog"], ["Some category", "/c/category"], ["Page", nil], ["Some category", "/catalog/shops/1?filter=top"], ["Bestseller-Shops", nil]]

Any clue why these last two elements get into the breadcrumb automatically?

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.