Module: Blogical::Helpers

Included in:
Application
Defined in:
app/blogical/helpers.rb

Class Method Summary collapse

Class Method Details

.included(app) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/blogical/helpers.rb', line 6

def self.included(app)
  app.helpers do
    include Rack::Utils
    alias_method :h, :escape_html

    def markup(string)
      RDiscount::new(string, :smart).to_html
    end

    def tags(post)
      return '' unless post
      tag_names = post.tags.collect { |tag| tag.name }
      ", #{tag_names.join(', ')}"
    end

    def url(path)
      request.script_name + path
    end

    def body_id
      b_id = request.path_info.split('/')[1] || 'home'
      b_id.to_i == 0 ? b_id : 'blog' # numerical paths are considered blog posts
    end

    def current_page?(page_number)
      Integer(params['page']) == page_number
    end
  end

  super
end