From 54ca5881fe9d6f5dec1869193e148f8d3c7b9c15 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 29 Jul 2012 16:45:12 -0400 Subject: [PATCH] add thumbnails to outfits#show via open graph --- app/helpers/application_helper.rb | 25 +++++++++++++++++++++++++ app/views/layouts/application.html.haml | 1 + app/views/outfits/show.html.haml | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d6bb8c3c..63d4af2f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,12 @@ module ApplicationHelper + def absolute_url(path_or_url) + if path_or_url.include?('://') # already an absolute URL + path_or_url + else # a relative path + request.protocol + request.host_with_port + path_or_url + end + end + def add_body_class(class_name) @body_class ||= '' @body_class << " #{class_name}" @@ -100,6 +108,23 @@ module ApplicationHelper def origin_tag(value) hidden_field_tag 'origin', value, :id => nil end + + def open_graph(properties) + if @open_graph + @open_graph.merge! properties + else + @open_graph = properties + end + end + + def open_graph_tags + if @open_graph + @open_graph.inject('') do |output, property| + key, value = property + output + tag(:meta, :property => "og:#{key}", :content => value) + end.html_safe + end + end def return_to_field_tag hidden_field_tag :return_to, request.fullpath diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 0736bedf..2c5437c3 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -14,6 +14,7 @@ = yield :stylesheets = stylesheet_link_tag "compiled/screen" = yield :meta + = open_graph_tags = csrf_meta_tag = signed_in_meta_tag %body{:class => body_class} diff --git a/app/views/outfits/show.html.haml b/app/views/outfits/show.html.haml index 880925b4..0a769542 100644 --- a/app/views/outfits/show.html.haml +++ b/app/views/outfits/show.html.haml @@ -1,6 +1,11 @@ - title(@outfit.name || "Shared outfit") - content_for :before_title, campaign_progress +- open_graph :type => 'openneo-impress:outfit', :title => yield(:title), + :url => outfit_url(@outfit) +- if @outfit.image? + - open_graph :image => absolute_url(@outfit.image.url) + = link_to_edit_outfit(@outfit, :class => 'button', :id => 'outfit-wardrobe-link') do Edit - unless user_signed_in? && @outfit.user == current_user