Skip to content

Instantly share code, notes, and snippets.

@fujimogn
Created March 25, 2012 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujimogn/2198987 to your computer and use it in GitHub Desktop.
Save fujimogn/2198987 to your computer and use it in GitHub Desktop.
microdata breadcrumb helper for twitterbootstrap
# microdata breadcrumb helper for twitterbootstrap
# http://support.google.com/webmasters/bin/answer.py?hl=ja&answer=176035
#
# :example
# array = [
# [{:name => name, :url => url },{:name => name :url => url}],
# [{:name => name, :url => url },{:name => name :url => url}]
# ]
# options = {}
#
def breadcrumbs_for(array = [], options = {})
default_options = YAML.load <<-"EOS"
:nav:
:options:
:ol:
:options:
:class: "breadcrumb"
:li:
:options:
:itemscope: "itemscope"
:itemtype: "http://data-vocabulary.org/Breadcrumb"
:a:
:options:
:itemprop: "url"
:rel: "directory"
:span:
:options:
:itemprop: "title"
:separator:
:name: :span
:content: "/"
:options:
:class: "divider"
EOS
options = default_options.merge options
content_tag(:nav, options[:nav][:options]) do
array.each do |ul|
unless ul.include?(nil)
content_tag(:ol,options[:ol][:options]) do
ul.each_with_index do |a, i|
if i + 1 != ul.size
content_tag(:li,options[:li][:options]) do
content_tag(:a, {:href => a[:url]}.merge(options[:a][:options])) do
content_tag(:span, options[:span][:options]) do
a[:name]
end
end
if options[:separator]
concat content_tag(options[:separator][:name], options[:separator][:content], options[:separator][:options])
end
end
else
content_tag(:li) do
content_tag(:span, options[:span][:options]) do
a[:name]
end
end
end
end
end
end
end
end unless array.empty?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment