Module: Postview::Helpers
- Defined in:
- lib/postview/helpers.rb
Overview
Copyright © 2009 Hallison Batista
Instance Attribute Summary collapse
-
#all_archived_posts ⇒ Object
readonly
All archived posts.
-
#all_drafted_posts ⇒ Object
readonly
All archived posts.
-
#all_posts ⇒ Object
readonly
All posts.
-
#all_tags ⇒ Object
readonly
All tags used in posts and archived posts.
-
#archived_posts_found ⇒ Object
readonly
All archived posts found by search.
-
#current_post ⇒ Object
readonly
Current post.
-
#current_tag ⇒ Object
readonly
Current tag.
-
#error_message ⇒ Object
readonly
HTTP status error message.
-
#page ⇒ Object
readonly
Current page.
-
#posts_found ⇒ Object
readonly
All posts found by search.
-
#site ⇒ Object
readonly
Site information.
Instance Method Summary collapse
-
#all_related_tags ⇒ Object
Returns all tags related with a post tags.
-
#count_posts_by_tag(name) ⇒ Object
Count posts by tag name.
-
#latest_posts(limit = 5) ⇒ Object
Returns latest posts.
-
#related_posts_in(folder = :posts) ⇒ Object
Returns all posts related to any post.
-
#related_tags_in(folder = :posts) ⇒ Object
Returns all tags related with a post tags.
Instance Attribute Details
#all_archived_posts ⇒ Object (readonly)
All archived posts.
25 26 27 |
# File 'lib/postview/helpers.rb', line 25 def all_archived_posts @all_archived_posts end |
#all_drafted_posts ⇒ Object (readonly)
All archived posts.
28 29 30 |
# File 'lib/postview/helpers.rb', line 28 def all_drafted_posts @all_drafted_posts end |
#all_posts ⇒ Object (readonly)
All posts
22 23 24 |
# File 'lib/postview/helpers.rb', line 22 def all_posts @all_posts end |
#all_tags ⇒ Object (readonly)
All tags used in posts and archived posts.
19 20 21 |
# File 'lib/postview/helpers.rb', line 19 def @all_tags end |
#archived_posts_found ⇒ Object (readonly)
All archived posts found by search.
34 35 36 |
# File 'lib/postview/helpers.rb', line 34 def archived_posts_found @archived_posts_found end |
#current_post ⇒ Object (readonly)
Current post.
13 14 15 |
# File 'lib/postview/helpers.rb', line 13 def current_post @current_post end |
#current_tag ⇒ Object (readonly)
Current tag.
16 17 18 |
# File 'lib/postview/helpers.rb', line 16 def current_tag @current_tag end |
#error_message ⇒ Object (readonly)
HTTP status error message
37 38 39 |
# File 'lib/postview/helpers.rb', line 37 def @error_message end |
#page ⇒ Object (readonly)
Current page.
10 11 12 |
# File 'lib/postview/helpers.rb', line 10 def page @page end |
#posts_found ⇒ Object (readonly)
All posts found by search.
31 32 33 |
# File 'lib/postview/helpers.rb', line 31 def posts_found @posts_found end |
#site ⇒ Object (readonly)
Site information.
7 8 9 |
# File 'lib/postview/helpers.rb', line 7 def site @site end |
Instance Method Details
#all_related_tags ⇒ Object
Returns all tags related with a post tags.
67 68 69 70 71 |
# File 'lib/postview/helpers.rb', line 67 def (all_posts + all_archived_posts).reject do |post| (post. & current_post.).empty? end.map{ |post| post. }.flatten.uniq.sort end |
#count_posts_by_tag(name) ⇒ Object
Count posts by tag name.
74 75 76 77 78 79 80 |
# File 'lib/postview/helpers.rb', line 74 def count_posts_by_tag(name) @count_posts_by_tag ||= .inject({}) do |count, tag| count[tag] = (all_posts + all_archived_posts).count{ |post| post..include? tag } count end @count_posts_by_tag[name] end |
#latest_posts(limit = 5) ⇒ Object
Returns latest posts.
40 41 42 |
# File 'lib/postview/helpers.rb', line 40 def latest_posts(limit = 5) @all_posts.limit(limit) || [] end |
#related_posts_in(folder = :posts) ⇒ Object
Returns all posts related to any post.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/postview/helpers.rb', line 45 def (folder = :posts) posts = case folder when :posts all_posts when :archive all_archived_posts when :drafts all_drafted_posts else return nil end posts.reject do |post| (post. & current_post.).empty? || post == current_post end end |
#related_tags_in(folder = :posts) ⇒ Object
Returns all tags related with a post tags.
62 63 64 |
# File 'lib/postview/helpers.rb', line 62 def (folder = :posts) ((folder) << current_post).map{ |post| post. }.flatten.uniq.sort end |