Module: Pageflow::SocialShareHelper

Includes:
EntriesHelper
Included in:
SocialShareLinksHelper, StructuredDataHelper
Defined in:
app/helpers/pageflow/social_share_helper.rb

Instance Method Summary collapse

Methods included from EntriesHelper

#entry_css_class, #entry_file_rights, #entry_global_links, #entry_header_css_class, #entry_mobile_navigation_pages, #entry_stylesheet_link_tag, #entry_summary, #entry_theme_stylesheet_link_tag, #pretty_entry_title, #pretty_entry_url

Instance Method Details

#social_share_entry_description(entry) ⇒ Object



45
46
47
48
49
50
51
52
# File 'app/helpers/pageflow/social_share_helper.rb', line 45

def social_share_entry_description(entry)
  return social_share_sanitize(entry.summary) if entry.summary.present?

  entry.pages.each do |page|
    return social_share_sanitize(page.configuration['text']) if page.configuration['text'].present?
  end
  ''
end

#social_share_entry_image_tags(entry) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/pageflow/social_share_helper.rb', line 54

def social_share_entry_image_tags(entry)
  image_urls = []
  image_file = ImageFile.find_by_id(entry.share_image_id)

  if image_file
    image_urls << image_file.thumbnail_url(:medium)
  else
    entry.pages.each do |page|
      if image_urls.size >= 4
        break
      else
        image_urls << page.thumbnail_url(:medium)
        image_urls.uniq!
      end
    end
  end

  render 'pageflow/social_share/image_tags', :image_urls => image_urls
end

#social_share_entry_url(entry) ⇒ Object



13
14
15
# File 'app/helpers/pageflow/social_share_helper.rb', line 13

def social_share_entry_url(entry)
  entry.share_url.presence || pretty_entry_url(entry)
end

#social_share_meta_tags_for(target) ⇒ Object



5
6
7
8
9
10
11
# File 'app/helpers/pageflow/social_share_helper.rb', line 5

def social_share_meta_tags_for(target)
  if target.is_a?(Page)
    render('pageflow/social_share/page_meta_tags', entry: @entry, page: @entry.share_target)
  else
    render('pageflow/social_share/entry_meta_tags', entry: @entry)
  end
end

#social_share_normalize_protocol(url) ⇒ Object



74
75
76
# File 'app/helpers/pageflow/social_share_helper.rb', line 74

def social_share_normalize_protocol(url)
  url.gsub(/^(\/\/|https:\/\/)/, 'http://')
end

#social_share_page_description(entry, page) ⇒ Object



39
40
41
42
43
# File 'app/helpers/pageflow/social_share_helper.rb', line 39

def social_share_page_description(entry, page)
  return social_share_sanitize(page.configuration['text']) if page.configuration['text'].present?
  return social_share_sanitize(page.configuration['description']) if page.configuration['description'].present?
  social_share_entry_description(entry)
end

#social_share_page_title(page) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/pageflow/social_share_helper.rb', line 28

def social_share_page_title(page)
  entry = page.chapter.entry

  title = ["#{entry.title}:"]
  title << page.title
  title << '-' if entry.theming.cname_domain.present?
  title << entry.theming.cname_domain

  title.join(' ')
end

#social_share_page_url(entry, page_or_perma_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/pageflow/social_share_helper.rb', line 17

def social_share_page_url(entry, page_or_perma_id)
  perma_id =
    if page_or_perma_id.respond_to?(:perma_id)
      page_or_perma_id.perma_id
    else
      page_or_perma_id
    end

  pretty_entry_url(entry, page: perma_id)
end