Module: EffectivePostsHelper
- Defined in:
- app/helpers/effective_posts_helper.rb
Instance Method Summary collapse
- #effective_post_path(post) ⇒ Object
- #link_to_post_category(category, options = {}) ⇒ Object
-
#post_excerpt(post, opts = {}) ⇒ Object
Only supported options are: :label => 'Read more' to set the label of the 'Read More' link :omission => '...' passed to the final text node's truncate :length => 200 to set the max inner_text length of the content All other options are passed to the link_to 'Read more'.
- #post_meta(post) ⇒ Object
- #readmore_link(post, options) ⇒ Object
- #render_post(post) ⇒ Object
Instance Method Details
#effective_post_path(post) ⇒ Object
57 58 59 60 |
# File 'app/helpers/effective_posts_helper.rb', line 57 def effective_post_path(post) category = post.category.to_s.downcase EffectivePosts.use_category_routes ? "/#{category}/#{post.to_param}" : effective_posts.post_path(post, category: category.to_s) end |
#link_to_post_category(category, options = {}) ⇒ Object
50 51 52 53 54 55 |
# File 'app/helpers/effective_posts_helper.rb', line 50 def link_to_post_category(category, = {}) category = category.to_s.downcase href = EffectivePosts.use_category_routes ? "/#{category}" : effective_posts.posts_path(category: category.to_s) link_to(category.to_s.titleize, href, ) end |
#post_excerpt(post, opts = {}) ⇒ Object
Only supported options are: :label => 'Read more' to set the label of the 'Read More' link :omission => '...' passed to the final text node's truncate :length => 200 to set the max inner_text length of the content All other options are passed to the link_to 'Read more'
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/effective_posts_helper.rb', line 22 def post_excerpt(post, opts = {}) content = effective_region(post, :content, :editable => false) { '<p>Default content</p>'.html_safe } = { :label => 'Read more', :omission => '...', :length => 200 }.merge(opts) divider = content.index(Effective::Snippets::ReadMoreDivider::TOKEN) length = .delete(:length) omission = .delete(:omission) CGI.unescapeHTML(if divider.present? truncate_html(content, Effective::Snippets::ReadMoreDivider::TOKEN, '') + readmore_link(post, ) elsif length.present? truncate_html(content, length, omission) + readmore_link(post, ) else content end).html_safe end |
#post_meta(post) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/helpers/effective_posts_helper.rb', line 8 def (post) [ 'Published', "on #{post.published_at.strftime('%B %d, %Y at %l:%M %p')}", ("to #{link_to_post_category(post.category)}" if Array(EffectivePosts.categories).length > 1), ("by #{post.user.to_s.presence || 'Unknown'}" if EffectivePosts.) ].compact.join(' ').html_safe end |
#readmore_link(post, options) ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/effective_posts_helper.rb', line 44 def readmore_link(post, ) content_tag(:p, class: 'post-read-more') do link_to((.delete(:label) || 'Read more'), effective_posts.post_path(post), ) end end |
#render_post(post) ⇒ Object
4 5 6 |
# File 'app/helpers/effective_posts_helper.rb', line 4 def render_post(post) render(partial: 'effective/posts/post', locals: { post: post }) end |