Commit 8732ba3390bbe8ae5f26b08f54f36eaf333b6b47

Authored by Braulio Bhavamitra
1 parent 8dc2e2b6

metadata: use environment data for required fields

plugins/metadata/lib/ext/article.rb
@@ -12,10 +12,10 @@ class Article @@ -12,10 +12,10 @@ class Article
12 end, 12 end,
13 title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" }, 13 title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" },
14 image: proc do |a, plugin| 14 image: proc do |a, plugin|
15 - result = a.body_images_paths  
16 - result = "#{a.profile.environment.top_url}#{a.profile.image.public_filename}" if a.profile.image if result.blank?  
17 - result ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if result.blank?  
18 - result 15 + img = a.body_images_paths
  16 + img = "#{a.profile.environment.top_url}#{a.profile.image.public_filename}" if a.profile.image if img.blank?
  17 + img ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if img.blank?
  18 + img
19 end, 19 end,
20 see_also: [], 20 see_also: [],
21 site_name: proc{ |a, c| a.profile.name }, 21 site_name: proc{ |a, c| a.profile.name },
plugins/metadata/lib/ext/enterprise.rb
@@ -7,15 +7,21 @@ class Enterprise @@ -7,15 +7,21 @@ class Enterprise
7 type: proc{ |e, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:enterprise] || :enterprise }, 7 type: proc{ |e, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:enterprise] || :enterprise },
8 } 8 }
9 9
  10 + # required for businness
  11 + metadata_spec namespace: 'place:location', tags: {
  12 + latitude: proc{ |e, plugin| if e.lat.present? then e.lat else e.environment.lat end },
  13 + longitude: proc{ |e, plugin| if e.lng.present? then e.lng else e.environment.lng end },
  14 + }
  15 +
10 metadata_spec namespace: 'business:contact_data', tags: { 16 metadata_spec namespace: 'business:contact_data', tags: {
11 - email: proc{ |e, plugin| e.contact_email },  
12 - phone_number: proc{ |e, plugin| e.contact_phone },  
13 - street_address: proc{ |e, plugin| e.address },  
14 - locality: proc{ |e, plugin| e.city },  
15 - region: proc{ |e, plugin| e.state },  
16 - postal_code: proc{ |e, plugin| e.zip_code },  
17 - # required  
18 - country_name: proc{ |e, plugin| e.country || e.environment.country_name || 'Unknown' }, 17 + # all required
  18 + email: proc{ |e, plugin| if e.contact_email.present? then e.contact_email else e.environment.contact_email end },
  19 + phone_number: proc{ |e, plugin| if e.contact_phone.present? then e.contact_phone else e.environment.contact_phone end },
  20 + street_address: proc{ |e, plugin| if e.address.present? then e.address else e.environment.address end },
  21 + locality: proc{ |e, plugin| if e.city.present? then e.city else e.environment.city end },
  22 + region: proc{ |e, plugin| if e.state.present? then e.state else e.environment.state end },
  23 + postal_code: proc{ |e, plugin| if e.zip_code.present? then e.zip_code else e.environment.postal_code end },
  24 + country_name: proc{ |e, plugin| if e.country.present? then e.country else e.environment.country_name end },
19 } 25 }
20 26
21 end 27 end
plugins/metadata/lib/ext/product.rb
@@ -4,7 +4,6 @@ class Product @@ -4,7 +4,6 @@ class Product
4 4
5 metadata_spec namespace: :og, tags: { 5 metadata_spec namespace: :og, tags: {
6 type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:product] || :product }, 6 type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:product] || :product },
7 - url: proc{ |p, plugin| plugin.og_url_for p.url },  
8 url: proc do |p, plugin| 7 url: proc do |p, plugin|
9 url = p.url.merge! profile: p.profile.identifier, og_type: plugin.context.params[:og_type] 8 url = p.url.merge! profile: p.profile.identifier, og_type: plugin.context.params[:og_type]
10 plugin.og_url_for url 9 plugin.og_url_for url
@@ -14,7 +13,12 @@ class Product @@ -14,7 +13,12 @@ class Product
14 title: proc{ |p, plugin| "#{p.name} - #{p.profile.name}" if p }, 13 title: proc{ |p, plugin| "#{p.name} - #{p.profile.name}" if p },
15 description: proc{ |p, plugin| ActionView::Base.full_sanitizer.sanitize p.description }, 14 description: proc{ |p, plugin| ActionView::Base.full_sanitizer.sanitize p.description },
16 15
17 - image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image }, 16 + image: proc do |p, plugin|
  17 + img = "#{p.environment.top_url}#{p.image.public_filename}" if p.image
  18 + img = "#{p.environment.top_url}#{p.profile.image.public_filename}" if img.blank? and p.profile.image
  19 + img ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if img.blank?
  20 + img
  21 + end,
18 'image:type' => proc{ |p, plugin| p.image.content_type if p.image }, 22 'image:type' => proc{ |p, plugin| p.image.content_type if p.image },
19 'image:height' => proc{ |p, plugin| p.image.height if p.image }, 23 'image:height' => proc{ |p, plugin| p.image.height if p.image },
20 'image:width' => proc{ |p, plugin| p.image.width if p.image }, 24 'image:width' => proc{ |p, plugin| p.image.width if p.image },
plugins/metadata/lib/ext/profile.rb
@@ -4,8 +4,12 @@ class Profile @@ -4,8 +4,12 @@ class Profile
4 4
5 metadata_spec namespace: :og, tags: { 5 metadata_spec namespace: :og, tags: {
6 type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:profile] || :profile }, 6 type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:profile] || :profile },
7 - image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },  
8 - title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, 7 + image: proc do |p, plugin|
  8 + img = "#{p.environment.top_url}#{p.image.public_filename}" if p.image
  9 + img ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if img.blank?
  10 + img
  11 + end,
  12 + title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end },
9 url: proc{ |p, plugin| plugin.og_url_for plugin.og_profile_url(p) }, 13 url: proc{ |p, plugin| plugin.og_url_for plugin.og_profile_url(p) },
10 description: proc{ |p, plugin| p.description }, 14 description: proc{ |p, plugin| p.description },
11 updated_time: proc{ |p, plugin| p.updated_at.iso8601 }, 15 updated_time: proc{ |p, plugin| p.updated_at.iso8601 },