diff --git a/app/views/layouts/application-ng.html.erb b/app/views/layouts/application-ng.html.erb
index 90e4829..23530a0 100644
--- a/app/views/layouts/application-ng.html.erb
+++ b/app/views/layouts/application-ng.html.erb
@@ -12,24 +12,9 @@
-
-
-
-
-
-
-
- <% if @page %>
-
- <% @page.body_images_paths.each do |img| %>
-
-
- <% end %>
- <% end %>
-
<%= noosfero_javascript %>
<%= noosfero_stylesheets %>
diff --git a/plugins/metadata/config.yml.dist b/plugins/metadata/config.yml.dist
new file mode 100644
index 0000000..50db0f8
--- /dev/null
+++ b/plugins/metadata/config.yml.dist
@@ -0,0 +1,12 @@
+open_graph:
+ domain: cirandas.net
+ environment_logo: 'http://cirandas.net/designs/themes/cirandas-responsive/images/cirandas-logo-110.png'
+ types:
+ article: article
+ product: app_cirandas:sse_product
+ uploaded_file: app_cirandas:document
+ image: app_cirandas:picture
+ profile: app_cirandas:profile
+ person: app_cirandas:user
+ community: app_cirandas:community
+ enterprise: app_cirandas:sse_initiative
diff --git a/plugins/metadata/lib/ext/article.rb b/plugins/metadata/lib/ext/article.rb
new file mode 100644
index 0000000..ecd3a58
--- /dev/null
+++ b/plugins/metadata/lib/ext/article.rb
@@ -0,0 +1,32 @@
+require_dependency 'article'
+
+class Article
+
+ Metadata = {
+ 'og:type' => MetadataPlugin.og_types[:article],
+ 'og:url' => proc{ |a, c| c.og_url_for a.url },
+ 'og:title' => proc{ |a, c| a.title },
+ 'og:image' => proc do |a, c|
+ 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] if result.blank?
+ result
+ end,
+ 'og:see_also' => [],
+ 'og:site_name' => proc{ |a, c| a.profile.name },
+ 'og:updated_time' => proc{ |a, c| a.updated_at.iso8601 },
+ 'og:locale:locale' => proc{ |a, c| a.environment.default_language },
+ 'og:locale:alternate' => proc{ |a, c| a.environment.languages - [a.environment.default_language] },
+ 'twitter:image' => proc{ |a, c| a.body_images_paths },
+ 'article:expiration_time' => "", # In the future we might want to populate this
+ 'article:modified_time' => proc{ |a, c| a.updated_at.iso8601 },
+ 'article:published_time' => proc{ |a, c| a.published_at.iso8601 },
+ 'article:section' => "", # In the future we might want to populate this
+ 'article:tag' => proc{ |a, c| a.tags.map &:name },
+ 'og:description' => proc{ |a, c| ActionView::Base.full_sanitizer.sanitize a.body },
+ 'og:rich_attachment' => "",
+ }
+
+
+
+end
diff --git a/plugins/metadata/lib/ext/community.rb b/plugins/metadata/lib/ext/community.rb
new file mode 100644
index 0000000..e550b46
--- /dev/null
+++ b/plugins/metadata/lib/ext/community.rb
@@ -0,0 +1,10 @@
+require_dependency 'community'
+require_dependency "#{File.dirname __FILE__}/profile"
+
+class Community
+
+ Metadata = Metadata.merge({
+ 'og:type' => MetadataPlugin.og_types[:community],
+ })
+
+end
diff --git a/plugins/metadata/lib/ext/enterprise.rb b/plugins/metadata/lib/ext/enterprise.rb
new file mode 100644
index 0000000..2fa565c
--- /dev/null
+++ b/plugins/metadata/lib/ext/enterprise.rb
@@ -0,0 +1,18 @@
+require_dependency 'enterprise'
+require_dependency "#{File.dirname __FILE__}/profile"
+
+class Enterprise
+
+ Metadata = Metadata.merge({
+ 'og:type' => MetadataPlugin.og_types[:enterprise],
+ 'business:contact_data:email' => proc{ |e, c| e.contact_email },
+ 'business:contact_data:phone_number' => proc{ |e, c| e.contact_phone },
+ 'business:contact_data:street_address' => proc{ |e, c| e.address },
+ 'business:contact_data:locality' => proc{ |e, c| e.city },
+ 'business:contact_data:region' => proc{ |e, c| e.state },
+ 'business:contact_data:postal_code' => proc{ |e, c| e.zip_code },
+ 'business:contact_data:country_name' => proc{ |e| e.country },
+ 'place:location:latitude' => proc{ |e, c| p.lat },
+ 'place:location:longitude' => proc{ |e, c| p.lng },
+ })
+end
diff --git a/plugins/metadata/lib/ext/environment.rb b/plugins/metadata/lib/ext/environment.rb
new file mode 100644
index 0000000..67498c1
--- /dev/null
+++ b/plugins/metadata/lib/ext/environment.rb
@@ -0,0 +1,13 @@
+require_dependency 'environment'
+
+class Environment
+
+ Metadata = {
+ 'og:site_name' => proc{ |e, c| e.name },
+ 'og:description' => proc{ |e, c| e.name },
+ 'og:url' => proc{ |e, c| e.top_url },
+ 'og:locale:locale' => proc{ |e, c| e.default_language },
+ 'og:locale:alternate' => proc{ |e, c| e.languages - [e.default_language] }
+ }
+
+end
diff --git a/plugins/metadata/lib/ext/person.rb b/plugins/metadata/lib/ext/person.rb
new file mode 100644
index 0000000..2b93a98
--- /dev/null
+++ b/plugins/metadata/lib/ext/person.rb
@@ -0,0 +1,10 @@
+require_dependency 'person'
+require_dependency "#{File.dirname __FILE__}/profile"
+
+class Person
+
+ Metadata = Metadata.merge({
+ 'og:type' => MetadataPlugin.og_types[:person],
+ })
+
+end
diff --git a/plugins/metadata/lib/ext/product.rb b/plugins/metadata/lib/ext/product.rb
new file mode 100644
index 0000000..ac3b95f
--- /dev/null
+++ b/plugins/metadata/lib/ext/product.rb
@@ -0,0 +1,25 @@
+require_dependency 'product'
+
+class Product
+
+ Metadata = {
+ 'og:type' => MetadataPlugin.og_types[:product],
+ 'og:url' => proc{ |p, c| c.og_url_for p.url },
+ 'og:gr_hascurrencyvalue' => proc{ |p, c| p.price.to_f },
+ 'og:gr_hascurrency' => proc{ |p, c| p.environment.currency_unit },
+ 'og:title' => proc{ |p, c| p.name },
+ 'og:description' => proc{ |p, c| ActionView::Base.full_sanitizer.sanitize p.description },
+ 'og:image' => proc{ |p, c| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },
+ 'og:image:type' => proc{ |p, c| p.image.content_type if p.image },
+ 'og:image:height' => proc{ |p, c| p.image.height if p.image },
+ 'og:image:width' => proc{ |p, c| p.image.width if p.image },
+ 'og:see_also' => [],
+ 'og:site_name' => proc{ |p, c| c.og_url_for p.profile.url },
+ 'og:updated_time' => proc{ |p, c| p.updated_at.iso8601 },
+ 'og:locale:locale' => proc{ |p, c| p.environment.default_language },
+ 'og:locale:alternate' => proc{ |p, c| p.environment.languages - [p.environment.default_language] },
+ }
+
+ protected
+
+end
diff --git a/plugins/metadata/lib/ext/profile.rb b/plugins/metadata/lib/ext/profile.rb
new file mode 100644
index 0000000..f378e25
--- /dev/null
+++ b/plugins/metadata/lib/ext/profile.rb
@@ -0,0 +1,24 @@
+require_dependency 'profile'
+
+class Profile
+
+ Metadata = {
+ 'og:type' => MetadataPlugin.og_types[:profile],
+ 'og:image' => proc{ |p, c| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },
+ 'og:title' => proc{ |p, c| p.short_name nil },
+ 'og:url' => proc do |p, c|
+ #force profile identifier for custom domains and fixed host. see og_url_for
+ c.og_url_for p.url.merge(profile: p.identifier)
+ end,
+ 'og:description' => proc{ |p, c| p.description },
+ 'og:updated_time' => proc{ |p, c| p.updated_at.iso8601 },
+ 'place:location:latitude' => proc{ |p, c| p.lat },
+ 'place:location:longitude' => proc{ |p, c| p.lng },
+ 'og:locale:locale' => proc{ |p, c| p.environment.default_language },
+ 'og:locale:alternate' => proc{ |p, c| p.environment.languages - [p.environment.default_language] },
+ 'og:site_name' => "",
+ 'og:see_also' => "",
+ 'og:rich_attachment' => "",
+ }
+
+end
diff --git a/plugins/metadata/lib/ext/uploaded_file.rb b/plugins/metadata/lib/ext/uploaded_file.rb
new file mode 100644
index 0000000..86acc2b
--- /dev/null
+++ b/plugins/metadata/lib/ext/uploaded_file.rb
@@ -0,0 +1,17 @@
+require_dependency 'uploaded_file'
+require_dependency "#{File.dirname __FILE__}/article"
+
+class UploadedFile
+
+ Metadata = {
+ 'og:type' => proc do |u, c|
+ type = if u.image? then :image else :uploaded_file end
+ MetadataPlugin.og_types[type]
+ end,
+ 'og:url' => proc{ |u, c| c.og_url_for u.url.merge(view: true) },
+ 'og:title' => proc{ |u, c| u.title },
+ 'og:image' => proc{ |u, c| "#{u.environment.top_url}#{u.public_filename}" if u.image? },
+ 'og:description' => proc{ |u, c| u.abstract || u.title },
+ }
+
+end
diff --git a/plugins/metadata/lib/metadata_plugin.rb b/plugins/metadata/lib/metadata_plugin.rb
new file mode 100644
index 0000000..f383edf
--- /dev/null
+++ b/plugins/metadata/lib/metadata_plugin.rb
@@ -0,0 +1,59 @@
+
+class MetadataPlugin < Noosfero::Plugin
+
+ def self.plugin_name
+ I18n.t 'metadata_plugin.lib.plugin.name'
+ end
+
+ def self.plugin_description
+ I18n.t 'metadata_plugin.lib.plugin.description'
+ end
+
+ def self.config
+ @config ||= HashWithIndifferentAccess.new(YAML.load File.read("#{File.dirname __FILE__}/../config.yml")) rescue {}
+ end
+
+ def self.og_types
+ @og_types ||= self.config[:open_graph][:types] rescue {}
+ end
+
+ def head_ending
+ plugin = self
+ lambda do
+ options = MetadataPlugin::Spec::Controllers[controller.controller_path.to_sym]
+ options ||= MetadataPlugin::Spec::Controllers[:profile] if controller.is_a? ProfileController
+ options ||= MetadataPlugin::Spec::Controllers[:environment]
+ return unless options
+
+ return unless object = case variable = options[:variable]
+ when Proc then instance_exec(&variable) rescue nil
+ else instance_variable_get variable
+ end
+ return unless metadata = (object.class.const_get(:Metadata) rescue nil)
+
+ metadata.map do |property, contents|
+ contents = contents.call(object, plugin) rescue nil if contents.is_a? Proc
+ next if contents.blank?
+
+ Array(contents).map do |content|
+ content = content.call(object, plugin) rescue nil if content.is_a? Proc
+ next if content.blank?
+ tag 'meta', property: property, content: content
+ end.join
+ end.join
+ end
+ end
+
+ # context HELPERS
+ def og_url_for options
+ options.delete :port
+ options[:host] = self.class.config[:open_graph][:domain] rescue context.send(:environment).default_hostname
+ Noosfero::Application.routes.url_helpers.url_for options
+ end
+
+ protected
+
+end
+
+ActiveSupport.run_load_hooks :metadata_plugin, MetadataPlugin
+
diff --git a/plugins/metadata/lib/metadata_plugin/spec.rb b/plugins/metadata/lib/metadata_plugin/spec.rb
new file mode 100644
index 0000000..af67ece
--- /dev/null
+++ b/plugins/metadata/lib/metadata_plugin/spec.rb
@@ -0,0 +1,29 @@
+
+class MetadataPlugin::Spec
+
+ Controllers = {
+ manage_products: {
+ variable: :@product,
+ },
+ content_viewer: {
+ variable: proc do
+ if profile and profile.home_page_id == @page.id
+ @profile
+ elsif @page.respond_to? :encapsulated_file
+ @page.encapsulated_file
+ else
+ @page
+ end
+ end,
+ },
+ # fallback
+ profile: {
+ variable: :@profile,
+ },
+ # last fallback
+ environment: {
+ variable: :@environment,
+ },
+ }
+
+end
diff --git a/plugins/metadata/locales/en.yml b/plugins/metadata/locales/en.yml
new file mode 100644
index 0000000..23dc565
--- /dev/null
+++ b/plugins/metadata/locales/en.yml
@@ -0,0 +1,14 @@
+
+"en-US": &en-US
+
+ metadata_plugin:
+ lib:
+ plugin:
+ name: 'Export metadata'
+ description: 'Export metadata for models on meta tags'
+
+'en_US':
+ <<: *en-US
+'en':
+ <<: *en-US
+
diff --git a/plugins/metadata/locales/pt.yml b/plugins/metadata/locales/pt.yml
new file mode 100644
index 0000000..3c125f9
--- /dev/null
+++ b/plugins/metadata/locales/pt.yml
@@ -0,0 +1,14 @@
+
+"pt-BR": &pt-BR
+
+ metadata_plugin:
+ lib:
+ plugin:
+ name: 'Exporta metadados'
+ description: 'Exporta metadados de modelos em tags meta'
+
+'pt_BR':
+ <<: *pt-BR
+'pt':
+ <<: *pt-BR
+
--
libgit2 0.21.2