<commit_before># Easy Table

Table helpers for your views to facilitate creating tables using a nice DSL similar to what 'simpleform' and 'formtastic' are for forms ;)

## Install

<code>gem install easy-table</code>

## Demo

<pre> 
  <code>
  data_table @posts, %w{Id Title}, :summary => 'many posts', :caption => 'posts table'  

  =>
  <table>
    <thead>
      <tr>
        <th>id</th>
        <th>title</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>my post</td>
      </tr>
      <tr>
        <td>2</td>
        <td>my other post</td>
      </tr>
    </tbody>
  </table>  
  </code>
</pre>

## Helpers

The following is the current Table Helper API. 

_Note:_ This API clearly needs to be cleaned up in the "near" future ;)

### Table

* data_table
* table
* render_table

### Table parts

* render_tbody
* table_body
* render_caption
* render_header
* render_footer
* header_row

### Rows

* row
* data_rows
* data_row

### Cells

* cells
* cell

### Misc

* indent_tag_

## Usage   

The following examples might not all be compatible with any API changes. 
Please raise an issue if you find a mismatch or have a problem using it ;)
Thanks!

Example: Using *table* helper

<pre>
  <% table @posts, %w{ID title} do |post, klass| -%><commit_msg>updated README with various notes for future changes<commit_after># Easy Table

Table helpers for your views to facilitate creating tables using a nice DSL similar to what 'simpleform' and 'formtastic' are for forms ;)

_Note:_ Updated with some notes on API changes and refactorings planned for the near future

## Install

<code>gem install easy-table</code>

## Demo

<pre> 
  <code>
  data_table @posts, %w{Id Title}, :summary => 'many posts', :caption => 'posts table'  

  =>
  <table>
    <thead>
      <tr>
        <th>id</th>
        <th>title</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>my post</td>
      </tr>
      <tr>
        <td>2</td>
        <td>my other post</td>
      </tr>
    </tbody>
  </table>  
  </code>
</pre>

## TODO

Encapsulate much of the functionality better

* method *table* => return EasyTable::Table object
* method *row* => return EasyTable::Row object 
* method *t.headers* => return EasyTable::Header object 

Clean up directory structure to put methods in the right, folders, files and containers. Also, avoid cramming too many functions into the View!


Future API (should be part of *tables_on_roles* gem)
<pre>
  data_table posts, %w{id name}, :actions => {:edit => :owner, :delete => :admin}

  # Provide labels and role lists  
  data_table posts, %w{id name}, :actions => {:edit => [:owner, 'Edit post], :delete => [:admin, :owner, 'Delete the post']}  
</pre>

## Helpers

The following is the current Table Helper API. 

_Note:_ This API clearly needs to be cleaned up in the "near" future ;)

### Table

* data_table
* table => EasyTable::Table
* render_table (rename to table_tag)

### Table parts


* table_body (rename to tbody)

The following methods should only be available on the EasyTable::Table object returned by *table*

* render_tbody -> t.tbody, tbody_tag
* render_caption -> t.caption, caption_tag
* render_header -> t.head, thead_tag
* render_footer -> t.footer, tfoot_tag
* header_row -> t.header

### Rows

* data_rows
* data_row
* row : => EasyTable::Row

### Cells

* cells, r.cells
* cell, r.cell, cell_tag

### Misc

* indent_tag

## Usage   

The following examples might not all be compatible with any API changes. 
Please raise an issue if you find a mismatch or have a problem using it ;)
Thanks!

Example: Using *table* helper

<pre>
  <% table @posts, %w{ID title} do |post, klass| -%>
{'fraction_non_alphanumeric': 0.12784398699891658, 'fraction_numerical': 0.0010834236186348862, 'mean_word_length': 3.135498320268757, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6046836', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1215, 'n_words': 438}