Module: Blogit::ApplicationHelper

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

Constant Summary

TIMETAG_FORMAT =
"%Y-%m-%dT%TZ"

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)

Can search for named routes directly in the main app, omitting the "main_app." prefix



62
63
64
65
66
67
68
# File 'app/helpers/blogit/application_helper.rb', line 62

def method_missing method, *args, &block
  if main_app_url_helper?(method)
    main_app.send(method, *args)
  else
    super
  end
end

Instance Method Details

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

A helper method for creating a <div> tag with class 'actions' Used for option links and form buttons



30
31
32
# File 'app/helpers/blogit/application_helper.rb', line 30

def actions(content_or_options={}, options ={}, &block)
  div_with_default_class(:actions, content_or_options, options, &block)
end

- (Object) errors_on(object, attribute)

Returns the first error message for an ActiveRecord model instance

Parameters:

  • object

    A model instance to check

  • attribute

    A symbol or string for attribute name to check for errors



17
18
19
20
# File 'app/helpers/blogit/application_helper.rb', line 17

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



24
25
26
# File 'app/helpers/blogit/application_helper.rb', line 24

def field(content_or_options={}, options ={}, &block)
  div_with_default_class(:field, content_or_options, options, &block)
end

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

Format content using the default_parser_class



7
8
9
10
11
# File 'app/helpers/blogit/application_helper.rb', line 7

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

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

A helper method for creating a <div> tag with class 'login_required' Will only render content if there is a logged in user



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

def (content_or_options={}, options ={}, &block)
  if current_blogger and blogit_conf.include_admin_links
    div_with_default_class(:login_required, content_or_options, options, &block)
  end
end

- (Boolean) respond_to?(method)

Returns:

  • (Boolean)


69
70
71
# File 'app/helpers/blogit/application_helper.rb', line 69

def respond_to?(method)
  main_app_url_helper?(method) or super
end

- (Object) time_tag(time_object, format = nil, options = {})

Returns an HTML 5 time tag

Parameters:

  • time_object

    Any Time or DateTime object

  • format (String, Symbol) (defaults to: nil)

    If passed a string will treat as a strftime format. If passed a symbol will treat as pre-set datetime format.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/blogit/application_helper.rb', line 46

def time_tag(time_object, format = nil, options ={})
  # if there's a specified format and it's a string, assume it's an strftime string
  if format && format.is_a?(String)
    time_string = time_object.strftime(format)
    # if there's a specified format and it's a symbol, assume it's a predefined format
  elsif format && format.is_a?(Symbol)
    time_string = I18n.localize(time_object, format: format)
  else
    time_string = time_object.to_s
  end
  options.merge(datetime: time_object.strftime(TIMETAG_FORMAT))
  (:time, time_string, options)
end