I thought I'd make up pseudo rhtml/ruby code I would like to use to create table views in html.
I basically need flexible helpers to create tables (and later lists). I do not want to write over and over again the same stuff.
This is what I made up in about an hour. I am still new to RoR.
What do you think about this approach? Which problems do you see theoretically, practically and implementation wise? Can you suggest another maybe better approach?
I hope for some feedback.
(jt just stands for jonas tag, i wanted to make sure that i wont take any actionview method name that might probably be used in future rails versions like table_tag_start or so)
<% jt_table_begin :for => jt_create_data_from @categories, :options => { :print_html_comments => false } -%> <!-- the option in the table tag method removes any html comments from the output --> <!-- raw data between begins and ends is being parsed to extend given tags by class / id attributes and fill values of elements/tags --> <table cellspacing="0" cellpadding="0"> <!-- all these parameters are optional --> <!-- jt_tr_begin adds a adds (or, like in this case, if given) extends a tr_tag --> <% jt_loop_data -%> <% jt_tr_begin :css_helpers => { :numerate, :first_n_last, :odd_n_even, :id => :primary_key_id } -%> <tr width="100%"> <% jt_loop_data -%> <!-- following is method block (jt_th_begin until jt_th_end) "probably" result into something like this: <th align="center" valign="middle" class="no1 first name"> <a href="#order_swap">Name</a> <a href="#order_asc">↑</a> <a href="#order_desc">↓</a> </th> <th align="center" valign="middle" class="no2 status"> Status </th> <th align="center" valign="middle" class="no3 updated_on"> <a href="#order_swap">Updated on</a> <a href="#order_asc">↑</a> <a href="#order_desc">↓</a> </th> <th align="center" valign="middle" class="no4 last created_on"> <a href="#order_swap">Created on</a> <a href="#order_asc">↑</a> <a href="#order_desc">↓</a> </th> --> <% jt_th_begin :colums_show => { :name, :status, :updated_on, :created_on }, :colums_orderable => { :name, :updated_on, :created_on }, :css_helpers => { :numerate, :first_n_last, :class => :column_name } ) -%> <th align="center" valign="middle"> <% jt_loop_data -%> </th> <% jt_th_end -%> <% jt_td_begin :css_helpers => { :numerate, :first_n_last, :odd_n_even } -%> <td valign="top"> <% jt_loop_data -%> </td> <% jt_td_end -%> <% jt_tr_end -%> <% jt_table_end -%>
What do you think?