Skip to content
Newer
Older
100644 183 lines (123 sloc) 5.11 KB
c5af34f @pupeno Fixed displaying the CI results.
pupeno authored
1 <a href="http://travis-ci.org/watu/table_builder"><img src="https://secure.travis-ci.org/watu/table_builder.png" alt="Continuous integration status"/></a>
f3ec709 @pupeno Use markdown for documentation.
pupeno authored
2
3
4 About watu_table_builder
5 ========================
6
7 watu_table_builder is a fork of [table_builder](https://github.com/jchunky/table_builder) in an effort to bring it up to
8 speed with the current Ruby and Rails practices (bundler, gem, ci) as well as maybe re-vive it, start merging useful
9 branches, implementing new features, fixing bugs, etc.
10
11 Install
12 =======
13
14 Add this to your Gemfile:
15
16 gem "watu_table_builder", :require => "table_builder"
17
18 or if you prefer to use it straight from GitHub:
19
56d962a @pupeno Fixed install instructions for git. Closes #6.
pupeno authored
20 gem "watu_table_builder", :require => "table_builder", :git => "git://github.com/watu/table_builder.git"
f3ec709 @pupeno Use markdown for documentation.
pupeno authored
21
22 TableBuilder
23 ============
24
25 Rails builder for creating tables and calendars inspired by ActionView's FormBuilder, updated for Rails 3.0beta
26 This is a fork of Petrik de Heus plugin for earlier versions of Rails. Note the new idiomatic use of "<%=" for the
27 table_for and calendar_for functions.
28
29 Examples
30 ========
31
32 table_for has methods for each tag used in a table (table, thead, tr, td, etc.)
33
34 A basic example would look like this:
35
36 @front_men = [FrontMan.new(1, 'David St. Hubbins'), FrontMan.new(2, 'David Lee Roth')]
37
38 and
39
40 <%= table_for(@front_men) do |t| %>
41 <%= t.head do %>
42 <%= t.r do %>
43 <%= t.h('Id') %>
44 <%= t.h('Name') %>
45 <% end %>
46 <% end %>
47 <%= t.body do |front_man| %>
48 <%= t.r do %>
49 <%= t.d(h(front_man.id)) %>
50 <%= t.d(h(front_man.name)) %>
51 <% end %>
52 <% end %>
53 <% end %>
54
55 You can pass an array to the head method:
56
57 <%= t.head('Id', 'Name') %>
58
59 The body and r method can be combined for easier usage:
60
61 <%= t.body_r do |front_man| %>
62 <%= t.d(h(front_man.id)) %>
63 <%= t.d(h(front_man.name)) %>
64 <% end %>
65
66 You can also pass blocks to the d and h methods for more flexibility:
67
68
69 <%= t.d(:class => 'name') do %>
70 <%= link_to(h(front_man.name), front_man_url(front_man)) %>
71 <% end %>
72
73 All tag methods are rails tag methods, so they can have extra html options.
74
75 @drummers = [Drummer.new(1, 'John "Stumpy" Pepys'), Drummer.new(2, 'Eric "Stumpy Joe" Childs')]
76
77 and
78
79 <%= table_for(@drummers, :html => { :id => 'spinal_tap', :class => 'drummers'}) do |t| %>
80 <%= t.body_r(:class => 'row') do |e| %>
81 <%= t.d(h(e.id), :title => 'id') %>
82 <%= t.d(h(e.name)) %>
83 <% end %>
84 <% end %>
85
86 which produces the following html:
87
88 <table class="drummers" id="spinal_tap">
89 <tbody>
90 <tr class="row">
91 <td title="id">1</td>
92 <td>John &quot;Stumpy&quot; Pepys</td>
93 </tr>
94 <tr class="row">
95 <td title="id">2</td>
96 <td>Eric &quot;Stumpy Joe&quot; Childs</td>
97 </tr>
98 </tbody>
99 </table>
100
101
102 You can customize the table by creating your own TableBuilder:
103
104 <%= table_for(@drummers, :builder => PagedTableBuilder) do |t| %>
105
106 Calendar Table
107 ==============
108
109 calendar_for creates a table like table_for.
110 All objects get sorted per day of the month
111
112 A basic example would look like this:
113
114 @tasks = Task.this_month
115
116 and
117
118 <%= calendar_for(@tasks) do |t| %>
119 <%= t.head('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') %>
120 <%= t.day do |day, tasks| %>
121 <%= day.day %>
122 <% tasks.each do |task| %>
123 <%= h(task.name) %>
124 <% end %>
125 <% end %>
126 <% end %>
127
128 To show a different month you can pass the :year and :month options:
129
130 <%= calendar_for(@tasks, :year => 2009, :month => 1) do |t| %>
131
132 To highlight a different day you can pass the :today option:
133
134 <%= calendar_for(@tasks, :today => Date.civil(2008, 12, 26)) do |t| %>
135
136 By default the :date method is called on the objects for sorting.
137 To use another method you can pass the :day_method option:
138
139 <%= t.day(:day_method => :calendar_date) do |day, tasks| %>
140
141 If you want to add id's to your td tag you can pass a pattern:
142
143 <%= t.day(:id => 'day_%d') do |day, tasks| %>
144
145 To have a header at the begining of each row:
146
147 <%= calendar_for(@tasks, :row_header => true) do |t| %>
148
149 and then in your block you get nil as the list of objects and the first day of thet upcoming week. For example:
150
151 <%= calendar_for(@tasks) do |t| %>
152 <%= t.day do |day, tasks| %>
153 <% if tasks.nil? %>
154 <%= day.cweek %>
155 <% else %>
156 <%= day.day %>
157 <% tasks.each do |task| %>
158 <%= h(task.name) %>
159 <% end %>
160 <% end %>
161 <% end %>
162 <% end %>
163
164 Contributing
165 ============
166
167 Document any new options and verify the documentation looks correct by running:
168
169 yard server --reload
170
171 and going to http://localhost:8808
172
173 Contributors
174 ============
175
176 Petrik de Heus, Sean Dague, F. Kocherga, John Duff, Andrew C. Greenberg, Jason Cheong-Kee-You, [J. Pablo Fernández](http://pupeno.com).
177
178 Original Work Copyright (c) 2008 Petrik de Heus, released under the MIT license.
179
180 Fork revisions Copyright (c) 2010 Andrew C. Greenberg, released under the MIT license.
181
182 Fork revisions Copyright (c) 2012 [Carrousel Apps Ltd (Watu)](http://watuhq.com), released under the MIT license.
Something went wrong with that request. Please try again.