From 8732ba3390bbe8ae5f26b08f54f36eaf333b6b47 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Mon, 16 Mar 2015 15:17:22 -0300 Subject: [PATCH] metadata: use environment data for required fields --- plugins/metadata/lib/ext/article.rb | 8 ++++---- plugins/metadata/lib/ext/enterprise.rb | 22 ++++++++++++++-------- plugins/metadata/lib/ext/product.rb | 8 ++++++-- plugins/metadata/lib/ext/profile.rb | 8 ++++++-- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/plugins/metadata/lib/ext/article.rb b/plugins/metadata/lib/ext/article.rb index 419c069..ac53071 100644 --- a/plugins/metadata/lib/ext/article.rb +++ b/plugins/metadata/lib/ext/article.rb @@ -12,10 +12,10 @@ class Article end, title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" }, image: proc do |a, plugin| - result = a.body_images_paths - result = "#{a.profile.environment.top_url}#{a.profile.image.public_filename}" if a.profile.image if result.blank? - result ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if result.blank? - result + img = a.body_images_paths + img = "#{a.profile.environment.top_url}#{a.profile.image.public_filename}" if a.profile.image if img.blank? + img ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if img.blank? + img end, see_also: [], site_name: proc{ |a, c| a.profile.name }, diff --git a/plugins/metadata/lib/ext/enterprise.rb b/plugins/metadata/lib/ext/enterprise.rb index 345ed30..1527128 100644 --- a/plugins/metadata/lib/ext/enterprise.rb +++ b/plugins/metadata/lib/ext/enterprise.rb @@ -7,15 +7,21 @@ class Enterprise type: proc{ |e, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:enterprise] || :enterprise }, } + # required for businness + metadata_spec namespace: 'place:location', tags: { + latitude: proc{ |e, plugin| if e.lat.present? then e.lat else e.environment.lat end }, + longitude: proc{ |e, plugin| if e.lng.present? then e.lng else e.environment.lng end }, + } + metadata_spec namespace: 'business:contact_data', tags: { - email: proc{ |e, plugin| e.contact_email }, - phone_number: proc{ |e, plugin| e.contact_phone }, - street_address: proc{ |e, plugin| e.address }, - locality: proc{ |e, plugin| e.city }, - region: proc{ |e, plugin| e.state }, - postal_code: proc{ |e, plugin| e.zip_code }, - # required - country_name: proc{ |e, plugin| e.country || e.environment.country_name || 'Unknown' }, + # all required + email: proc{ |e, plugin| if e.contact_email.present? then e.contact_email else e.environment.contact_email end }, + phone_number: proc{ |e, plugin| if e.contact_phone.present? then e.contact_phone else e.environment.contact_phone end }, + street_address: proc{ |e, plugin| if e.address.present? then e.address else e.environment.address end }, + locality: proc{ |e, plugin| if e.city.present? then e.city else e.environment.city end }, + region: proc{ |e, plugin| if e.state.present? then e.state else e.environment.state end }, + postal_code: proc{ |e, plugin| if e.zip_code.present? then e.zip_code else e.environment.postal_code end }, + country_name: proc{ |e, plugin| if e.country.present? then e.country else e.environment.country_name end }, } end diff --git a/plugins/metadata/lib/ext/product.rb b/plugins/metadata/lib/ext/product.rb index b2de60c..a6ff72e 100644 --- a/plugins/metadata/lib/ext/product.rb +++ b/plugins/metadata/lib/ext/product.rb @@ -4,7 +4,6 @@ class Product metadata_spec namespace: :og, tags: { type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:product] || :product }, - url: proc{ |p, plugin| plugin.og_url_for p.url }, url: proc do |p, plugin| url = p.url.merge! profile: p.profile.identifier, og_type: plugin.context.params[:og_type] plugin.og_url_for url @@ -14,7 +13,12 @@ class Product title: proc{ |p, plugin| "#{p.name} - #{p.profile.name}" if p }, description: proc{ |p, plugin| ActionView::Base.full_sanitizer.sanitize p.description }, - image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image }, + image: proc do |p, plugin| + img = "#{p.environment.top_url}#{p.image.public_filename}" if p.image + img = "#{p.environment.top_url}#{p.profile.image.public_filename}" if img.blank? and p.profile.image + img ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if img.blank? + img + end, 'image:type' => proc{ |p, plugin| p.image.content_type if p.image }, 'image:height' => proc{ |p, plugin| p.image.height if p.image }, 'image:width' => proc{ |p, plugin| p.image.width if p.image }, diff --git a/plugins/metadata/lib/ext/profile.rb b/plugins/metadata/lib/ext/profile.rb index 245c3f4..401a8ed 100644 --- a/plugins/metadata/lib/ext/profile.rb +++ b/plugins/metadata/lib/ext/profile.rb @@ -4,8 +4,12 @@ class Profile metadata_spec namespace: :og, tags: { type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:profile] || :profile }, - image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image }, - title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, + image: proc do |p, plugin| + img = "#{p.environment.top_url}#{p.image.public_filename}" if p.image + img ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if img.blank? + img + end, + title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, url: proc{ |p, plugin| plugin.og_url_for plugin.og_profile_url(p) }, description: proc{ |p, plugin| p.description }, updated_time: proc{ |p, plugin| p.updated_at.iso8601 }, -- libgit2 0.21.2