Module: EffectivePostsHelper

Defined in:
app/helpers/effective_posts_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_post_status_badge(post) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/effective_posts_helper.rb', line 89

def admin_post_status_badge(post)
  return nil unless EffectiveResources.authorized?(self, :admin, :effective_posts)

  if post.archived?
    (:span, 'ARCHIVED', class: 'badge badge-info')
  elsif post.draft?
    (:span, 'DRAFT', class: 'badge badge-info')
  elsif post.published? == false
    (:span, "TO BE PUBLISHED AT #{post.published_start_at&.strftime('%F %H:%M') || 'LATER'}", class: 'badge badge-info')
  end
end

#badge_to_post_category(category, options = {}) ⇒ Object



72
73
74
75
# File 'app/helpers/effective_posts_helper.rb', line 72

def (category, options = {})
  category = category.to_s.downcase
  link_to(category.to_s.titleize, (category), title: category.to_s.titleize, class: "badge badge-primary badge-post mb-2 effective-posts-#{category.parameterize}")
end

#effective_post_category_path(category, opts = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/effective_posts_helper.rb', line 46

def (category, opts = nil)
  return effective_posts.posts_path(opts || {}) unless category.present?

  category = category.to_s
  category_path = category.to_s.downcase.parameterize
  opts = (opts || {}).compact
  query = ('?' + opts.to_query) if opts.present?

  if EffectivePosts.use_blog_routes
    "/blog/category/#{category_path}#{query}"
  elsif EffectivePosts.use_category_routes
    "/#{category_path}#{query}"
  else
    effective_posts.posts_path(opts.merge(category: category.presence).compact)
  end
end

#effective_post_category_url(category, opts = nil) ⇒ Object



63
64
65
# File 'app/helpers/effective_posts_helper.rb', line 63

def (category, opts = nil)
  root_url.to_s.chomp('/') + (category, opts)
end

#effective_post_path(post, opts = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/effective_posts_helper.rb', line 33

def effective_post_path(post, opts = nil)
  category = post.category.to_s.downcase.parameterize
  opts ||= {}

  if EffectivePosts.use_blog_routes
    effective_posts.post_path(post, opts)
  elsif EffectivePosts.use_category_routes
    effective_posts.post_path(post, opts).sub('/posts', "/#{category}")
  else
    effective_posts.post_path(post, opts.merge(category: category))
  end
end

#effective_posts_header_tagsObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/effective_posts_helper.rb', line 20

def effective_posts_header_tags
  return unless @post && @post.kind_of?(Effective::Post) && @post.persisted? && @post.published?

  @effective_pages_og_type = 'article'

  tags = [
    tag(:meta, itemprop: 'author', content: @post.user.to_s),
    tag(:meta, itemprop: 'publisher', content: @post.user.to_s),
    tag(:meta, itemprop: 'datePublished', content: (@post.published_start_at || Time.zone.now).strftime('%FT%T%:z')),
    tag(:meta, itemprop: 'headline', content: @post.title)
  ].join("\n").html_safe
end

#link_to_post_category(category, options = {}) ⇒ Object



67
68
69
70
# File 'app/helpers/effective_posts_helper.rb', line 67

def (category, options = {})
  category = category.to_s.downcase
  link_to(category.to_s.titleize, (category), title: category.to_s.titleize)
end

#link_to_submit_post(label = 'Submit a post', options = {}) ⇒ Object

Submitting a Post



161
162
163
# File 'app/helpers/effective_posts_helper.rb', line 161

def link_to_submit_post(label = 'Submit a post', options = {})
  link_to(label, effective_posts.new_post_path, options)
end

#post_categoriesObject

Post Categories



116
117
118
# File 'app/helpers/effective_posts_helper.rb', line 116

def post_categories
  categories = EffectivePosts.categories
end

#post_excerpt(post, label: 'Continue reading') ⇒ Object

All other options are passed to the link_to ‘Read more’



102
103
104
105
# File 'app/helpers/effective_posts_helper.rb', line 102

def post_excerpt(post, label: 'Continue reading')
  content = post.excerpt.presence || post.body.presence
  (content.to_s + readmore_link(post, label: label)).html_safe
end

#post_labelObject

Post



11
12
13
# File 'app/helpers/effective_posts_helper.rb', line 11

def 
  et(Effective::Post)
end

#post_meta(post, date: true, datetime: false, category: true, author: true) ⇒ Object



81
82
83
84
85
86
87
# File 'app/helpers/effective_posts_helper.rb', line 81

def (post, date: true, datetime: false, category: true, author: true)
  [
    ("#{post.published_start_at.strftime('%A, %B %d, %Y')}" if date && post.published_start_at),
    ("#{post.published_start_at.strftime('%A, %B %d, %Y · %l:%M%P')}" if datetime && post.published_start_at),
    ("#{post.user.to_s.presence || 'Unknown'}" if author && EffectivePosts. && post.user.present?)
  ].compact.join(' ').html_safe
end

#posts_labelObject

Posts



16
17
18
# File 'app/helpers/effective_posts_helper.rb', line 16

def posts_label
  ets(Effective::Post)
end

#posts_name_labelObject

Posts



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

def posts_name_label
  et('effective_posts.name')
end


107
108
109
110
111
# File 'app/helpers/effective_posts_helper.rb', line 107

def read_more_link(post, options = {})
  (:p, class: 'post-read-more') do
    link_to((options.delete(:label) || 'Continue reading'), effective_post_path(post), (options.delete(:class) || {class: ''}).reverse_merge(options))
  end
end

#recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page) ⇒ Object

Recent News



137
138
139
140
# File 'app/helpers/effective_posts_helper.rb', line 137

def recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page)
  @recent_news ||= {}
  @recent_news[category] ||= Effective::Post.posts(user: user, category: category).limit(limit)
end

#recent_posts(user: current_user, category: nil, limit: EffectivePosts.per_page) ⇒ Object

Recent Posts



126
127
128
129
# File 'app/helpers/effective_posts_helper.rb', line 126

def recent_posts(user: current_user, category: nil, limit: EffectivePosts.per_page)
  @recent_posts ||= {}
  @recent_posts[category] ||= Effective::Post.posts(user: user, category: category).limit(limit)
end

#render_post(post) ⇒ Object



77
78
79
# File 'app/helpers/effective_posts_helper.rb', line 77

def render_post(post)
  render(partial: 'effective/posts/post', locals: { post: post })
end

#render_post_categories(reverse: false) ⇒ Object



120
121
122
# File 'app/helpers/effective_posts_helper.rb', line 120

def render_post_categories(reverse: false)
  render(partial: '/effective/posts/categories', locals: { categories: (reverse ? post_categories.reverse : post_categories) })
end

#render_recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page) ⇒ Object



142
143
144
145
# File 'app/helpers/effective_posts_helper.rb', line 142

def render_recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page)
  posts = recent_news(user: user, category: category, limit: limit)
  render partial: '/effective/posts/recent_posts', locals: { posts: posts }
end

#render_recent_posts(user: current_user, category: nil, limit: EffectivePosts.per_page) ⇒ Object



131
132
133
134
# File 'app/helpers/effective_posts_helper.rb', line 131

def render_recent_posts(user: current_user, category: nil, limit: EffectivePosts.per_page)
  posts = recent_posts(user: user, category: category, limit: limit)
  render partial: '/effective/posts/recent_posts', locals: { posts: posts }
end

#render_upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page) ⇒ Object



155
156
157
158
# File 'app/helpers/effective_posts_helper.rb', line 155

def render_upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page)
  posts = upcoming_events(user: user, category: category, limit: limit)
  render partial: '/effective/posts/upcoming_events', locals: { posts: posts }
end

#upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page) ⇒ Object

Upcoming Events



149
150
151
152
153
# File 'app/helpers/effective_posts_helper.rb', line 149

def upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page)
  @upcoming_events ||= {}
  @upcoming_events[category] ||= Effective::Post.posts(user: user, category: category).limit(limit)
    .reorder(:start_at).where('start_at > ?', Time.zone.now)
end