Module: EffectivePostsHelper
- Defined in:
- app/helpers/effective_posts_helper.rb
Instance Method Summary collapse
- #admin_post_status_badge(post) ⇒ Object
- #effective_post_category_path(category, opts = nil) ⇒ Object
- #effective_post_category_url(category, opts = nil) ⇒ Object
- #effective_post_path(post, opts = nil) ⇒ Object
- #effective_posts_header_tags ⇒ Object
- #link_to_post_category(category, options = {}) ⇒ Object
-
#link_to_submit_post(label = 'Submit a post', options = {}) ⇒ Object
Submitting a Post.
-
#post_categories ⇒ Object
Post Categories.
-
#post_excerpt(post, label: 'Continue reading') ⇒ Object
All other options are passed to the link_to ‘Read more’.
- #post_meta(post, date: true, datetime: false, category: true, author: true) ⇒ Object
- #read_more_link(post, options = {}) ⇒ Object (also: #readmore_link)
-
#recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page) ⇒ Object
Recent News.
-
#recent_posts(user: current_user, category: nil, limit: EffectivePosts.per_page) ⇒ Object
Recent Posts.
- #render_post(post) ⇒ Object
- #render_post_categories(reverse: false) ⇒ Object
- #render_recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page) ⇒ Object
- #render_recent_posts(user: current_user, category: nil, limit: EffectivePosts.per_page) ⇒ Object
- #render_upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page) ⇒ Object
-
#upcoming_events(user: current_user, category: 'events', limit: EffectivePosts.per_page) ⇒ Object
Upcoming Events.
Instance Method Details
#admin_post_status_badge(post) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/effective_posts_helper.rb', line 71 def admin_post_status_badge(post) return nil unless EffectiveResources.(self, :admin, :effective_posts) if post.draft? content_tag(:span, 'DRAFT', class: 'badge badge-info') elsif post.published? == false content_tag(:span, "TO BE PUBLISHED AT #{post.published_at&.strftime('%F %H:%M') || 'LATER'}", class: 'badge badge-info') end end |
#effective_post_category_path(category, opts = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/effective_posts_helper.rb', line 31 def effective_post_category_path(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
48 49 50 |
# File 'app/helpers/effective_posts_helper.rb', line 48 def effective_post_category_url(category, opts = nil) root_url.to_s.chomp('/') + effective_post_category_path(category, opts) end |
#effective_post_path(post, opts = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/effective_posts_helper.rb', line 18 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_tags ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/effective_posts_helper.rb', line 5 def return unless @post && @post.kind_of?(Effective::Post) && @post.persisted? && @post.published? @effective_pages_og_type = 'article' = [ 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_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
52 53 54 55 |
# File 'app/helpers/effective_posts_helper.rb', line 52 def link_to_post_category(category, = {}) category = category.to_s.downcase link_to(category.to_s.titleize, effective_post_category_path(category), title: category.to_s.titleize) end |
#link_to_submit_post(label = 'Submit a post', options = {}) ⇒ Object
Submitting a Post
140 141 142 |
# File 'app/helpers/effective_posts_helper.rb', line 140 def link_to_submit_post(label = 'Submit a post', = {}) link_to(label, effective_posts.new_post_path, ) end |
#post_categories ⇒ Object
Post Categories
95 96 97 |
# File 'app/helpers/effective_posts_helper.rb', line 95 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’
82 83 84 |
# File 'app/helpers/effective_posts_helper.rb', line 82 def post_excerpt(post, label: 'Continue reading') (post.excerpt.to_s + readmore_link(post, label: label)).html_safe end |
#post_meta(post, date: true, datetime: false, category: true, author: true) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/effective_posts_helper.rb', line 61 def (post, date: true, datetime: false, category: true, author: true) [ 'Published', ("on #{post.published_at.strftime('%B %d, %Y')}" if date && post.published_at), ("on #{post.published_at.strftime('%B %d, %Y at %l:%M %p')}" if datetime && post.published_at), ("to #{link_to_post_category(post.category)}" if category && Array(EffectivePosts.categories).length > 1), ("by #{post.user.to_s.presence || 'Unknown'}" if && EffectivePosts. && post.user.present?) ].compact.join(' ').html_safe end |
#read_more_link(post, options = {}) ⇒ Object Also known as: readmore_link
86 87 88 89 90 |
# File 'app/helpers/effective_posts_helper.rb', line 86 def read_more_link(post, = {}) content_tag(:p, class: 'post-read-more') do link_to((.delete(:label) || 'Continue reading'), effective_post_path(post), (.delete(:class) || {class: ''}).reverse_merge()) end end |
#recent_news(user: current_user, category: 'news', limit: EffectivePosts.per_page) ⇒ Object
Recent News
116 117 118 119 |
# File 'app/helpers/effective_posts_helper.rb', line 116 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
105 106 107 108 |
# File 'app/helpers/effective_posts_helper.rb', line 105 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
57 58 59 |
# File 'app/helpers/effective_posts_helper.rb', line 57 def render_post(post) render(partial: 'effective/posts/post', locals: { post: post }) end |
#render_post_categories(reverse: false) ⇒ Object
99 100 101 |
# File 'app/helpers/effective_posts_helper.rb', line 99 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
121 122 123 124 |
# File 'app/helpers/effective_posts_helper.rb', line 121 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
110 111 112 113 |
# File 'app/helpers/effective_posts_helper.rb', line 110 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
134 135 136 137 |
# File 'app/helpers/effective_posts_helper.rb', line 134 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
128 129 130 131 132 |
# File 'app/helpers/effective_posts_helper.rb', line 128 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 |