Jonas Hartmann
2006-Nov-07 18:03 UTC
Solution to generate table output of data, comments and suggestions please.
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---