Module: BoxOfTricksHelper

Defined in:
app/helpers/box_of_tricks_helper.rb

Instance Method Summary collapse

Instance Method Details

#actions(*args, &block) ⇒ Object

Creates a div with class ‘actions’. All of the usual options may also be applied here including the class argument.

<%= actions class: "sign_up_actions", id: "sign_up_links" do %>
  <%= f.submit "Sign Up" %>
<% end %>
<!-- generates -->
<div class="actions sign_up_actions" id="sign_up_links">
  <input type="submit" value="Sign Up">
</div>

Content may be passed as a block or as the first argument

Author:

  • Gavin Morrice



45
46
47
# File 'app/helpers/box_of_tricks_helper.rb', line 45

def actions(*args, &block)
  div_with_class(:actions, *args, &block)
end

#clearfixObject

Add a
tag to clear any floated elements which came before



63
64
65
# File 'app/helpers/box_of_tricks_helper.rb', line 63

def clearfix
  %{<br class="clear">}
end

#div(*args, &block) ⇒ Object

Creates a div tag. This is basically a short-hand for

(:div)

Author:

  • Gavin Morrice



52
53
54
# File 'app/helpers/box_of_tricks_helper.rb', line 52

def div(*args, &block)
  (:div, *args, &block)
end

#field(*args, &block) ⇒ Object

Creates a div with class ‘field’. All of the usual options may also be applied here including the class argument.

<%= field "Hello", class: "my_field", id: "field_1" %>
<!-- generates -->
<div class="my_field field" id="field_1">Hello</div>

Content may be passed as a block or as the first argument

Author:

  • Gavin Morrice



30
31
32
# File 'app/helpers/box_of_tricks_helper.rb', line 30

def field(*args, &block)
  div_with_class(:field, *args, &block)
end

#html5_shimObject

Load a JS file if browser is Internet Explorer to ensure backward-compatibility of HTML5 elements



58
59
60
# File 'app/helpers/box_of_tricks_helper.rb', line 58

def html5_shim
  %{<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->}.html_safe
end

#title(content = nil) ⇒ Object

Sets the page title if passed an argument, otherwise returns the page title.

# layouts/application.html.erb
<DOCTYPE!>
<html>
<head>
  <title><%= title %></title>
</head>
<body>
  <%= yield %>
</body>
</html>

# users/show.hmtl.erb
<% title @user.username %>

Content may be passed as a block or as the first argument

Author:

  • Gavin Morrice



19
20
21
# File 'app/helpers/box_of_tricks_helper.rb', line 19

def title(content = nil)
  content ? @title = content : @title
end