Module: Cms::PageHelper

Includes:
DeprecatedBehavior
Defined in:
app/helpers/cms/page_helper.rb

Constant Summary collapse

PAGE_TOOLBAR_HEIGHT =

Keep this taller until we reverse the iframes (so menus will work)

159
TOOLBAR_HEIGHT =
100

Instance Method Summary collapse

Methods included from DeprecatedBehavior

#cms_toolbar, #deprecated_set_page_title_usage

Instance Method Details

#able_to?(*perms, &block) ⇒ Boolean

Determines if the current_user is able to do specific permissions.

Returns:

  • (Boolean)


159
160
161
162
# File 'app/helpers/cms/page_helper.rb', line 159

def able_to?(*perms, &block)
  block.call if current_user.able_to?(*perms)
  return ''
end

#cms_content_editorString

Return the JS file to load the configured default WYSIWYG editor

Ideally, this could be improved if sprockets allows for dynamically determining which js library to use.

Returns:

  • (String)

    Names of the JS file needed to load the editor.



30
31
32
# File 'app/helpers/cms/page_helper.rb', line 30

def cms_content_editor
  "bcms/#{Cms.content_editor}"
end

#container(name) ⇒ String

Outputs the content of a particular container. If the user is in ‘edit’ mode the container and block controls will be rendered.

Returns:

  • (String)

    The HTML content for the container.



81
82
83
84
85
86
87
88
# File 'app/helpers/cms/page_helper.rb', line 81

def container(name)
  content = content_for(name)
  if is_current_user_able_to_edit_this_content?(@page)
    render :partial => 'cms/pages/simple_container', :locals => {:name => name, :content => content, :container => name}
  else
    content
  end
end

#container_has_block?(name, &block) ⇒ Boolean

Determine if a given container has any blocks within it. Useful for determine if markup should be conditionally included when a block is present, but not shown if no block was added. For example:

<% unless container_has_block? :sidebar %>

<div id="sidebar">
<%= container :sidebar %>
</div>

<% end %>

Parameters:

  • name (Symbol)

    The name of the container to check

  • block (Proc)

Returns:

  • (Boolean)

    True if the container has one or more blocks, or if we are in edit mode. False otherwise.



102
103
104
105
106
107
108
109
110
# File 'app/helpers/cms/page_helper.rb', line 102

def container_has_block?(name, &block)
  has_block = (edit_mode?) || current_page.connectable_count_for_container(name) > 0
  logger.info "mode = #{@mode}, has_block = #{has_block}"
  if block_given?
    concat(capture(&block)) if has_block
  else
    has_block
  end
end

#current_pageObject



73
74
75
# File 'app/helpers/cms/page_helper.rb', line 73

def current_page
  @page
end

#edit_mode?Boolean

Determines whether this page is in edit mode or not.

Returns:

  • (Boolean)


165
166
167
# File 'app/helpers/cms/page_helper.rb', line 165

def edit_mode?()
  @mode == "edit"
end

#page_headerObject

Returns the Page title in an In Context editable area.

Use for h1/h2 elements. Use page_title for title elements.



56
57
58
59
60
61
62
63
# File 'app/helpers/cms/page_helper.rb', line 56

def page_header()
  if (is_current_user_able_to_edit_this_content?(current_page))
    options = {id: 'page_title', contenteditable: true, data: {attribute: "title", content_name: "page", id: current_page.id, page_id: current_page.id}}
     "div", page_title, options
  else
    page_title
  end
end

#page_title(*args) ⇒ String

Outputs the title for this page. Used by both internal CMS pages, as well as page templates. Call use_page_title to change this value.

Parameters:

  • If (String)

    provided, this is the name of the page to set. (This usage is deprecated in 4.0 and will be removed in 4.1)

Returns:

  • (String)

    The title of the page.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/cms/page_helper.rb', line 39

def page_title(*args)
  if args.first
    deprecated_set_page_title_usage(args)
  else
    if @page_title
      @page_title
    elsif current_page
      current_page.page_title
    else
      "Untitled"
    end
  end
end

#render_breadcrumbs(options = {}) ⇒ Object

Renders breadcrumbs based on the current_page. This will generate an unordered list representing the current page and all it’s ancestors including the root name of of the site. The UL can be styled via CSS for layout purposes. Each breadcrumb except the last will be linked to the page in question.

If the current_page is nil, it will return an empty string.

Params:

options = A hash of options which determine how the breadcrumbs will be laid out.

Options:

  • :from_top - How many below levels from the root the tree should start at. All sections at this level will be shown. The default is 0, which means show all nodes that are direct children of the root.

  • :show_parent - Determines if the name of the page itself show be shown as a breadcrumb link. Defaults to false, meaning that the parent section of the current page will be the ‘last’ breadcrumb link. (Note: This probably better renamed as ‘show_page’).



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/helpers/cms/page_helper.rb', line 128

def render_breadcrumbs(options={})
  return "" unless current_page

  start = options[:from_top] || 0
  show_parent = options[:show_parent].nil? ? false : options[:show_parent]
  ancestors = current_page.ancestors
  items = []
  ancestors[start..ancestors.size].each_with_index do |sec, i|
    items << (:li,
                         link_to(sec.name, sec.actual_path), (i == 0 ? {:class => "first"} : {}))
  end
  if !show_parent && current_page.landing_page?
    items[items.size-1] = (:li, current_page.parent.name)
  else
    items << (:li, current_page.page_title)
  end
  (:ul, "\n  #{items.join("\n  ")}\n".html_safe, :class => "breadcrumbs")
end

#render_portlet(name) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'app/helpers/cms/page_helper.rb', line 147

def render_portlet(name)
  portlets = Portlet.all(:conditions => ["name = ?", name.to_s])
  if portlets.size > 1
    edit_mode? ? "ERROR: Multiple Portlets with name '#{name}'" : nil
  elsif portlets.empty?
    edit_mode? ? "ERROR: No Portlet with name '#{name}'" : nil
  else
    render_connectable(portlets.first)
  end
end

#use_page_title(title) ⇒ Object

Allows Views to set what will be displayed as the <title> element for Page Templates (and Cms admin pages.)



67
68
69
70
71
# File 'app/helpers/cms/page_helper.rb', line 67

def use_page_title(title)
  # Implementation note: This method is named use_page_title rather than page_title= because ruby will create a
  # local variable if you call <%= page_title = "A New Page Name" %>
  @page_title = title
end