Module: Blogit::ApplicationHelper

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

Instance Method Summary (collapse)

Instance Method Details

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

A helper method for creating a div tag with class 'actions'. Used as a wrapper for form actions.

Parameters:

  • content_or_options (defaults to: {})

    The content to include in the div when not using a block. The options Hash when using a block

  • options (defaults to: {})

    The options when not using a block

  • block

    A block that returns HTML content to include in the div

Returns:

  • an HTML safe String


64
65
66
# File 'app/helpers/blogit/application_helper.rb', line 64

def actions(content_or_options={}, options ={}, &block)
  div_tag_with_default_class("actions", content_or_options, options, &block)
end

- (Object) errors_on(object, attribute)

The first error message for an ActiveRecord::Base model instance attribute

Examples:

errors_on(@user, :first_name)
# => "Can't be blank"

Parameters:

  • object

    An ActiveRecord::Base instance to check

  • attribute

    A Symbol or String with the attribute name to check errors on

Returns:

  • a String with the error message


37
38
39
40
# File 'app/helpers/blogit/application_helper.rb', line 37

def errors_on(object, attribute)
  error_message = object.errors[attribute].first
  (:span, error_message, class: "blogit_error_message") if error_message
end

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

A helper method for creating a div tag with class 'field'. Used for separating form fields.

Parameters:

  • content_or_options (defaults to: {})

    The content to include in the div when not using a block. The options Hash when using a block

  • options (defaults to: {})

    The options when not using a block

  • block

    A block that returns HTML content to include in the div

Returns:

  • an HTML safe String


51
52
53
# File 'app/helpers/blogit/application_helper.rb', line 51

def field(content_or_options = {}, options ={}, &block)
  div_tag_with_default_class("field", content_or_options, options, &block)
end

- (Object) format_content(content = nil, &block)

Format content using the default_parser_class

Examples:

format_content("# This is a Markdown header")
# => "<h1>This is a Markdown header</h1>"
format_content do 
  "some text"
end
# => "<p>some text</p>"

Parameters:

  • content (defaults to: nil)

    A String containing the content to be formatted (defaults: nil)

  • block

    A Proc that returns a String of content to be formatted

Returns:

  • an HTML safe String.


20
21
22
23
24
# File 'app/helpers/blogit/application_helper.rb', line 20

def format_content(content = nil, &block)
  content = capture(&block) if block_given?
  parser  = Blogit::configuration.default_parser_class.new(content)
  parser.parsed.to_s.html_safe
end