Module: Virgo::PostHelper

Defined in:
app/helpers/virgo/post_helper.rb

Instance Method Summary collapse

Instance Method Details

#featured_post_text(post, opts = {}) ⇒ Object


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/virgo/post_helper.rb', line 87

def featured_post_text(post, opts={})
  if post.excerpt.present? && post.show_excerpt?
    html = "
      <div class='featured-post-excerpt'>
        #{truncate post.excerpt, length: 414}
    "

    if opts[:read_more] != false
      html += "#{link_to "Read More", post_detail_path(post), class: 'read-more-link'}"
    end

    html += "</div>"

    html.html_safe
  else
    "".html_safe
  end
end

#post_banner_image_url(post) ⇒ Object


138
139
140
141
142
# File 'app/helpers/virgo/post_helper.rb', line 138

def post_banner_image_url(post)
  if post.show_feature_image_on_post_page
    post.featured_image.try(:image).try(:url, :wide)
  end
end

#post_byline(post, opts = {}) ⇒ Object


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/virgo/post_helper.rb', line 69

def (post, opts={})
  html = "
    <div class='post-byline'>
      <span class='post-by'>By</span> "

  unless opts[:no_links]
    html += link_to(post.author.pretty_name, user_path(post.author), class: 'post-author-link')
  else
    html += "<span class='post-author-name'>#{post.author.pretty_name}</span>"
  end

  html += "<span class='bullet'>&bull;</span>
    <span class='post-date'>#{local_time (post.publish_at || post.created_at), post_time_format}</span>
  </div>"

 html.html_safe
end

#post_categories(post) ⇒ Object


17
18
19
# File 'app/helpers/virgo/post_helper.rb', line 17

def post_categories(post)
  post.categories.map(&:name).join(", ")
end

#post_category_label(post) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/virgo/post_helper.rb', line 53

def (post)
  if post.categories.any?
    category = post.categories.order(navbar_weight: :asc).first

    html = "
      <div class='category-label'>
        <span class='category-name'>#{category.name}</span>
      </div>
    "

    html.html_safe
  else
    ""
  end
end

#post_excerpt(post) ⇒ Object


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/helpers/virgo/post_helper.rb', line 119

def post_excerpt(post)
  if post.excerpt.present? && post.show_excerpt?
    "
      <div class='post-body post-excerpt'>
        #{post.excerpt}
        <div class='read-more-link-wrap'>
        #{link_to "Read More", post_detail_path(post), class: 'read-more-link'}
        </div>
      </div>
    ".html_safe
  else
    "
      <div class='post-body'>
        #{truncate_post_to_read_more(post)}
      </div>
    ".html_safe
  end
end

#post_permalink_url(post) ⇒ Object


144
145
146
# File 'app/helpers/virgo/post_helper.rb', line 144

def post_permalink_url(post)
  virgo.post_detail_url(post, protocol: 'https')
end

#post_status_label(post) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/virgo/post_helper.rb', line 3

def post_status_label(post)
  if post.draft?
    "<span class='label label-danger'>Draft</span>".html_safe
  elsif post.assigned?
    "<span class='label label-info'>Assigned</span>".html_safe
  elsif post.published?
    "<span class='label label-primary'>Published</span>".html_safe
  elsif post.killed?
    "<span class='label label-danger'>Hidden</span>".html_safe
  elsif post.hidden?
    "<span class='label label-warning'>Hidden</span>".html_safe
  end
end

#post_tag(post) ⇒ Object


106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/virgo/post_helper.rb', line 106

def (post)
  if post.tags.any?
    tag = post..by_position.first.tag
    "
      <div class='post-tag'>
        <span class='post-tag-text'>#{tag.name}</span>
      </div>
    ".html_safe
  else
    ""
  end
end

#post_tags(post) ⇒ Object


21
22
23
# File 'app/helpers/virgo/post_helper.rb', line 21

def (post)
  post.tags.map(&:name).join(", ")
end

#rss_post(xml, post) ⇒ Object


149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/helpers/virgo/post_helper.rb', line 149

def rss_post(xml, post)
  xml.item {
    xml.guid(post.uuid)
    xml.pubDate(post.publish_at.to_s(:rfc822))
    xml.title(post.headline)
    xml.author(post.author.)
    xml.link(post_permalink_url(post))
    xml.description(post.rendered_body)

    if post.featured_image
      xml.tag!("media:content", {"url" => post.thumb_image.image.url(:email), "medium" => "image"})
    end
  }
end

#truncate_post_to_read_more(post, opts = {}) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/virgo/post_helper.rb', line 25

def truncate_post_to_read_more(post, opts={})
  include_link = true if opts[:link].nil?

  text = post.rendered_body

  idx = text.index("[read-more]")

  if opts[:length]
    if idx.nil? || (opts[:length] < idx)
      return truncate(strip_tags(text), length: opts[:length])
    end
  end

  if idx
    result = text[0..(idx-1)] + "<span class='ellipse'>...</span>"

    if include_link
      result += "<div class='read-more-link-wrap'>"
      result += link_to("Read More", post_detail_path(post), class: 'read-more-link')
      result += "</div>"
    end
  else
    result = text
  end

  result.html_safe
end