Module: Blogit::PostsHelper

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) blog_post_tag(name, content_or_options = {}, options = {}, &block)

Creates a div tag with class 'blog_post_' + name Eg:

(:title, "") # => <div class="blog_post_title"></div>


7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/blogit/posts_helper.rb', line 7

def (name, content_or_options = {}, options ={}, &block)
  if block_given?
    content = capture(&block)
    options = content_or_options
  else
    content = content_or_options
  end
  options[:class] = "#{options[:class]} blog_post_#{name}".strip
  (name, content, options)
end

- (Object) blog_posts_archive_tag(year_css, month_css, post_css, archive_posts = Post.all)

Creates a ul tag tree with posts by year and monthes. Include blogit/archive.js to enabled expand collapse.

Parameters:

  • year_css (String, Symbol)

    The CSS class of the year UL tag

  • month_css (String, Symbol)

    The CSS class of the month UL tag

  • post_css (String, Symbol)

    The CSS class of the year LI tag

  • archive_posts (ActiveRecord::Relation, Array) (defaults to: Post.all)

    The posts to be included in the archive (defaults to Post.all)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/blogit/posts_helper.rb', line 38

def blog_posts_archive_tag(year_css, month_css, post_css, archive_posts = Post.all)
  posts_tree = archive_posts.chunk {|post| post.created_at.year}.map do |year, posts_of_year|
    [year, posts_of_year.chunk {|post| l(post.created_at, format: :plain_month_only) }]
  end

  result = []
  result << "<ul class=\"#{year_css}\">"
  posts_tree.each do |year, posts_by_month|
    result << "<li><a data-blogit-click-to-toggle-children>#{year}</a><ul class=\"#{month_css}\">"
    posts_by_month.each do |month, posts|
      result << "<li><a data-blogit-click-to-toggle-children>#{CGI.escape_html(month)}</a><ul class=\"#{post_css}\">"
      posts.each do |post|
        result << "<li><a href=\"#{blogit.post_path(post)}\">#{CGI.escape_html(post.title)}</a></li>"
      end
      result << "</ul></li>"
    end
    result << "</ul></li>"
  end
  result << "</ul>"

  result.join.html_safe
end

- (Object) comments_for(post)

A comments tag corresponding to the comments configuration



19
20
21
# File 'app/helpers/blogit/posts_helper.rb', line 19

def comments_for(post)
  render(partial: "blogit/posts/#{Blogit.configuration.include_comments}_comments", locals: { post: post, comment: Blogit::Comment.new })
end

- (Object) share_bar_for(post)

A share bar as configured



24
25
26
27
28
29
30
# File 'app/helpers/blogit/posts_helper.rb', line 24

def share_bar_for(post)
  if !Blogit.configuration.include_share_bar
    ""
  else
    render(partial: "blogit/posts/share_bar", locals: { post: post})
  end
end