Module: OpenGraphHelper

Defined in:
app/helpers/open_graph_helper.rb

Instance Method Summary collapse

Instance Method Details


53
54
55
# File 'app/helpers/open_graph_helper.rb', line 53

def link_to_oembed_image(cache, prefix = 'thumbnail_')
  link_to(oembed_image_tag(cache, prefix), cache.url, :target => '_blank')
end

#meta_tag_with_property(name, content) ⇒ Object


39
40
41
# File 'app/helpers/open_graph_helper.rb', line 39

def meta_tag_with_property(name, content)
  (:meta, '', :property => name, :content => content)
end

#oembed_image_tag(cache, prefix) ⇒ Object


57
58
59
# File 'app/helpers/open_graph_helper.rb', line 57

def oembed_image_tag(cache, prefix)
  image_tag(cache.data["#{prefix}url"], cache.options_hash(prefix))
end

#og_description(post) ⇒ Object


20
21
22
# File 'app/helpers/open_graph_helper.rb', line 20

def og_description(post)
  meta_tag_with_property('og:description', post_page_title(post, :length => 1000))
end

#og_html(cache) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'app/helpers/open_graph_helper.rb', line 43

def og_html(cache)
  "<a href=\"#{cache.url}\" target=\"_blank\">" +
  "  <div>" +
  "    <img src=\"#{cache.image}\" />" +
  "    <strong>#{cache.title}</strong>" +
  "    <p>#{cache.description}</p>" +
  "  </div>" +
  "</a>"
end

#og_image(post) ⇒ Object


14
15
16
17
18
# File 'app/helpers/open_graph_helper.rb', line 14

def og_image(post)
  tags = post.photos.map{|x| meta_tag_with_property('og:image', x.url(:thumb_large))}
  tags << meta_tag_with_property('og:image', default_image_url) if tags.empty?
  tags.join(' ')
end

#og_namespace(object) ⇒ Object


28
29
30
31
# File 'app/helpers/open_graph_helper.rb', line 28

def og_namespace(object)
  namespace = AppConfig.services.facebook.open_graph_namespace.present? ? AppConfig.services.facebook.open_graph_namespace : 'joindiaspora'
  "#{namespace}:frame"
end

#og_page_specific_tags(post) ⇒ Object


33
34
35
36
37
# File 'app/helpers/open_graph_helper.rb', line 33

def og_page_specific_tags(post)
  [og_title(post), og_type,
    og_url(post), og_image(post), 
    og_description(post)].join(' ').html_safe
end

#og_title(post) ⇒ Object


2
3
4
# File 'app/helpers/open_graph_helper.rb', line 2

def og_title(post)
  meta_tag_with_property('og:title', post_page_title(post, :length => 140))
end

#og_typeObject


6
7
8
# File 'app/helpers/open_graph_helper.rb', line 6

def og_type(post)
  meta_tag_with_property('og:type', 'article')
end

#og_url(post) ⇒ Object


10
11
12
# File 'app/helpers/open_graph_helper.rb', line 10

def og_url(post)
  meta_tag_with_property('og:url', post_url(post))
end