Module: Cms::PageHelper

Included in:
ApplicationController
Defined in:
app/helpers/cms/page_helper.rb

Instance Method Summary collapse

Instance Method Details

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

Determines if the current_user is able to do specific permissions.

Returns:

  • (Boolean)


99
100
101
# File 'app/helpers/cms/page_helper.rb', line 99

def able_to?(*perms, &block)
  yield if current_user.able_to?(*perms)
end

#cms_toolbarObject



46
47
48
# File 'app/helpers/cms/page_helper.rb', line 46

def cms_toolbar
  instance_variable_get("@content_for_layout")
end

#container(name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'app/helpers/cms/page_helper.rb', line 15

def container(name)
  content = instance_variable_get("@content_for_#{name}")
  if logged_in? && @page && @mode == "edit" && current_user.able_to_edit?(@page)
    render :partial => 'cms/pages/edit_container', :locals => {:name => name, :content => content}
  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.



36
37
38
39
40
41
42
43
44
# File 'app/helpers/cms/page_helper.rb', line 36

def container_has_block?(name, &block)
  has_block = (@mode == "edit") || 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



11
12
13
# File 'app/helpers/cms/page_helper.rb', line 11

def current_page
  @page
end

#page_title(*args) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/cms/page_helper.rb', line 3

def page_title(*args)
  if args.first
    @controller.instance_variable_get("@template").instance_variable_set("@page_title", args.first)
  else
    @controller.instance_variable_get("@template").instance_variable_get("@page_title")
  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’).



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/cms/page_helper.rb', line 67

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(h(sec.name), sec.actual_path), 
      (i == 0 ? {:class => "first"} : {}))
  end
  if !show_parent && current_page.section.path == current_page.path
    items[items.size-1] = (:li, h(current_page.section.name))
  else
    items << (:li, h(current_page.page_title))
  end
  (:ul, "\n  #{items.join("\n  ")}\n", :class => "breadcrumbs")
end

#render_portlet(name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'app/helpers/cms/page_helper.rb', line 87

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