Permalink
Browse files

README update

  • Loading branch information...
Iain Hecker
Iain Hecker committed Nov 5, 2008
1 parent 14dee0e commit 68d2cb03f6b80ddab514d1958a7616a3b84665bb
Showing with 79 additions and 47 deletions.
  1. +79 −47 README.textile
View
@@ -1,23 +1,28 @@
h1. ModelBasedHtml
This plugin enables the binding of other html elements to models, comparable
-with form_for. This plugin works best with "Haml":http://haml.hamptoncatlin.com/,
-which I strongly recommend. I still use ERB in these examples to reach a
-bigger audience.
+with form_for. The idea is that you can bind common html-elements to an object
+or collection and that you can easily view the data. At the moment, it includes
+definition lists and tables. For any suggestions, please send me a message.
+
+This plugin works best with "Haml":http://haml.hamptoncatlin.com/,
+which I strongly recommend. This plugin works fine with ERB though.
+
+This plugin requires Rails 2.2 or higher!
h2. Definition Lists
I'll start with an example, which explains the basic methods you can use:
- <% definition_list_for @user do |dl| %>
- <%= dl.dt_and_dd :login %>
- <%= dl.dt :email %>
- <%= dl.dd :email do |mail_address| %>
- <%= mail_to mail_address %>
- <% end %>
- <%= dl.dt :signature %>
- <%= dl.dd_h :signature %>
- <% end %>
+ - definition_list_for @user do |dl|
+ - dl.dt_and_dd :login do |login|
+ = link_to(login, @user)
+ - dl.dt_and_dd_h :name
+ - dl.dt :email
+ - dl.dd :email do |mail_address|
+ = mail_to mail_address
+ - dl.dt 'some other value'
+ - dl.dd_h :signature
The dt method will automatically display the human_attribute_name of this
attribute (and thus translate it), the dd will automatically show the value
@@ -30,45 +35,72 @@ h2. Tables
A similar option is available for tables.
- <% table_for @users do |table| %>
- <% table.thead do %>
- <%= table.th :login %>
- <%= table.th :email %>
- <%= table.th :signature %>
- <% end %>
- <% table.tbody :sanitize => true %>
- <% end %>
-
-By not specifying a block to table.tbody, it automatically loops all records.
-Setting :sanitize to true will automatically escape all html in the tds.
-If you do specify a block to tbody, you can define each cell, just as you would
-do with the definition list. It automatically loops.
-
- <% table_for @users do |table| %>
- <% table.thead do %>
- <%= table.th :login %>
- <%= table.th :email %>
- <%= table.th :signature %>
- <% end %>
- <% table.tbody do |user| %>
- <% table.tr do %>
- <%= table.td :login
- <%= table.td :email do |email| %>
- <%= mail_to(email) %>
- <% end %>
- <%= table.td_h :signature %>
- <% end %>
- <% end %>
- <% end %>
+ - table_for @users do |t|
+ - t.head do
+ - t.th :login
+ - t.th :email
+ - t.th :signature
+ - t.body :sanitize => true
+ - t.when_empty do |message|
+ %em= message
+ - t.when_not_empty do
+ - t.tr do
+ - t.td(nil, :colspan => t.width) do
+ %em An extra row
+
+By not specifying a block to t.body, it automatically loops all records,
+using the columns specified in the t.head. Setting :sanitize to true will
+automatically escape all html in the tds, but only when no block has been
+specified.
+
+With t.when_empty you can specify what will be placed *in stead of* the table
+when the collection was empty. If you don't specify anything, not even a block
+it will render a default text, like "no entries found". This is a translate
+call, trying these scopes for the type:
+
+# entries.controller_name
+# entries.common
+
+And these scopes for the rest of the method (enabling interpolation of the
+above):
+
+# tables.nil_class.empty_table
If the collection was empty, it doesn't render a table at all. You can still
force a table to render, so you can fill it with your own data. Fill the :force
-option with the class you're using. A td with the proper colspan will be
-rendered with a translatable message.
+option with the class you're using.
+
+ - table_for @users, :force => User do |t|
+ - t.head do
+ - t.th :login
+ - t.when_empty
+
+Now the when_empty renders a td with a colspan to match the width of the table.
+The default translation scope of the message will be:
+
+# tables.user.empty_table
+
+The model interpolation will be the human_name (thus translated) of the class.
+
+If you do specify a block to t.body, you can define each cell, just as you
+would do with the definition list. It automatically loops your data. The tr
+will get a odd or even class automatically.
+
+ - table_for @users do |t|
+ - t.head do
+ - t.th :login
+ - t.th :email
+ - t.th :signature
+ - t.th 'Actions'
+ - t.body do |user|
+ - t.tr do
+ - t.td :login
+ - t.td :email do |email|
+ = mail_to(email)
+ - t.td_h :signature
+ - t.td do
+ = link_to('delete', user, :method => :delete)
- <% table_for @users, :force => User do |table| %>
- # etc...
- <% end %>
h1. Nota bene

0 comments on commit 68d2cb0

Please sign in to comment.