Permalink
Newer
Older
100644 101 lines (84 sloc) 3.55 KB
1
h1. Viewaide
Joshua Clayton
Apr 28, 2009
2
3
Viewaide contains a set of view helpers made to standardize basic HTML structures and provide simple Blueprint CSS integration.
Feb 9, 2010
4
5
h2. Installation
6
7
Viewaide is a gem and should be declared in your @config/environment.rb@.
8
Feb 9, 2010
9
<pre><code>config.gem "viewaide"</code></pre>
Feb 9, 2010
10
11
h2. Usage
12
13
Viewaide has a handful of helpers for things like recordsets and zebra rows (@<table>@s and @<tr>@s), columns (@<div class="span-#">@), fieldsets, sets (for input elements), and more.
14
15
For a full overview of what the library does, head to "the documentation":http://yardoc.org/docs/frames/joshuaclayton-viewaide. Here's a brief overview.
16
Feb 9, 2010
17
<pre><code># layouts/admin.html.erb
18
<!DOCTYPE html>
19
<html lang="en">
20
<head>
21
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
22
<title><%= application_name %></title>
23
<%= stylesheet_link_tag *%w(screen my-screen) %>
24
<!--[if lt IE 8]>
25
<%= stylesheet_link_tag "ie" %>
26
<![endif]-->
27
<%= yield :head %>
28
</head>
29
<% body :admin do %>
30
<% container do %>
31
<% column :header do %>
32
<h1><%= link_to "#{application_name} - Admin", admin_root_path %></h1>
33
<%= render :partial => "layouts/admin_navigation" %>
34
<% end %>
35
<% column do %>
36
<%= messages(flash) %>
37
<h2><%= yield :page_title %></h2>
38
<%= yield %>
Feb 9, 2010
39
<% end %>
40
<%= render :partial => "layouts/footer" %>
Feb 9, 2010
41
<% end %>
42
<%= yield :footer %>
43
</body>
44
</html>
45
46
# admin/users/index.html.erb
47
<% body :additional_class %>
48
<% column :three_fourths, :content do %>
49
<% recordset do %>
50
<thead>
51
<tr>
52
<th>Name</th>
53
<th>Email Address</th>
54
<th>Confirmed At</th>
55
</tr>
56
</thead>
57
<tbody>
58
<% @users.each do |user| %>
59
<% zebra_row do %>
60
<td><%= user.name %></td>
61
<td><%= link_to_email user.email %></td>
62
<td><%= datetime user.confirmed_at, "Unconfirmed" %></td>
Feb 9, 2010
63
<% end %>
64
<% end %>
65
</tbody>
66
<% end %>
67
<% end %>
68
<% column :one_fourth, :last do %>
69
<%= link_button "Create New User", new_admin_user_path %>
70
<% form_for :user, :url => admin_users_path, :action => :get do |form| %>
71
<% fieldset "Search" do %>
72
<% set do %>
73
<%= form.label :search %>
74
<%= form.text_field :search %>
75
<% end %>
76
<% end %>
77
<% fieldset "Filter" do %>
78
<% set :select do %>
79
<%= form.label :filter %>
80
<%= form.select :filter, filter_options_for_users %>
Feb 9, 2010
81
<% end %>
82
<% end %>
83
<%= submit_button "Filter" %>
84
<% end %>
Feb 9, 2010
85
<% end %></pre></code>
Feb 9, 2010
86
87
h2. Conventions
88
89
Most of the helpers (@body@, @container@, @column@, @fieldset@, @set@, @submit_button@, and @recordset@) support some sort of splat arguments and a hash; that is, they take a handful of classes and a hash of additional attributes.
Feb 9, 2010
90
Feb 9, 2010
91
<pre><code># at the top of a view
92
<% body :admin, "another-class", :id => "body-id" %></code></pre>
Feb 9, 2010
93
94
This helper would attach the admin and another-class classes, as well as an id of 'body-id', to the @<body>@ element (if the @body@ helper is used in the layout). This convention allows developers to quickly and easily assign multiple classes without worry of duplication to the HTML structures generated.
Feb 9, 2010
95
96
h2. Patches, Tweaks, or Fixes?
97
98
Fork the project, write (failing) tests, write code to get the tests to pass, rake to ensure the entire suite passes, and commit. Send me a pull request once everything is working. Do not touch Rakefile or version of the project. If you write code without tests, I'm not going to accept it.
Feb 9, 2010
99
Joshua Clayton
Apr 28, 2009
100
Copyright (c) 2009 Josh Clayton, released under the MIT license