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_toolbar ⇒ Object
- #container(name) ⇒ Object
- #container_has_block?(name, &block) ⇒ Boolean
- #current_page ⇒ Object
- #page_title(*args) ⇒ Object
-
#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.
87 88 89 |
# File 'app/helpers/cms/page_helper.rb', line 87 def able_to?(*perms, &block) yield if current_user.able_to?(*perms) end |
#cms_toolbar ⇒ Object
34 35 36 |
# File 'app/helpers/cms/page_helper.rb', line 34 def 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
24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/cms/page_helper.rb', line 24 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
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’).
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/cms/page_helper.rb', line 55 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(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] = content_tag(:li, h(current_page.section.name)) else items << content_tag(:li, h(current_page.page_title)) end content_tag(:ul, "\n #{items.join("\n ")}\n", :class => "breadcrumbs") end |
#render_portlet(name) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/cms/page_helper.rb', line 75 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 |