Skip to content

Instantly share code, notes, and snippets.

@miyamae
Created November 28, 2014 18:34
Show Gist options
  • Save miyamae/e4573f54a02bcc9d5d41 to your computer and use it in GitHub Desktop.
Save miyamae/e4573f54a02bcc9d5d41 to your computer and use it in GitHub Desktop.
microdata markup for weppos/breadcrumbs_on_rails
class CustomBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::SimpleBuilder
def initialize(context, elements, options = {})
super
@options[:separator] = ''
end
def render_element(element)
# truncate page title
if element.name !~ /^</ && element.name.to_s.length > 20
trunc = element.name[0..19].to_s
element.name = trunc + '…'
end
# with microdata
if element.path == nil
content = compute_name(element)
else
content = @context.link_to_unless_current(
@context.content_tag(:span, compute_name(element), itemprop: 'title'),
compute_path(element), itemprop: 'url')
end
content = @context.content_tag(:li, content,
itemscope: 'itemscope', itemtype: 'http://data-vocabulary.org/Breadcrumb')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment