Module: ActivoateHelper

Defined in:
app/helpers/activoate_helper.rb

Defined Under Namespace

Classes: ControlsBuilder, NavigationBuilder

Instance Method Summary collapse

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 add_button(path)
  button(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

  ('div', { :class => "badge#{color}" }) do
    content
  end
end

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.

Yields:

  • (items)


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 breadcrumbs(options = {})
  items = NavigationBuilder.new
  yield items if block_given?

  options[:class] ||= ""
  options[:class] << " breadcrumb"
  options[:class] = options[:class].strip.html_safe

  ("div", options) do
    ("ul") do
      items.collect { |item|
        ("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 button(path, caption = 'click-me', icon = 'show', options = {})
  default_options = { :class => "button", :confirm => false }
  options = default_options.merge(options)

  link_to path, options do
    image_tag("activo/icons/#{icon}.png", :alt => caption) + " " + caption
  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 cancel_button(path)
  button(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.

Yields:

  • (items)


148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/helpers/activoate_helper.rb', line 148

def controls(options = {})
  options[:class] ||= ""
  options[:class] << " control"
  options[:class] = options[:class].strip.html_safe

  items = ControlsBuilder.new
  yield items if block_given?

  ("div", options) 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 delete_button(path, alternative_icon = false)
  options = {
      :confirm => t("activoate.confirm", :default => "Are you sure?"),
      :method => :delete
  }
  button(path, t("activoate.delete", :default => 'Delete'), alternative_icon ? 'delete' : 'cross', options)
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 edit_button(path, alternative_icon = false)
  button(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, options = {})
  return "" if name.nil?

  options[:alt] ||= name.capitalize.gsub("_", " ")

  path = "activo/icons/#{name}.png"

  image_tag path, { :alt => options[:alt] }
end

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.

Yields:

  • (menu)


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 navigation(options = {}, &block)
  options[:class] ||= ""
  options[:class] = options[:class].strip.html_safe

  menu = NavigationBuilder.new
  yield menu if block_given?

  ("div", options) do
    ("ul", "", :class => "wat-cf") do
      menu.collect { |item|
        ("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 secondary_inner_navigation(options = {}, &block)
  options[:class] ||= ""
  options[:class] << " secondary-inner-nav"

  navigation(options, &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 secondary_navigation(options = {}, &block)
  options[:class] ||= ""
  options[:class] << " secondary-navigation"

  navigation(options, &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_button(caption = 'submit', icon = 'show', options = {})
  default_options = { :class => "button", :type => 'submit' }
  options = default_options.merge(options)

  ("button", options) do
    image_tag("activo/icons/#{icon}.png", :alt => caption) + " " + caption
  end
end