README.md in admino-0.0.6 vs README.md in admino-0.0.7

- old
+ new

@@ -369,16 +369,16 @@ <th role='completed'>Completed</th> <th role='due-date'>Due date</th> </tr> <thead> <tbody> - <tr id='task_1' class='is-even'> + <tr class='is-even'> <td role='title'>Call mum ASAP</td> <td role='completed'>✓</td> <td role='due-date'>2013-02-04</td> </tr> - <tr id='task_2' class='is-odd'> + <tr class='is-odd'> <!-- ... --> </tr> <tbody> </table> ``` @@ -405,11 +405,11 @@ <!-- ... --> <th role='actions'>Actions</th> </tr> <thead> <tbody> - <tr id='task_1' class='is-even'> + <tr class='is-even'> <!-- ... --> <td role='actions'> <a href='/admin/tasks/1' role='show'>Show</a> <a href='/admin/tasks/1/edit' role='edit'>Edit</a> <a href='/admin/tasks/1' role='destroy' data-method='delete'>Destroy</a> @@ -566,9 +566,49 @@ ```erb <%= CustomTablePresenter.new(@tasks, Task, self).to_html do |row, record| %> <%# ... %> <%= row.actions :show, :edit, :destroy %> <% end %> +``` + +### Showcase::Traits::Record + +As funny it may sound, it is strongly suggested to pass to the table presenter an array of records which in turn have been already presented. This enables you to use as columns not only the raw attributes of the model, but all the methods defined in the presenter. + +Furthermore, if the record presenter includes the `Showcase::Traits::Record` trait, each row of the table will automatically have an unique id attribute thanks to the [`#dom_id` method](https://github.com/stefanoverna/showcase#dom_id). + +```ruby +class TaskPresenter < Showcase::Presenter + include Showcase::Traits::Record + + def truncated_title + h.truncate(title, length: 50) + end +end +``` + +```erb +<% tasks = present_collection(@tasks) + +<%= Admino::Table::Presenter.new(tasks, Task, self).to_html do |row, record| %> + <%= row.column :truncated_title, 'Title' %> +<% end %> +``` + +```html +<table> + <thead> + <th role='truncated-title'>Title</th> + <thead> + <tbody> + <tr id='task_1' class='is-even'> + <td role='truncated-title'>Call mum ASAP</td> + </tr> + <tr id='task_2' class='is-odd'> + <td role='truncated-title'>Buy some milk</td> + </tr> + <tbody> +</table> ``` ### I18n Column titles are generated using the model [`#human_attribute_name`](http://apidock.com/rails/ActiveRecord/Base/human_attribute_name/class) method, so if you already translated the model attribute names, you're good to go. To translate actions, please refer to the following YAML file: