Module: Manageable::ApplicationHelper
- Defined in:
- app/helpers/manageable/application_helper.rb
Instance Method Summary collapse
-
#manageable_attributes(record, options = {}, &block) ⇒ Object
Helper for custom attrtastic like builder.
-
#manageable_breadcrumbs(options = {}) {|items| ... } ⇒ Object
Displays a breadcrumb trail.
-
#manageable_button(body, url, html_options = {}) ⇒ Object
Creates a link_to button.
-
#manageable_content_box(options = {}, &block) ⇒ Object
Create a content box.
-
#manageable_controls(options = {}) {|items| ... } ⇒ Object
Creates a set of buttons.
- #manageable_footer ⇒ Object
-
#manageable_head ⇒ Object
Default customizable helpers.
-
#manageable_icon(name, size = :small, options = {}) ⇒ Object
Display an icon.
- #manageable_javascripts ⇒ Object
- #manageable_logo ⇒ Object
- #manageable_main_navigation(menu) ⇒ Object
- #manageable_navigation(options = {}) {|menu| ... } ⇒ Object
-
#manageable_page_title(title = nil) ⇒ Object
Get or set the page title.
-
#manageable_pagination(options = {}) ⇒ Object
Prints a pagination block.
-
#manageable_secondary_navigation(options = {}, &block) ⇒ Object
Displays a secondary naviagtion menu.
- #manageable_sidebar ⇒ Object
-
#manageable_sortable(column, title = nil, options = {}) ⇒ Object
Links to a sortable column.
- #manageable_user_navigation(menu) ⇒ Object
Instance Method Details
#manageable_attributes(record, options = {}, &block) ⇒ Object
Helper for custom attrtastic like builder
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'app/helpers/manageable/application_helper.rb', line 304 def manageable_attributes(record, = {}, &block) [:html] ||= {} html_class = [ "attrtastic", record.class.to_s.underscore, [:html][:class] ].compact.join(" ") output = tag(:div, { :class => html_class}, true) if block_given? output << capture(Helpers::AttributesBuilder.new(record, self), &block) else output << capture(Helpers::AttributesBuilder.new(record, self)) do |attr| attr.attributes end end output.safe_concat("</div>") end |
#manageable_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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'app/helpers/manageable/application_helper.rb', line 187 def ( = {}) items = Helpers::NavigationBuilder.new yield items if block_given? [:class] ||= "" [:class] << " breadcrumb" [:class].strip! 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 |
#manageable_button(body, url, html_options = {}) ⇒ Object
Creates a link_to button
224 225 226 227 228 229 230 231 |
# File 'app/helpers/manageable/application_helper.rb', line 224 def (body, url, = {}) [:class] = [[:class], "button"].compact.join(" ") icon = manageable_icon(.delete(:icon), :small, :alt => body) if [:icon] link_to url, do [icon, body].compact.join(" ").html_safe end end |
#manageable_content_box(options = {}, &block) ⇒ Object
Create a content box.
options - A hash of options to apply to the box. &block - The content of the box, passed an instance of Helpers::BoxBuilder.
Valid options:
-
:headline – The headline to show in the box.
-
:class – A class to apply to the box.
-
:id – The ID to apply to the box.
Example:
<% content_box :headline => "My Box", :class => "alert", :id => "my_box" do |box| %>
<% box.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 %>
<% box.breadcrumbs do |crumbs| %>
<% crumbs.item "Home", root_path %>
<% crumbs.item "People", people_path %>
<% crumbs.item "Bob Jones", person_path(@person), :active => true %>
<% end %>
<p>This is a really neat box, which will be displayed with a headline and navigation.</p>
<% end %>
Returns the completed box, yields an instance of Helpers::BoxBuilder.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/manageable/application_helper.rb', line 32 def manageable_content_box( = {}, &block) box_buffer = Helpers::BoxBuilder.new(self) box_content = capture(box_buffer, &block) = { :id => nil, :class => [] }.merge() block_class = ([ "block" ] + [ [:class] ].flatten).join(" ") content_tag(:div, :class => block_class, :id => [:id]) do block_out = box_buffer.buffers[:block_header].html_safe block_out << content_tag(:div, :class => "content") do content_out = ''.html_safe content_out = content_tag(:h2, [:headline]) if [:headline] content_out << content_tag(:div, box_content, :class => 'inner') end block_out << box_buffer.buffers[:block_footer].html_safe end end |
#manageable_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 "Copy", copy_person_path(person), :icon => "copy_person"
c.item "Delete", person_path(person), :method => :delete
end %>
</div>
</div>
Returns a set of controls to be displayed.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/helpers/manageable/application_helper.rb', line 154 def manageable_controls( = {}) [:class] ||= "" [:class] << " control" [:class].strip! items = Helpers::NavigationBuilder.new yield items if block_given? content_tag("div", ) do items.collect { |item| (item[:label], item[:href], item[:link_options].merge(:icon => item[:icon])) }.join("").html_safe end end |
#manageable_footer ⇒ Object
338 339 340 |
# File 'app/helpers/manageable/application_helper.rb', line 338 def content_tag(:p, "Manageable - Activo Theme by David Francisco / [email protected] / activo.dmfranc.com") end |
#manageable_head ⇒ Object
Default customizable helpers
322 323 324 |
# File 'app/helpers/manageable/application_helper.rb', line 322 def manageable_head content_for(:head) end |
#manageable_icon(name, size = :small, options = {}) ⇒ Object
Display an icon
name - The icon to display size - One of :small or :large (optional) options - A hash to be passed to the image_tag helper (optional)
Example:
manageable_icon("add")
# => image_tag("/assets/manageable/icons/16x16/add.png", :alt => "Add")
manageable_icon("new_item", :large)
# => image_tag("/assets/manageable/icons/32x32/new_item.png, :alt => "New Item")
Returns an image tag, ready to be displayed in a template.
83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/manageable/application_helper.rb', line 83 def manageable_icon(name, size = :small, = {}) return "" if name.nil? dimension = ( (size == :small) ? "16" : "32" ).html_safe [:alt] ||= name.capitalize.gsub("_", " ") image_tag(asset_path("manageable/icons/#{dimension}x#{dimension}/#{name}.png"), { :alt => [:alt] }) end |
#manageable_javascripts ⇒ Object
326 327 328 |
# File 'app/helpers/manageable/application_helper.rb', line 326 def manageable_javascripts content_for(:javascripts) end |
#manageable_logo ⇒ Object
334 335 336 |
# File 'app/helpers/manageable/application_helper.rb', line 334 def manageable_logo content_tag(:h1, "Manageable") end |
#manageable_main_navigation(menu) ⇒ Object
349 350 351 352 353 |
# File 'app/helpers/manageable/application_helper.rb', line 349 def () .item "Main Page", "#" .item "Active", "#", :class => "active" .item "Login", "#" end |
#manageable_navigation(options = {}) {|menu| ... } ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/manageable/application_helper.rb', line 94 def ( = {}, &block) [:class] ||= "" [:class].strip! [:ul_class] ||= "wat-cf" [:ul_class].strip! = Helpers::NavigationBuilder.new yield if block_given? content_tag("div", ) do content_tag("ul", "", :class => [:ul_class]) 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 |
#manageable_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.
65 66 67 68 |
# File 'app/helpers/manageable/application_helper.rb', line 65 def manageable_page_title(title = nil) @title = title unless title.nil? @title || "Untitled Page" end |
#manageable_pagination(options = {}) ⇒ Object
Prints a pagination block. Accepts the following options:
current_page num_pages param_name
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'app/helpers/manageable/application_helper.rb', line 238 def manageable_pagination( = {}) current_page = [:current_page] || 1 num_pages = [:num_pages] || 1 outer_window = [:outer_window] || 4 page_param = [:param_name] || :page if current_page <= num_pages previous_page = current_page - 1 next_page = current_page + 1 left_window = ((current_page - outer_window)...current_page).to_a.select{|i| i > 0} right_window = ((current_page + 1)..(current_page + outer_window)).to_a.select{|i| i <= num_pages} elements = [] if 1 != current_page # First elements << {:value => t("manageable.pagination.first"), :href => params.merge(page_param => 1)} # Previous elements << {:value => t("manageable.pagination.previous"), :href => params.merge(page_param => previous_page)} end # Left Gap if left_window.first && left_window.first != 1 elements << {:value => t("manageable.pagination.gap")} end # Left window left_window.each do |i| elements << {:value => i, :href => params.merge(page_param => i)} end # Current Page elements << {:value => current_page, :html => {:class => "current"}} # Right window right_window.each do |i| elements << {:value => i, :href => params.merge(page_param => i)} end # Right Gap if right_window.last && right_window.last != num_pages elements << {:value => t("manageable.pagination.gap")} end if num_pages != current_page # Next elements << {:value => t("manageable.pagination.next"), :href => params.merge(page_param => next_page)} # Last elements << {:value => t("manageable.pagination.last"), :href => params.merge(page_param => num_pages)} end content_tag :div, :class => "pagination" do elements.map do || if [:href] link_to [:value], [:href] else content_tag(:span, [:value], [:html]) end end.join.html_safe end end end |
#manageable_secondary_navigation(options = {}, &block) ⇒ Object
Displays a secondary naviagtion menu
options - A hash of attributes to apply to the wrapping div tag
Example:
<div class="block">
<%= secondary_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 secondary navigation block to be displayed.
132 133 134 135 136 137 |
# File 'app/helpers/manageable/application_helper.rb', line 132 def ( = {}, &block) [:class] ||= "" [:class] << " secondary-navigation" (, &block) end |
#manageable_sidebar ⇒ Object
330 331 332 |
# File 'app/helpers/manageable/application_helper.rb', line 330 def content_for(:sidebar) end |
#manageable_sortable(column, title = nil, options = {}) ⇒ Object
Links to a sortable column. column: - The column to link to title: - The link title options: - Additional link_to options
214 215 216 217 218 219 220 221 |
# File 'app/helpers/manageable/application_helper.rb', line 214 def manageable_sortable(column, title = nil, = {}) title ||= column.titleize css_class = column && sort_column && column.to_sym == sort_column.to_sym ? "sort_#{sort_direction}" : nil direction = column && sort_column && column.to_sym == sort_column.to_sym && sort_direction == "asc" ? "desc" : "asc" [:class] = [[:class], css_class].compact.join(" ") link_to title, params.merge(:sort => column, :direction => direction, :page => nil), end |
#manageable_user_navigation(menu) ⇒ Object
342 343 344 345 346 347 |
# File 'app/helpers/manageable/application_helper.rb', line 342 def () .item image_tag("manageable/session/home.png", :alt => "Dashboard", :"original-title" => "Dashboard"), "#" .item image_tag("manageable/session/account.png", :alt => "Profile", :"original-title" => "Profile"), "#" .item image_tag("manageable/session/config.png", :alt => "Preferences", :"original-title" => "Preferences"), "#" .item image_tag("manageable/session/logout.png", :alt => "Logout", :"original-title" => "Logout"), "#" end |