Module: Blogit::ApplicationHelper
- Defined in:
- app/helpers/blogit/application_helper.rb
Instance Method Summary collapse
-
#actions(content_or_options = {}, options = {}, &block) ⇒ Object
A helper method for creating a div tag with class ‘actions’.
-
#errors_on(object, attribute) ⇒ Object
The first error message for an ActiveRecord::Base model instance attribute.
-
#field(content_or_options = {}, options = {}, &block) ⇒ Object
A helper method for creating a div tag with class ‘field’.
-
#format_content(content = nil, &block) ⇒ Object
Format content using the default_parser_class.
Instance Method Details
#actions(content_or_options = {}, options = {}, &block) ⇒ Object
A helper method for creating a div tag with class ‘actions’. Used as a wrapper for form actions.
content_or_options - The content to include in the div when not using a block. The
options Hash when using a block
options - 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(={}, ={}, &block) div_tag_with_default_class("actions", , , &block) end |
#errors_on(object, attribute) ⇒ Object
The first error message for an ActiveRecord::Base model instance attribute
object - An ActiveRecord::Base instance to check attribute - A Symbol or String with the attribute name to check errors on
Examples
errors_on(@user, :first_name)
# => "Can't be blank"
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) = object.errors[attribute].first content_tag(:span, , class: "blogit_error_message") if end |
#field(content_or_options = {}, options = {}, &block) ⇒ Object
A helper method for creating a div tag with class ‘field’. Used for separating form fields.
content_or_options - The content to include in the div when not using a block. The
options Hash when using a block
options - 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( = {}, ={}, &block) div_tag_with_default_class("field", , , &block) end |
#format_content(content = nil, &block) ⇒ Object
Format content using the default_parser_class
content - A String containing the content to be formatted (defaults: nil) block - A Proc that returns a String of content to be formatted
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>"
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 |