Module: Alchemy::PagesHelper
- Includes:
- BaseHelper, ElementsHelper
- Defined in:
- app/helpers/alchemy/pages_helper.rb
Instance Method Summary (collapse)
-
- (Object) alchemy_menu_bar
Renders a menubar for logged in users that are visiting a page.
-
- (Object) alchemy_preview_mode_code
Include this in your layout file to have element selection magic in the page edit preview window.
-
- (Boolean) cell_empty?(name)
Returns true or false if no elements are in the cell found by name.
-
- (Object) external_page_css_class(page)
Returns 'active' if the given external page is in the current url path or nil.
-
- (Object) language_links(options = {})
Renders links to language root pages of all published languages.
- - (Object) language_switcher(options = {})
- - (Object) language_switches(options = {})
-
- (Boolean) page_active?(page)
Returns true if page is in the active branch.
- - (Object) picture_essence_caption(content)
-
- (Object) render_breadcrumb(options = {})
Returns page links in a breadcrumb beginning from root to current page.
-
- (Object) render_cell(name, options = {})
Renders the partial for the cell with the given name of the current page.
- - (Object) render_classes(classes = [])
-
- (Object) render_meta_data(options = {})
This helper takes care of all important meta tags for your page.
-
- (Object) render_meta_tag(options = {})
Renders a html tag for :name => “” and :content => “”.
-
- (Object) render_navigation(options = {}, html_options = {})
Renders the navigation.
-
- (Object) render_page_layout(options = {})
Renders the layout from @page.page_layout.
-
- (Object) render_page_title(options = {})
Returns current page title.
-
- (Object) render_search_form(options = {})
Renders a search form.
-
- (Object) render_search_results(options = {})
Renders the search results partial within app/views/alchemy/search/_results.html.
-
- (Object) render_subnavigation(options = {})
Renders navigation the children and all siblings of the given page (standard is the current page).
-
- (Object) render_title_tag(options = {})
Returns a complete html tag for the part of the html document.
- - (Object) sitename_from_header_page
Methods included from ElementsHelper
#all_elements_by_name, #element_dom_id, #element_from_page, #element_preview_code, #element_preview_code_attributes, #element_tags, #element_tags_attributes, #full_url_for_element, #render_cell_elements, #render_element, #render_elements
Methods included from ElementsBlockHelper
#element_editor_for, #element_view_for
Methods included from UrlHelper
#download_alchemy_attachment_path, #download_alchemy_attachment_url, #page_path_for, #show_alchemy_page_path, #show_alchemy_page_url, #show_alchemy_picture_path, #show_alchemy_picture_url, #show_page_path_params, #show_picture_path_params
Methods included from EssencesHelper
#render_essence, #render_essence_picture_view, #render_essence_view, #render_essence_view_by_name, #render_essence_view_by_position, #render_essence_view_by_type
Methods included from BaseHelper
#_t, #breadcrumb, #configuration, #current_language, #multi_language?, #page_or_find, #parse_sitemap_name, #render_flash_notice, #render_icon, #render_message, #shorten, #warning
Instance Method Details
- (Object) alchemy_menu_bar
Renders a menubar for logged in users that are visiting a page.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'app/helpers/alchemy/pages_helper.rb', line 409 def return if @preview_mode if permitted_to?(:edit, :alchemy_admin_pages) = "" += stylesheet_link_tag("alchemy/menubar") += javascript_include_tag('alchemy/menubar') += <<-STR <script type="text/javascript"> try { Alchemy.loadAlchemyMenuBar({ page_id: #{@page.id}, route: '#{Alchemy.mount_point}', locale: '#{current_user.language || ::I18n.default_locale}' }); } catch(e) { if(console){console.log(e)} } </script> STR .html_safe else nil end end |
- (Object) alchemy_preview_mode_code
Include this in your layout file to have element selection magic in the page edit preview window.
361 362 363 |
# File 'app/helpers/alchemy/pages_helper.rb', line 361 def alchemy_preview_mode_code javascript_include_tag("alchemy/preview") if @preview_mode end |
- (Boolean) cell_empty?(name)
Returns true or false if no elements are in the cell found by name.
354 355 356 357 358 |
# File 'app/helpers/alchemy/pages_helper.rb', line 354 def cell_empty?(name) cell = @page.cells.find_by_name(name) return true if cell.blank? cell.elements.blank? end |
- (Object) external_page_css_class(page)
Returns 'active' if the given external page is in the current url path or nil.
178 179 180 181 |
# File 'app/helpers/alchemy/pages_helper.rb', line 178 def external_page_css_class(page) return nil if !page.redirects_to_external? request.path.split('/').delete_if(&:blank?).first == page.urlname.gsub(/^\//, '') ? 'active' : nil end |
- (Object) language_links(options = {})
Renders links to language root pages of all published languages.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/alchemy/pages_helper.rb', line 25 def language_links(={}) = { linkname: 'name', show_title: true, spacer: '', reverse: false }.merge() languages = Language.published.with_language_root.order("name #{[:reverse] ? 'DESC' : 'ASC'}") return nil if languages.count < 2 render( partial: "alchemy/language_links/language", collection: languages, spacer_template: "alchemy/language_links/spacer", locals: {languages: languages, options: } ) end |
- (Object) language_switcher(options = {})
47 48 49 50 |
# File 'app/helpers/alchemy/pages_helper.rb', line 47 def language_switcher(={}) ActiveSupport::Deprecation.warn("Used deprecated language_switcher helper. Please use language_links instead.") language_links() end |
- (Object) language_switches(options = {})
42 43 44 45 |
# File 'app/helpers/alchemy/pages_helper.rb', line 42 def language_switches(={}) ActiveSupport::Deprecation.warn("Used deprecated language_switches helper. Please use language_links instead.") language_links() end |
- (Boolean) page_active?(page)
Returns true if page is in the active branch
172 173 174 175 |
# File 'app/helpers/alchemy/pages_helper.rb', line 172 def page_active?(page) @breadcrumb ||= (@page) @breadcrumb.include?(page) end |
- (Object) picture_essence_caption(content)
12 13 14 15 16 |
# File 'app/helpers/alchemy/pages_helper.rb', line 12 def picture_essence_caption(content) return "" if content.nil? return "" if content.essence.nil? content.essence.caption end |
- (Object) render_breadcrumb(options = {})
Returns page links in a breadcrumb beginning from root to current page.
Options:
:seperator => %(<span class="seperator">></span>) # Maybe you don't want this seperator. Pass another one.
:page => @page # Pass a different Page instead of the default (@page).
:without => nil # Pass Page object or array of Pages that must not be displayed.
:restricted_only => false # Pass boolean for displaying restricted pages only.
:reverse => false # Pass boolean for displaying breadcrumb in reversed reversed.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/helpers/alchemy/pages_helper.rb', line 193 def (={}) = { :seperator => %(<span class="seperator">></span>), :page => @page, :restricted_only => false, :reverse => false, :link_active_page => false }.merge() pages = ([:page]).published.visible.(:show, :context => :alchemy_pages) pages = pages.restricted if .delete(:restricted_only) pages.to_a.reverse! if [:reverse] if [:without].present? if [:without].class == Array pages = pages.to_a - [:without] else pages.to_a.delete([:without]) end end render( partial: 'alchemy/breadcrumb/page', collection: pages, spacer_template: 'alchemy/breadcrumb/spacer', locals: {pages: pages, options: } ) end |
- (Object) render_cell(name, options = {})
Renders the partial for the cell with the given name of the current page. Cell partials are located in app/views/cells/ of your project.
Options are:
:from_page => Alchemy::Page # Alchemy::Page object from which the elements are rendered from.
:locals => Hash # Hash of variables that will be available in the partial. Example: {:user => var1, :product => var2}
342 343 344 345 346 347 348 349 350 351 |
# File 'app/helpers/alchemy/pages_helper.rb', line 342 def render_cell(name, ={}) = { :from_page => @page, :locals => {} } = .merge() cell = [:from_page].cells.find_by_name(name) return "" if cell.blank? render :partial => "alchemy/cells/#{name}", :locals => {:cell => cell}.merge([:locals]) end |
- (Object) render_classes(classes = [])
7 8 9 10 |
# File 'app/helpers/alchemy/pages_helper.rb', line 7 def render_classes(classes=[]) s = classes.uniq.delete_if { |x| x.blank? }.join(" ") s.blank? ? "" : "class='#{s}'" end |
- (Object) render_meta_data(options = {})
This helper takes care of all important meta tags for your page.
The meta data is been taken from the @page.title, @page.meta_description, @page.meta_keywords, @page.updated_at and @page.language database entries managed by the Alchemy user via the Alchemy cockpit.
Assume that the user has entered following data into the Alchemy cockpit of the Page “home” and that the user wants that the searchengine (aka. google) robot should index the page and should follow all links on this page:
Title = Homepage Description = Your page description Keywords: cms, ruby, rubyonrails, rails, software, development, html, javascript, ajax
Then placing +render_meta_data(:title_prefix => “Company”, :title_seperator => “-”)+ into the <head> part of the pages.html.erb layout produces:
<meta charset="UTF-8">
<title>Company - #{@page.title}</title>
<meta name="description" content="Your page description">
<meta name="keywords" content="cms, ruby, rubyonrails, rails, software, development, html, javascript, ajax">
<meta name="created" content="Tue Dec 16 10:21:26 +0100 2008">
<meta name="robots" content="index, follow">
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'app/helpers/alchemy/pages_helper.rb', line 294 def ={} if @page.blank? warning("No Page found!") return nil end = { :title_prefix => "", :title_seperator => "", :default_lang => "de" } = .merge() #render meta description of the root page from language if the current meta description is empty if @page..blank? description = Page.published.with_language(session[:language_id]).find_by_language_root(true).try(:meta_description) else description = @page. end #render meta keywords of the root page from language if the current meta keywords is empty if @page..blank? keywords = Page.published.with_language(session[:language_id]).find_by_language_root(true).try(:meta_keywords) else keywords = @page. end robot = "#{@page.robot_index? ? "" : "no"}index, #{@page.robot_follow? ? "" : "no"}follow" = %( <meta charset="UTF-8"> #{render_title_tag(:prefix => [:title_prefix], :seperator => [:title_seperator])} #{(:name => "description", :content => description)} #{(:name => "keywords", :content => keywords)} <meta name="created" content="#{@page.updated_at}"> <meta name="robots" content="#{robot}"> ) if @page.contains_feed? += %( <link rel="alternate" type="application/rss+xml" title="RSS" href="#{show_alchemy_page_url(@page, :protocol => 'feed', :format => :rss)}"> ) end return .html_safe end |
- (Object) render_meta_tag(options = {})
Renders a html <meta> tag for :name => “” and :content => “”
Webdevelopers:
Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. So you dont have to worry about anything.
264 265 266 267 268 269 270 271 272 273 |
# File 'app/helpers/alchemy/pages_helper.rb', line 264 def (={}) = { :name => "", :default_language => "de", :content => "" } = .merge() lang = (@page.language.blank? ? [:default_language] : @page.language.code) %(<meta name="#{[:name]}" content="#{[:content]}" lang="#{lang}">).html_safe end |
- (Object) render_navigation(options = {}, html_options = {})
Renders the navigation.
It produces a html <ul><li></li></ul> structure with all necessary classes so you can produce every navigation the web uses today. I.E. dropdown-navigations, simple mainnavigations or even complex nested ones.
En detail:
<ul class="navigation level_1">
<li class="first home"><a href="/home" class="active" title="Homepage" lang="en" data-page-id="1">Homepage</a></li>
<li class="contact"><a href="/contact" title="Contact" lang="en" data-page-id="2">Contact</a></li>
<li class="last imprint"><a href="/imprint" title="Imprint" lang="en" data-page-id="3">Imprint</a></li>
</ul>
As you can see: Everything you need.
Not pleased with the way Alchemy produces the navigation structure? Then feel free to overwrite the partials (_renderer.html.erb and _link.html.erb) found in views/navigation/ or pass different partials via the options :navigation_partial and :navigation_link_partial.
The options are:
:submenu => false # Do you want a nested <ul> <li> structure for the deeper levels of your navigation, or not? Used to display the subnavigation within the mainnaviagtion. E.g. for dropdown menues.
:all_sub_menues => false # Renders the whole page tree.
:from_page => @root_page # Do you want to render a navigation from a different page then the current page? Then pass an Page instance or a Alchemy::PageLayout name as string.
:spacer => nil # A spacer for the entries can be passed. Simple string, or even a complex html structure. E.g: "<span class='spacer'>|</spacer>".
:navigation_partial => "navigation/renderer" # Pass a different partial to be taken for the navigation rendering.
:navigation_link_partial => "navigation/link" # Alchemy places an <a> html link in <li> tags. The tag automatically has an active css class if necessary. So styling is everything. But maybe you don't want this. So feel free to make you own partial and pass the filename here.
:show_nonactive => false # Commonly Alchemy only displays the submenu of the active page (if :submenu => true). If you want to display all child pages then pass true (together with :submenu => true of course). E.g. for the popular css-driven dropdownmenues these days.
:show_title => true # For our beloved SEOs :). Appends a title attribute to all links and places the page.title content into it.
:restricted_only => false # Render only restricted pages. I.E for members only navigations.
:show_title => true # Show a title on navigation links. Title attribute from page.
:reverse => false # Reverse the navigation
:reverse_children => false # Reverse the nested children
:deepness => nil # Show only pages up to this depth.
Passing HTML classes and ids to the renderer
A second hash can be passed as html_options to the navigation renderer partial.
Example:
<%= render_navigation({from_page => 'subnavi'}, {:class => 'navigation', :id => 'subnavigation'}) %>
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/helpers/alchemy/pages_helper.rb', line 110 def ( = {}, = {}) = { :submenu => false, :all_sub_menues => false, :from_page => @root_page || Page.language_root_for(session[:language_id]), :spacer => nil, :navigation_partial => "alchemy/navigation/renderer", :navigation_link_partial => "alchemy/navigation/link", :show_nonactive => false, :restricted_only => false, :show_title => true, :reverse => false, :reverse_children => false }.merge() page = page_or_find([:from_page]) return nil if page.blank? pages = page.children.visible.(:show, :context => :alchemy_pages) pages = pages.restricted if .delete(:restricted_only) if depth = [:deepness] pages = pages.where("#{Page.table_name}.depth <= #{depth}") end if [:reverse] pages.reverse! end render( [:navigation_partial], :options => , :pages => pages, :html_options => ) end |
- (Object) render_page_layout(options = {})
Renders the layout from @page.page_layout. File resists in /app/views/page_layouts/_LAYOUT-NAME.html.erb
53 54 55 56 57 58 |
# File 'app/helpers/alchemy/pages_helper.rb', line 53 def render_page_layout(={}) render :partial => "alchemy/page_layouts/#{@page.page_layout.downcase}" rescue ActionView::MissingTemplate warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.") render :partial => "alchemy/page_layouts/standard" end |
- (Object) render_page_title(options = {})
Returns current page title
Options:
:prefix => "" # Prefix
:seperator => "" # Seperating prefix and title
Webdevelopers
Please use the render_meta_data() helper instead. There all important meta information gets rendered in one helper. So you dont have to worry about anything.
231 232 233 234 235 236 237 238 239 |
# File 'app/helpers/alchemy/pages_helper.rb', line 231 def render_page_title(={}) return "" if @page.title.blank? = { :prefix => "", :seperator => "" } .update() [[:prefix], response.status == 200 ? @page.title : response.status].join([:seperator]) end |
- (Object) render_search_form(options = {})
Renders a search form
It queries the controller and then redirects to the search result page.
Example search results page layout
Only performs the search if ferret is enabled in your config/alchemy/config.yml and a page is present that is flagged with searchresults true.
# config/alchemy/page_layouts.yml
- name: search
searchresults: true # Flag as search result page
Note
The search result page will not be cached.
386 387 388 389 390 391 392 393 |
# File 'app/helpers/alchemy/pages_helper.rb', line 386 def render_search_form(={}) = { :html5 => false, :class => 'fulltext_search', :id => 'search' } render :partial => 'alchemy/search/form', :locals => {:options => .merge(), :search_result_page => find_search_result_page} end |
- (Object) render_search_results(options = {})
Renders the search results partial within app/views/alchemy/search/_results.html
400 401 402 403 404 405 406 |
# File 'app/helpers/alchemy/pages_helper.rb', line 400 def render_search_results(={}) = { :show_result_count => true, :show_heading => true } render 'alchemy/search/results', :options => .merge() end |
- (Object) render_subnavigation(options = {})
Renders navigation the children and all siblings of the given page (standard is the current page).
Use this helper if you want to render the subnavigation independent from the mainnavigation. I.E. to place it in a different area on your website.
This helper passes all its options to the the render_navigation helper.
Options:
:from_page => @page # The page to render the navigation from
:submenu => true # Shows the nested children
:level => 2 # Normally there is no need to change the level parameter, just in a few special cases
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/helpers/alchemy/pages_helper.rb', line 154 def ( = {}) = { :from_page => @page, :submenu => true, :level => 2 } = .merge() if ![:from_page].nil? while [:from_page].level > [:level] do [:from_page] = [:from_page].parent end () else return nil end end |
- (Object) render_title_tag(options = {})
Returns a complete html <title> tag for the <head> part of the html document.
Webdevelopers:
Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. So you dont have to worry about anything.
248 249 250 251 252 253 254 255 |
# File 'app/helpers/alchemy/pages_helper.rb', line 248 def render_title_tag(={}) = { :prefix => "", :seperator => "" } = .merge() %(<title>#{render_page_title()}</title>).html_safe end |
- (Object) sitename_from_header_page
60 61 62 63 64 65 66 |
# File 'app/helpers/alchemy/pages_helper.rb', line 60 def sitename_from_header_page header_page = Page.find_by_page_layout_and_layoutpage('layout_header', true) return "" if header_page.nil? page_title = header_page.elements.find_by_name('sitename') return "" if page_title.nil? page_title.ingredient('name') end |