Module: Mist::PostsHelper
- Defined in:
- app/helpers/mist/posts_helper.rb
Instance Method Summary collapse
- #admin_link_separator ⇒ Object
- #authorized?(type) ⇒ Boolean
- #authorized_link(type, *link_options) ⇒ Object
- #authorized_links(separator, *link_options) ⇒ Object
- #popular_posts(count = 5) ⇒ Object
- #recent_posts(count = 5) ⇒ Object
- #render_posts ⇒ Object
- #similar_posts(count = 5) ⇒ Object
Instance Method Details
#admin_link_separator ⇒ Object
14 15 16 |
# File 'app/helpers/mist/posts_helper.rb', line 14 def admin_link_separator ' • '.html_safe end |
#authorized?(type) ⇒ Boolean
18 19 20 |
# File 'app/helpers/mist/posts_helper.rb', line 18 def (type) Mist. type, controller end |
#authorized_link(type, *link_options) ⇒ Object
2 3 4 5 6 7 8 |
# File 'app/helpers/mist/posts_helper.rb', line 2 def (type, *) if type link_to * else "" end end |
#authorized_links(separator, *link_options) ⇒ Object
10 11 12 |
# File 'app/helpers/mist/posts_helper.rb', line 10 def (separator, *) .collect { |link_args| (*link_args) }.reject { |a| a.blank? }.join(separator).html_safe end |
#popular_posts(count = 5) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/mist/posts_helper.rb', line 46 def popular_posts(count = 5) # same as recent posts -- get twice as many and filter out the extras @popular_posts ||= {} @popular_posts[count] ||= begin result = Mist::Post.most_popular(count*2).select { |post| post.published? } result = result[0...count] if result.length > count result end end |
#recent_posts(count = 5) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/mist/posts_helper.rb', line 35 def recent_posts(count = 5) @recent_posts ||= {} @recent_posts[count] ||= begin # without SQL, we don't have access to conveniences like Post.where(:published), # so instead just find 2x count and return those that are published. result = Mist::Post.recently_published count*2 result = result[0...count] if result.length > count result end end |
#render_posts ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/mist/posts_helper.rb', line 22 def render_posts preview = false @posts.collect { |post| if post.published? || (:view_drafts) render(:partial => 'post', :locals => { :post => post, :preview => preview }).tap do preview = true end else "" end }.join.html_safe end |
#similar_posts(count = 5) ⇒ Object
56 57 58 59 60 |
# File 'app/helpers/mist/posts_helper.rb', line 56 def similar_posts(count = 5) return [] if @post.nil? @similar_posts ||= {} @similar_posts[count] ||= @post.similar_posts(count) end |