1
0
Fork 0
forked from OpenNeo/impress

add thumbnails to outfits#show via open graph

This commit is contained in:
Emi Matchu 2012-07-29 16:45:12 -04:00
parent f8aacfba98
commit 54ca5881fe
3 changed files with 31 additions and 0 deletions

View file

@ -1,4 +1,12 @@
module ApplicationHelper 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) def add_body_class(class_name)
@body_class ||= '' @body_class ||= ''
@body_class << " #{class_name}" @body_class << " #{class_name}"
@ -101,6 +109,23 @@ module ApplicationHelper
hidden_field_tag 'origin', value, :id => nil hidden_field_tag 'origin', value, :id => nil
end 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 def return_to_field_tag
hidden_field_tag :return_to, request.fullpath hidden_field_tag :return_to, request.fullpath
end end

View file

@ -14,6 +14,7 @@
= yield :stylesheets = yield :stylesheets
= stylesheet_link_tag "compiled/screen" = stylesheet_link_tag "compiled/screen"
= yield :meta = yield :meta
= open_graph_tags
= csrf_meta_tag = csrf_meta_tag
= signed_in_meta_tag = signed_in_meta_tag
%body{:class => body_class} %body{:class => body_class}

View file

@ -1,6 +1,11 @@
- title(@outfit.name || "Shared outfit") - title(@outfit.name || "Shared outfit")
- content_for :before_title, campaign_progress - 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 = link_to_edit_outfit(@outfit, :class => 'button', :id => 'outfit-wardrobe-link') do
Edit Edit
- unless user_signed_in? && @outfit.user == current_user - unless user_signed_in? && @outfit.user == current_user