Module: ActivoateHelper
- Defined in:
- app/helpers/activoate_helper.rb
Defined Under Namespace
Classes: ControlsBuilder, NavigationBuilder
Instance Method Summary collapse
-
#add_button(path) ⇒ Object
Wraps the button helper, creating an add button.
-
#badge(content, color = '') ⇒ Object
Displays a badge.
-
#breadcrumbs(options = {}) {|items| ... } ⇒ Object
Displays a breadcrumb trail.
-
#button(path, caption = 'click-me', icon = 'show', options = {}) ⇒ Object
Displays a button.
-
#cancel_button(path) ⇒ Object
Wraps the button helper, creating a cancel button.
-
#controls(options = {}) {|items| ... } ⇒ Object
Creates a set of buttons.
-
#delete_button(path, alternative_icon = false) ⇒ Object
Wraps the button helper, creating a delete button.
-
#edit_button(path, alternative_icon = false) ⇒ Object
Wraps the button helper, creating an edit button.
-
#icon(name, options = {}) ⇒ Object
Displays an icon.
-
#navigation(options = {}) {|menu| ... } ⇒ Object
Displays a navigation menu.
-
#page_title(title = nil) ⇒ Object
Get or set the page title.
-
#secondary_inner_navigation(options = {}, &block) ⇒ Object
Displays a secondary inner navigation menu.
-
#secondary_navigation(options = {}, &block) ⇒ Object
Displays a secondary navigation menu.
-
#submit_button(caption = 'submit', icon = 'show', options = {}) ⇒ Object
Displays a submit button.
Instance Method Details
#add_button(path) ⇒ Object
Wraps the button helper, creating an add button
path - The button`s action
Example:
<%= add_button new_user_path %>
Returns an anchor tag
45 46 47 |
# File 'app/helpers/activoate_helper.rb', line 45 def (path) (path, t("activoate.add", :default => 'Add'), 'add') end |
#badge(content, color = '') ⇒ Object
Displays a badge
content - The bagde`s content color - null for white, or grey, red, yellow, green
Example:
<%= badge 'New!', 'yellow' %>
Returns a div tag
28 29 30 31 32 33 34 |
# File 'app/helpers/activoate_helper.rb', line 28 def badge(content, color = '') color = "-#{color}" unless color.length == 0 content_tag('div', { :class => "badge#{color}" }) do content end end |
#breadcrumbs(options = {}) {|items| ... } ⇒ Object
Displays a breadcrumb trail
options - A hash of attributes to apply to the wrapping div tag
Example:
<div class="block">
<div class="content">
<h2><%= @news_item.title %></h2>
<p><%= @news_item.content %></p>
</div>
<%= breadcrumbs do |b|
b.item "Home", root_path
b.item "News", news_path
b.item "Awesome New Things", news_path(@news_item), :active => true
%>
</div>
Returns the breadcrumb trail.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'app/helpers/activoate_helper.rb', line 249 def ( = {}) items = NavigationBuilder.new yield items if block_given? [:class] ||= "" [:class] << " breadcrumb" [:class] = [:class].strip.html_safe content_tag("div", ) do content_tag("ul") do items.collect { |item| content_tag("li", :class => item[:class]) do if item[:active] item[:label] else link_to(item[:label], item[:href]) end end }.join("").html_safe end end end |
#button(path, caption = 'click-me', icon = 'show', options = {}) ⇒ Object
Displays a button
path - The button`s action caption - The button`s caption icon - The icon file name, without the extension options - A hash of attributes to apply to the wrapping anchor tag
Example:
<%= button root_path, { :caption => 'home', :icon => 'home' } %>
Returns an anchor tag
104 105 106 107 108 109 110 111 |
# File 'app/helpers/activoate_helper.rb', line 104 def (path, = 'click-me', icon = 'show', = {}) = { :class => "button", :confirm => false } = .merge() link_to path, do image_tag("activo/icons/#{icon}.png", :alt => ) + " " + end end |
#cancel_button(path) ⇒ Object
Wraps the button helper, creating a cancel button
path - The button`s action
Example:
<%= cancel_button users_path %>
Returns an anchor tag
57 58 59 |
# File 'app/helpers/activoate_helper.rb', line 57 def (path) (path, t("activoate.cancel", :default => 'Cancel'), 'cross') end |
#controls(options = {}) {|items| ... } ⇒ Object
Creates a set of buttons
options - A hash of attributes to apply to the wrapping div tag
Example:
<div class="block">
<div class="content">
<%= controls do |c|
c.item add_button(new_user_path)
c.item button(root_path, { :caption => 'home', :icon => 'home' })
c.item delete_button(users_path(@user), true)
end %>
</div>
</div>
Returns a set of controls to be displayed.
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'app/helpers/activoate_helper.rb', line 148 def controls( = {}) [:class] ||= "" [:class] << " control" [:class] = [:class].strip.html_safe items = ControlsBuilder.new yield items if block_given? content_tag("div", ) do items.to_a.join("").html_safe end end |
#delete_button(path, alternative_icon = false) ⇒ Object
Wraps the button helper, creating a delete button
path - The button`s action alternative_icon - True for the alternative icon
Example:
<%= delete_button users_path(@user) %>
<%= delete_button users_path(@user), true %>
Returns an anchor tag
85 86 87 88 89 90 91 |
# File 'app/helpers/activoate_helper.rb', line 85 def (path, alternative_icon = false) = { :confirm => t("activoate.confirm", :default => "Are you sure?"), :method => :delete } (path, t("activoate.delete", :default => 'Delete'), alternative_icon ? 'delete' : 'cross', ) end |
#edit_button(path, alternative_icon = false) ⇒ Object
Wraps the button helper, creating an edit button
path - The button`s action alternative_icon - True for the alternative icon
Example:
<%= edit_button edit_user_path(@user) %>
<%= edit_button edit_user_path(@user), true %>
Returns an anchor tag
71 72 73 |
# File 'app/helpers/activoate_helper.rb', line 71 def (path, alternative_icon = false) (path, t("activoate.edit", :default => 'Edit'), alternative_icon ? 'edit' : 'application_edit') end |
#icon(name, options = {}) ⇒ Object
Displays an icon
name - The icon file name, without the extension options - A hash of attributes to apply to the image tag
Example:
<%= icon 'add', { :alt => "Add item" } %>
Returns an img tag.
170 171 172 173 174 175 176 177 178 |
# File 'app/helpers/activoate_helper.rb', line 170 def icon(name, = {}) return "" if name.nil? [:alt] ||= name.capitalize.gsub("_", " ") path = "activo/icons/#{name}.png" image_tag path, { :alt => [:alt] } end |
#navigation(options = {}) {|menu| ... } ⇒ Object
Displays a navigation menu
options - A hash of attributes to apply to the wrapping div tag
Example:
<div class="block">
<%= navigation do |nav|
nav.item "List People", people_path, :active => true
nav.item "New Person", new_person_path
nav.item "Search", search_path(:type => "people")
end %>
<div class="content">
<h2 class="title">List People</h2>
</div>
</div>
Returns a navigation block to be displayed.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'app/helpers/activoate_helper.rb', line 197 def ( = {}, &block) [:class] ||= "" [:class] = [:class].strip.html_safe = NavigationBuilder.new yield if block_given? content_tag("div", ) do content_tag("ul", "", :class => "wat-cf") do .collect { |item| content_tag("li", :class => item[:class]) do link_to(item[:label], item[:href], item[:link_options]) end }.join("").html_safe end end end |
#page_title(title = nil) ⇒ Object
Get or set the page title
title - The title to set. (optional)
Example:
page_title("Hello, world!")
# => "Hello, world!"
page_title
# => "Hello, world!"
Returns the page title, first setting it if title is not nil.
14 15 16 17 |
# File 'app/helpers/activoate_helper.rb', line 14 def page_title(title = nil) @title = title unless title.nil? @title end |
#secondary_inner_navigation(options = {}, &block) ⇒ Object
Displays a secondary inner navigation menu
224 225 226 227 228 229 |
# File 'app/helpers/activoate_helper.rb', line 224 def ( = {}, &block) [:class] ||= "" [:class] << " secondary-inner-nav" (, &block) end |
#secondary_navigation(options = {}, &block) ⇒ Object
Displays a secondary navigation menu
216 217 218 219 220 221 |
# File 'app/helpers/activoate_helper.rb', line 216 def ( = {}, &block) [:class] ||= "" [:class] << " secondary-navigation" (, &block) end |
#submit_button(caption = 'submit', icon = 'show', options = {}) ⇒ Object
Displays a submit button
caption - The button`s caption icon - The icon file name, without the extension options - A hash of attributes to apply to the wrapping button tag
Example:
<%= submit_button root_path, { :caption => 'home', :icon => 'home' } %>
Returns a button tag
123 124 125 126 127 128 129 130 |
# File 'app/helpers/activoate_helper.rb', line 123 def ( = 'submit', icon = 'show', = {}) = { :class => "button", :type => 'submit' } = .merge() content_tag("button", ) do image_tag("activo/icons/#{icon}.png", :alt => ) + " " + end end |