Module: RailsBlogEngine::ApplicationHelper

Defined in:
app/helpers/rails_blog_engine/application_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Intercept calls to our containing application’s helpers, and explain to our caller how to make them work.



53
54
55
56
57
58
59
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 53

def method_missing(name, *args, &block)
  if app_helpers.respond_to?(name)
    raise "Please call #{name} as app_helpers.#{name}"
  else
    super(name, *args, &block)
  end
end

Instance Method Details

#app_helpersObject

Returns an object providing the standard application helpers for our containing application. This is necessary when we are rendered using an application-wide layout from inside an engine-specific controller, which normally makes it impossible to access the application’s helper methods.



44
45
46
47
48
49
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 44

def app_helpers
  @app_helpers ||= Class.new do
    include Rails.application.routes.url_helpers
    include ::ApplicationHelper
  end.new
end

#blog_page(&block) ⇒ Object

Wrap a block of content up as a blog page. This is basically a nested layout with some wrapper classes and a sidebar.



5
6
7
8
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 5

def blog_page(&block)
  content_for(:rails_blog_engine_content, &block)
  render :partial => 'layouts/rails_blog_engine/blog_page'
end

#comment_author_html(comment) ⇒ Object

Generate HTML describing the author of a comment.



31
32
33
34
35
36
37
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 31

def comment_author_html(comment)
  if comment.author_url && !comment.author_url.blank?
    link_to comment., comment.author_url, :rel => "nofollow"
  else
    comment.
  end
end

#comment_classes(comment) ⇒ Object

Get extra HTML classes for the specified comment.



26
27
28
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 26

def comment_classes(comment)
  comment.state.sub(/\A(filtered|marked)_as_/, '')
end

#feed_urlObject

The URL of our Atom feed. Rails refuses to generate this in any simple fashion, so we do it manually.



21
22
23
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 21

def feed_url
  blog_url + "posts.atom"
end

#markdown(md_text, options = {}) ⇒ Object

Process a block of text as Markdown, using our filters, and sanitize any usafe HTML. You can pass :trusted? => true to allow images and links without nofollow.



13
14
15
16
17
# File 'app/helpers/rails_blog_engine/application_helper.rb', line 13

def markdown(md_text, options={})
  config = sanitize_config(options[:trusted?] || false)
  filtered = Filters.apply_all_to(md_text)
  Sanitize.clean(RDiscount.new(filtered, :smart).to_html, config).html_safe
end