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, including an edit marker for the preview If the option :marker is false, no edit marker will be rendered.

<%= display_field @obj, :title %>

When creating an edit marker, all options except :marker are passed to MarkerHelper#edit_marker.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/rails_connector/display_helper.rb', line 43

def display_field(obj, attr, options = {})
  options.reverse_merge!({
    :marker => ![:id, :path, :created, :last_changed, :version].include?(attr.to_sym)
    })
  if options.delete :marker
    edit_marker(obj, attr, options) do |obj, attr|
      display_value obj[attr]
    end
  else
    display_value obj[attr]
  end
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
26
# File 'app/helpers/rails_connector/display_helper.rb', line 18

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