Created
March 25, 2012 18:51
-
-
Save fujimogn/2198987 to your computer and use it in GitHub Desktop.
microdata breadcrumb helper for twitterbootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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