Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 133 lines (90 sloc) 3.516 kb
aae7d30 @p8 Improved documentation
p8 authored
1 = TableBuilder
f609979 @p8 Improved documentation
p8 authored
2
aae7d30 @p8 Improved documentation
p8 authored
3 Rails builder for creating tables and calendars inspired by ActionView's FormBuilder.
f609979 @p8 Improved documentation
p8 authored
4
aae7d30 @p8 Improved documentation
p8 authored
5 == Examples
6
7 table_for has methods for each tag used in a table (<table>, <thead> <tr>, <td>, etc.)
8
9 A basic example would look like this:
f609979 @p8 Improved documentation
p8 authored
10
11 @front_men = [FrontMan.new(1, 'David St. Hubbins'), FrontMan.new(2, 'David Lee Roth')]
12
13 <% table_for(@front_men) do |t| %>
8097415 @p8 Improved documentation
p8 authored
14 <% t.head do %>
15 <% t.r do %>
16 <%= t.h('Id') %>
17 <%= t.h('Name') %>
18 <% end %>
19 <% end %>
9e05eab @p8 Improved documentation
p8 authored
20 <% t.body do |front_man| %>
8097415 @p8 Improved documentation
p8 authored
21 <% t.r do %>
22 <%= t.d(h(front_man.id)) %>
23 <%= t.d(h(front_man.name)) %>
24 <% end %>
f609979 @p8 Improved documentation
p8 authored
25 <% end %>
26 <% end %>
27
28 You can pass an array to the head method:
29
30 <%= t.head('Id', 'Name') %>
31
32
aae7d30 @p8 Improved documentation
p8 authored
33 The body and r method can be combined for easier usage:
34
8097415 @p8 Improved documentation
p8 authored
35 <% t.body_r do |front_man| %>
36 <%= t.d(h(front_man.id)) %>
37 <%= t.d(h(front_man.name)) %>
38 <% end %>
aae7d30 @p8 Improved documentation
p8 authored
39
40 You can also pass blocks to the d and h methods for more flexibility:
f609979 @p8 Improved documentation
p8 authored
41
42 <%= t.d(:class => 'name') do %>
aae7d30 @p8 Improved documentation
p8 authored
43 <%= link_to(h(front_man.name), front_man_url(front_man)) %>
f609979 @p8 Improved documentation
p8 authored
44 <% end %>
45
aae7d30 @p8 Improved documentation
p8 authored
46 All tag methods are rails tag methods, so they can have extra html options.
f609979 @p8 Improved documentation
p8 authored
47
48 @drummers = [Drummer.new(1, 'John "Stumpy" Pepys'), Drummer.new(2, 'Eric "Stumpy Joe" Childs')]
49
50 <% table_for(@drummers, :html => { :id => 'spinal_tap', :class => 'drummers'}) do |t| %>
aae7d30 @p8 Improved documentation
p8 authored
51 <% t.body_r(:class => 'row') do |e| %>
802d4fd @p8 Improved documentation
p8 authored
52 <%= t.d(h(e.id), :title => 'id') %>
f609979 @p8 Improved documentation
p8 authored
53 <%= t.d(h(e.name)) %>
54 <% end %>
55 <% end %>
56
57 ... which produces the following html:
58
59 <table class="drummers" id="spinal_tap">
aae7d30 @p8 Improved documentation
p8 authored
60 <tbody>
61 <tr class="row">
802d4fd @p8 Improved documentation
p8 authored
62 <td title="id">1</td>
aae7d30 @p8 Improved documentation
p8 authored
63 <td>John &quot;Stumpy&quot; Pepys</td>
64 </tr>
65 <tr class="row">
802d4fd @p8 Improved documentation
p8 authored
66 <td title="id">2</td>
aae7d30 @p8 Improved documentation
p8 authored
67 <td>Eric &quot;Stumpy Joe&quot; Childs</td>
68 </tr>
69 </tbody>
f609979 @p8 Improved documentation
p8 authored
70 </table>
71
732c95c @p8 Improved documentation
p8 authored
72 You can customize the table by creating your own TableBuilder:
73
74 <% table_for(@drummers, :builder => PagedTableBuilder) do |t| %>
75
f609979 @p8 Improved documentation
p8 authored
76
aae7d30 @p8 Improved documentation
p8 authored
77 == Calendar Table
78
732c95c @p8 Improved documentation
p8 authored
79 calendar_for creates a table like table_for.
aae7d30 @p8 Improved documentation
p8 authored
80 All objects get sorted per day of the month
81
732c95c @p8 Improved documentation
p8 authored
82 A basic example would look like this:
aae7d30 @p8 Improved documentation
p8 authored
83
84 @tasks = Task.this_month
85
86 <% calendar_for(@tasks) do |t| %>
87 <%= t.head('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') %>
732c95c @p8 Improved documentation
p8 authored
88 <% t.day do |day, tasks| %>
aae7d30 @p8 Improved documentation
p8 authored
89 <%= day.day %>
90 <% tasks.each do |task| %>
91 <%= h(task.name) %>
92 <% end %>
93 <% end %>
94 <% end %>
f609979 @p8 Improved documentation
p8 authored
95
732c95c @p8 Improved documentation
p8 authored
96 To show a different month you can pass the :year and :month options:
97
98 <% calendar_for(@tasks, :year => 2009, :month => 1) do |t| %>
99
100 To highlight a different day you can pass the :today option:
101
102 <% calendar_for(@tasks, :today => Date.civil(2008, 12, 26)) do |t| %>
103
104 By default the :date method is called on the objects for sorting.
105 To use another method you can pass the :day_method option:
106
107 <% t.day(:day_method => :calendar_date) do |day, tasks| %>
108
21bb3fd @p8 Updated doucmentation
p8 authored
109 If you want to add id's to your td tag you can pass a pattern:
110
111 <% t.day(:id => 'day_%d') do |day, tasks| %>
732c95c @p8 Improved documentation
p8 authored
112
f609979 @p8 Improved documentation
p8 authored
113
aae7d30 @p8 Improved documentation
p8 authored
114 == Install
f609979 @p8 Improved documentation
p8 authored
115
e36c64a @p8 Use as plugin for now
p8 authored
116 script/plugin install git://github.com/p8/table_builder.git
f609979 @p8 Improved documentation
p8 authored
117
248f4cb @p8 Made reference to pre-rails 3.0 version
p8 authored
118 For a pre rails 3.0 table_builder:
182c92f @p8 Merged with maca/master
p8 authored
119 script/plugin install git://github.com/p8/table_builder.git
248f4cb @p8 Made reference to pre-rails 3.0 version
p8 authored
120 cd vendor/plugins/table_builder/
121 git checkout pre-rails-2.2
6510f5d @p8 Added documentation for pre rails 2.2 error
p8 authored
122
248f4cb @p8 Made reference to pre-rails 3.0 version
p8 authored
123 For a pre rails 2.2 table_builder:
182c92f @p8 Merged with maca/master
p8 authored
124 script/plugin install git://github.com/p8/table_builder.git
6510f5d @p8 Added documentation for pre rails 2.2 error
p8 authored
125 cd vendor/plugins/table_builder/
126 git checkout pre-rails-2.2
351c69f @p8 Added Sean Dague to the contributors list
p8 authored
127
128 == Contributors
129
66cd31d @p8 Added contributors F. Kocherga and John Duff to README
p8 authored
130 Thanks to Sean Dague, F. Kocherga, John Duff.
f609979 @p8 Improved documentation
p8 authored
131
132 Copyright (c) 2008 Petrik de Heus, released under the MIT license
Something went wrong with that request. Please try again.