Module: RailsConnector::DisplayHelper

Included in:
DefaultCmsHelper
Defined in:
app/helpers/rails_connector/display_helper.rb

Overview

This module contains a helper that can be used to render attributes of the CMS models.

Instance Method Summary collapse

Instance Method Details

#display_field(obj, attr, options = {}) ⇒ Object

Renders a field from the CMS.

<%= display_field @obj, :title %>


39
40
41
# File 'app/helpers/rails_connector/display_helper.rb', line 39

def display_field(obj, attr, options = {})
  display_value obj[attr]
end

#display_value(value) ⇒ Object

For a consistent look of your site and easy maintenance, only the display helpers should be used to render an attribute value of a CMS model.

<%= display_value @obj.title %>

Renders the value, taking its type into account.

  • An HtmlString will be exported by converting its links

  • A Time will be exported in an international form: Year-Month-Day Hour:Minutes

  • A non-HTML String will be quoted

  • other values will be rendered unchanged


18
19
20
21
22
23
24
25
# File 'app/helpers/rails_connector/display_helper.rb', line 18

def display_value(value)
  case value
    when HtmlString then convert_links(value).html_safe
    when String then h(value)
    when Time then h(l(value))
    else value
  end
end