Module: LayoutHelper
- Defined in:
- app/helpers/layout_helper.rb
Overview
These helper methods can be called in your template to set variables to be used in the layout This module should be included in all views globally, to do so you may need to add this line to your ApplicationController
helper :layout
The original LayoutHelper module was done by Ryan Bates and got some extensions for our project.
Instance Method Summary (collapse)
-
- (Object) javascript(*args)
Put javascripts to the html-head.
-
- (Object) link_button(label_txt, button_options, *args)
Links as buttons.
-
- (Object) render_pagination_box(paginations)
render a pagination box if resource has items.
-
- (Object) set_browser_address(page, title)
Outputs a Javascript to place the title of a page at the URL in cases where the page was addressed by it’s ID
parameters:.
-
- (Boolean) show_title?
Let’s see if there is a title for the h1-title.
-
- (Object) stylesheet(*args)
Put stylesheets in the yield used in application.html.erb.
-
- (Object) tag_cloud
render a tag-cloud.
-
- (Object) title(page_title, show_title = true)
Set the title of the html-page.
-
- (Object) ui_button(icon, label_text, url, options = {})
render jquery-ui-buttons.
-
- (Object) ui_link_to_function(icon, label_text, function_call, options = {})
render button for link_to_function.
-
- (Object) w3c_url(url)
Replace blanks by %20 to satisfy w3c-validators Attantion: This is implemented in BasePresenter too!.
Instance Method Details
- (Object) javascript(*args)
Put javascripts to the html-head
32 33 34 |
# File 'app/helpers/layout_helper.rb', line 32 def javascript(*args) content_for(:head) { javascript_include_tag(*args) } end |
- (Object) link_button(label_txt, button_options, *args)
Links as buttons
59 60 61 |
# File 'app/helpers/layout_helper.rb', line 59 def ( label_txt, , *args ) link_to label_txt, *args, :class => end |
- (Object) render_pagination_box(paginations)
render a pagination box if resource has items
65 66 67 68 69 70 71 |
# File 'app/helpers/layout_helper.rb', line 65 def render_pagination_box paginations if paginations.total_pages > 1 haml_tag(".pagination_box") do concat(will_paginate(paginations)) end end end |
- (Object) set_browser_address(page, title)
Outputs a Javascript to place the title of a page at the URL in cases where the page was addressed by it’s ID
parameters:
page:
The `Page` to set address for
title:
HTML-Title to use
43 44 45 46 47 48 49 50 |
# File 'app/helpers/layout_helper.rb', line 43 def set_browser_address(page,title) unless title.length > CONSTANTS['title_max_length'].to_i address = "/p/"+title.txt_to_url "<script> history.replaceState( {page: '#{page}'},'#{title}', '#{address}'); </script>".html_safe end end |
- (Boolean) show_title?
Let’s see if there is a title for the h1-title
22 23 24 |
# File 'app/helpers/layout_helper.rb', line 22 def show_title? @show_title end |
- (Object) stylesheet(*args)
Put stylesheets in the yield used in application.html.erb
27 28 29 |
# File 'app/helpers/layout_helper.rb', line 27 def stylesheet(*args) content_for(:head) { stylesheet_link_tag(*args) } end |
- (Object) tag_cloud
render a tag-cloud
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/layout_helper.rb', line 74 def tag_cloud ContentItem::(Posting).map { |tag,weight| unless tag.blank? if accessible_postings(tag,current_role).any? content_tag :span, :class => "tag-weight-#{weight.to_s.gsub('.','-')}" do link_to( "#{tag}", (tag)) end end end }.compact.join(" ").html_safe end |
- (Object) title(page_title, show_title = true)
Set the title of the html-page.
parameters:
show_title::
If true the title will also displayed as a h1-title within the
html-page not only in the browser-window-title
16 17 18 19 |
# File 'app/helpers/layout_helper.rb', line 16 def title(page_title, show_title = true) content_for(:title) { h(page_title.html_safe) } @show_title = show_title end |
- (Object) ui_button(icon, label_text, url, options = {})
render jquery-ui-buttons
87 88 89 90 |
# File 'app/helpers/layout_helper.rb', line 87 def (icon,label_text,url,={}) (icon,label_text,) link_to( icon_and_text(label_text,icon), url, ).html_safe end |
- (Object) ui_link_to_function(icon, label_text, function_call, options = {})
render button for link_to_function
93 94 95 96 |
# File 'app/helpers/layout_helper.rb', line 93 def ui_link_to_function(icon,label_text,function_call,={}) (icon,label_text,) link_to_function(icon_and_text(label_text,icon),function_call,).html_safe end |
- (Object) w3c_url(url)
Replace blanks by %20 to satisfy w3c-validators Attantion: This is implemented in BasePresenter too!
54 55 56 |
# File 'app/helpers/layout_helper.rb', line 54 def w3c_url(url) url.gsub(' ', '%20') end |