Box of Tricks

This gem contains a bunch of CSS classes and Rails helper methods that we rely upon regularly

View Helpers

BoxOfTricks#title

# 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  
def title(content = nil)
  content ? @content = content : @content
end

BoxOfTricks#field

<%= field id: "my_field", class: "user_form" do %>
  <%= text_field_tag :user, :username %>
<% end %>
<!-- generates: -->
<div class="field user_form" id="my_field">
  <input type="text" name="user[username]" id="user_username">
</div>

BoxOfTricks#actions

<%= actions id: "my_actions", class: "user_form" do %>
  <%= submit_tag("Save") %>
<% end %>
<!-- generates: -->
<div class="actions user_form" id="my_actions">
  <input type="submit" value="Save" id="user_submit">
</div>

BoxOfTricks#div

<%= div id: "some_div", class: "vague_class" do %>
  <%= link_to("Click here", "#") %>
<% end %>
<!-- generates: -->
<div id="some_div" class="vague_class">
  <a href="#">Click here</a>
</div>

CSS

HTML5 Reset Sheet

To include an HTML reset to your CSS, simply add the following to your application.css file:

/* 
*= require html5reset 
*/

There's also a file named *box_of_tricks.css.scss which comes with a bunch of CSS classes that I constantly rely on.

/* 
*= require html5reset 
*/