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)

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

Links as buttons



59
60
61
# File 'app/helpers/layout_helper.rb', line 59

def link_button( label_txt, button_options, *args )
  link_to label_txt, *args, :class => button_options
end

- (Object) render_pagination_box(paginations)

render a pagination box if resource has items

Parameters:

  • paginations (Array)

    the slected Items to display



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

Returns:

  • (Boolean)


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::normalized_tags_with_weight(Posting).map { |tag,weight|
    unless tag.blank?
      if accessible_postings(tag,current_role).any?
         :span, :class => "tag-weight-#{weight.to_s.gsub('.','-')}" do
          link_to( "#{tag}", tags_path(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 ui_button(icon,label_text,url,options={})
  setup_button(icon,label_text,options)
  link_to( icon_and_text(label_text,icon), url, options ).html_safe
end

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,options={})
  setup_button(icon,label_text,options)
  link_to_function(icon_and_text(label_text,icon),function_call,options).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