Module: Mist::PostsHelper

Defined in:
app/helpers/mist/posts_helper.rb

Instance Method Summary collapse

Instance Method Details



14
15
16
# File 'app/helpers/mist/posts_helper.rb', line 14

def admin_link_separator
  ' • '.html_safe
end

#authorized?(type) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/helpers/mist/posts_helper.rb', line 18

def authorized?(type)
  Mist.authorized? type, controller
end


2
3
4
5
6
7
8
# File 'app/helpers/mist/posts_helper.rb', line 2

def authorized_link(type, *link_options)
  if authorized? type
    link_to *link_options
  else
    ""
  end
end


10
11
12
# File 'app/helpers/mist/posts_helper.rb', line 10

def authorized_links(separator, *link_options)
  link_options.collect { |link_args| authorized_link(*link_args) }.reject { |a| a.blank? }.join(separator).html_safe
end


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_postsObject



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? || authorized?(: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