Module: Cms::PageHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/cms/page_helper.rb
Instance Method Summary collapse
-
#able_to?(*perms, &block) ⇒ Boolean
Determines if the current_user is able to do specific permissions.
-
#cms_content_editor ⇒ Array
Return the JS file to load the configured default WYSIWYG editor.
-
#cms_toolbar ⇒ Object
Add the code to render the CMS toolbar.
-
#container(name) ⇒ String
Outputs the content of a particular container.
-
#container_has_block?(name, &block) ⇒ Boolean
Determine if a given container has any blocks within it.
- #current_page ⇒ Object
-
#page_title(*args) ⇒ String
Outputs the title for this page.
-
#render_breadcrumbs(options = {}) ⇒ Object
Renders breadcrumbs based on the current_page.
- #render_portlet(name) ⇒ Object
Instance Method Details
#able_to?(*perms, &block) ⇒ Boolean
Determines if the current_user is able to do specific permissions.
125 126 127 128 |
# File 'app/helpers/cms/page_helper.rb', line 125 def able_to?(*perms, &block) block.call if current_user.able_to?(*perms) return '' end |
#cms_content_editor ⇒ Array
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.
8 9 10 11 12 13 14 |
# File 'app/helpers/cms/page_helper.rb', line 8 def cms_content_editor if Cms.content_editor.is_a?(Array) Cms.content_editor else "bcms/#{Cms.content_editor}" # Handles existing FCKEditor behavior end end |
#cms_toolbar ⇒ Object
Add the code to render the CMS toolbar.
69 70 71 72 73 74 |
# File 'app/helpers/cms/page_helper.rb', line 69 def = <<HTML <iframe src="#{cms.(:page_id => @page.id, :page_version => @page.version, :mode => @mode, : => @show_page_toolbar ? 1 : 0) }" width="100%" height="#{@show_page_toolbar ? 159 : 100 }px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" name="cms_toolbar"></iframe> HTML .html_safe if @show_toolbar 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.
38 39 40 41 42 43 44 45 |
# File 'app/helpers/cms/page_helper.rb', line 38 def container(name) content = 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 %>
58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/cms/page_helper.rb', line 58 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_page ⇒ Object
30 31 32 |
# File 'app/helpers/cms/page_helper.rb', line 30 def current_page @page end |
#page_title(*args) ⇒ String
Outputs the title for this page. Used by both internal CMS pages, as well as page templates. If not explicitily set,
returns the title of the page.
21 22 23 24 25 26 27 28 |
# File 'app/helpers/cms/page_helper.rb', line 21 def page_title(*args) if args.first # Removed unneeded indirection/fixed issue where @template is frozen in r1.9.1 @page_title = args.first else @page_title ? @page_title : current_page.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’).
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/cms/page_helper.rb', line 94 def (={}) return "" unless current_page start = [:from_top] || 0 show_parent = [:show_parent].nil? ? false : [:show_parent] ancestors = current_page.ancestors items = [] ancestors[start..ancestors.size].each_with_index do |sec,i| items << content_tag(:li, link_to(sec.name, sec.actual_path), (i == 0 ? {:class => "first"} : {})) end if !show_parent && current_page.section.path == current_page.path items[items.size-1] = content_tag(:li, current_page.section.name) else items << content_tag(:li, current_page.page_title) end content_tag(:ul, "\n #{items.join("\n ")}\n".html_safe, :class => "breadcrumbs") end |
#render_portlet(name) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/cms/page_helper.rb', line 113 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 |