From 11ea4a1cd5fa474bc2595ea386f393927a803356 Mon Sep 17 00:00:00 2001 From: Rupyshev Vladimir Date: Tue, 25 Oct 2016 14:51:44 +0300 Subject: [PATCH 1/4] Semantic from scheme.org. --- lib/gretel/renderer.rb | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/gretel/renderer.rb b/lib/gretel/renderer.rb index cbe3468..d39790b 100644 --- a/lib/gretel/renderer.rb +++ b/lib/gretel/renderer.rb @@ -170,13 +170,13 @@ def render return "" if links.empty? # Loop through all but the last (current) link and build HTML of the fragments - fragments = links[0..-2].map do |link| - render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic]) + fragments = links[0..-2].map do |link, index| + render_fragment(options[:fragment_tag], link.text, link.url, links.index(link)+1, options[:semantic]) end # The current link is handled a little differently, and is only linked if specified in the options current_link = links.last - fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], class: options[:current_class], current_link: current_link.url) + fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), links.index(current_link)+1, options[:semantic], class: options[:current_class], current_link: current_link.url) # Build the final HTML html_fragments = [] @@ -192,37 +192,44 @@ def render end html = html_fragments.join(" ").html_safe - content_tag(options[:container_tag], html, id: options[:id], class: options[:class]) + + if options[:semantic] + content_tag(options[:container_tag], html, id: options[:id], class: options[:class], itemscope: "", itemtype: "http://schema.org/BreadcrumbList") + + else + content_tag(options[:container_tag], html, id: options[:id], class: options[:class]) + end end alias :to_s :render # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link. - def render_fragment(fragment_tag, text, url, semantic, options = {}) + def render_fragment(fragment_tag, text, url, position, semantic, options = {}) if semantic - render_semantic_fragment(fragment_tag, text, url, options) + render_semantic_fragment(fragment_tag, text, url, position, options) else render_nonsemantic_fragment(fragment_tag, text, url, options) end end # Renders semantic fragment HTML. - def render_semantic_fragment(fragment_tag, text, url, options = {}) + def render_semantic_fragment(fragment_tag, text, url, position, options = {}) + tag_position = tag(:meta, itemprop: "position", content: position) if fragment_tag - text = content_tag(:span, text, itemprop: "title") + text = content_tag(:span, text, itemprop: "name") if url.present? - text = breadcrumb_link_to(text, url, itemprop: "url") + text = breadcrumb_link_to(text, url, itemprop: "item", itemscope: "", itemtype: "http://schema.org/Thing") elsif options[:current_link].present? current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}" text = text + tag(:meta, itemprop: "url", content: current_url) end - - content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb") + text = text + tag_position + content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") elsif url.present? - content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb") + content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "name"), url, class: options[:class], itemprop: "item", itemscope: "", itemtype: "http://schema.org/Thing") + tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") else - content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb") + content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "name")+tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") end end From fc72335169fdafc54fd2692f83cfe4ed128dc2bb Mon Sep 17 00:00:00 2001 From: Rupyshev Vladimir Date: Tue, 25 Oct 2016 14:51:44 +0300 Subject: [PATCH 2/4] Semantic from schema.org. --- lib/gretel/renderer.rb | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/gretel/renderer.rb b/lib/gretel/renderer.rb index cbe3468..d39790b 100644 --- a/lib/gretel/renderer.rb +++ b/lib/gretel/renderer.rb @@ -170,13 +170,13 @@ def render return "" if links.empty? # Loop through all but the last (current) link and build HTML of the fragments - fragments = links[0..-2].map do |link| - render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic]) + fragments = links[0..-2].map do |link, index| + render_fragment(options[:fragment_tag], link.text, link.url, links.index(link)+1, options[:semantic]) end # The current link is handled a little differently, and is only linked if specified in the options current_link = links.last - fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], class: options[:current_class], current_link: current_link.url) + fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), links.index(current_link)+1, options[:semantic], class: options[:current_class], current_link: current_link.url) # Build the final HTML html_fragments = [] @@ -192,37 +192,44 @@ def render end html = html_fragments.join(" ").html_safe - content_tag(options[:container_tag], html, id: options[:id], class: options[:class]) + + if options[:semantic] + content_tag(options[:container_tag], html, id: options[:id], class: options[:class], itemscope: "", itemtype: "http://schema.org/BreadcrumbList") + + else + content_tag(options[:container_tag], html, id: options[:id], class: options[:class]) + end end alias :to_s :render # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link. - def render_fragment(fragment_tag, text, url, semantic, options = {}) + def render_fragment(fragment_tag, text, url, position, semantic, options = {}) if semantic - render_semantic_fragment(fragment_tag, text, url, options) + render_semantic_fragment(fragment_tag, text, url, position, options) else render_nonsemantic_fragment(fragment_tag, text, url, options) end end # Renders semantic fragment HTML. - def render_semantic_fragment(fragment_tag, text, url, options = {}) + def render_semantic_fragment(fragment_tag, text, url, position, options = {}) + tag_position = tag(:meta, itemprop: "position", content: position) if fragment_tag - text = content_tag(:span, text, itemprop: "title") + text = content_tag(:span, text, itemprop: "name") if url.present? - text = breadcrumb_link_to(text, url, itemprop: "url") + text = breadcrumb_link_to(text, url, itemprop: "item", itemscope: "", itemtype: "http://schema.org/Thing") elsif options[:current_link].present? current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}" text = text + tag(:meta, itemprop: "url", content: current_url) end - - content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb") + text = text + tag_position + content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") elsif url.present? - content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb") + content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "name"), url, class: options[:class], itemprop: "item", itemscope: "", itemtype: "http://schema.org/Thing") + tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") else - content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb") + content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "name")+tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") end end From b2fb4e7c99a46b7c41cd0c6969b7b13bd95e470d Mon Sep 17 00:00:00 2001 From: Rupyshev Vladimir Date: Sun, 13 Nov 2016 03:22:21 +0300 Subject: [PATCH 3/4] Fix schema.org --- lib/gretel/renderer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gretel/renderer.rb b/lib/gretel/renderer.rb index d39790b..af1b021 100644 --- a/lib/gretel/renderer.rb +++ b/lib/gretel/renderer.rb @@ -219,7 +219,7 @@ def render_semantic_fragment(fragment_tag, text, url, position, options = {}) text = content_tag(:span, text, itemprop: "name") if url.present? - text = breadcrumb_link_to(text, url, itemprop: "item", itemscope: "", itemtype: "http://schema.org/Thing") + text = breadcrumb_link_to(text, url, itemprop: "item") elsif options[:current_link].present? current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}" text = text + tag(:meta, itemprop: "url", content: current_url) @@ -227,7 +227,7 @@ def render_semantic_fragment(fragment_tag, text, url, position, options = {}) text = text + tag_position content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") elsif url.present? - content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "name"), url, class: options[:class], itemprop: "item", itemscope: "", itemtype: "http://schema.org/Thing") + tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") + content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "name"), url, class: options[:class], itemprop: "item") + tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") else content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "name")+tag_position, itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") end From a3238dc6c59e1cf75ffe97fb9f3434bcc80cd821 Mon Sep 17 00:00:00 2001 From: Rupyshev Vladimir Date: Sun, 20 Nov 2016 00:15:31 +0300 Subject: [PATCH 4/4] Meta tag incorrect url content --- lib/gretel/renderer.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/gretel/renderer.rb b/lib/gretel/renderer.rb index af1b021..3443f69 100644 --- a/lib/gretel/renderer.rb +++ b/lib/gretel/renderer.rb @@ -220,10 +220,8 @@ def render_semantic_fragment(fragment_tag, text, url, position, options = {}) if url.present? text = breadcrumb_link_to(text, url, itemprop: "item") - elsif options[:current_link].present? - current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}" - text = text + tag(:meta, itemprop: "url", content: current_url) end + text = text + tag_position content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://schema.org/ListItem", itemprop: "itemListElement") elsif url.present?