Anybody out there interested in programmatic HTML generation? I know I am. I tried to do it once with perl and it worked out OK, but it didn''t make use of inheritance very well. A programmatic HTML package could be very useful if it was done right... I''m talking reusable components, not just like the HTML::Builder package, more of an inheritable class library of "widgets". -Jeff _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Rails has XML Builder support, which should work fine for XHTML: http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml http://builder.rubyforge.org/ -- rick http://techno-weenie.net
Yes I know, but I don''t see much advantage to using builder over plain html since you''re not really saving much work, and its still just as difficult to make good looking HTML. I''m not really sure how well it pans out, but I once tried to do something where I could define a class and subsequence classes that inherit all the parents content and add to it, beginning middle and end, I had moderate success. I looked into this with XML builder a while back and found it was generating text right as you used it, not a structure of components that you "output", so XML builder wouldn''t have worked, I was thinking REXML or libxml. So I was thinking more like a set of classes named after all the HTML elements, which validated themselves, could be added to and have items removed... a simple use case might look something like this: module MyWidgets include RPML # fictional module for "Ruby Programmatic Markup Language" class RedBox < Div attr :style => { ''background-color'' => ''red'' } content P.new(''Hello World'') end class RedBoxWithSubmit < RedBox add_content Input(''type'' => ''submit'') def initialize(value, *extras) content.last.attributes[''value''] = value super(*extras) end end end box = MyWidgets::RedBoxWithSubmit.new('' Continue '') Something like that. Pardon any syntax errors. I only bring this up because someone suggested I look at the seaside framework for smalltalk, and first thing I notice was it had a programmatic HTML generator, which I liked. -Jeff ----- Original Message ----- From: "Rick Olson" <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> Sent: Monday, April 04, 2005 2:21 PM Subject: Re: [Rails] Programmatic HTML generation> Rails has XML Builder support, which should work fine for XHTML: > > http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml > http://builder.rubyforge.org/ > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> So I was thinking more like a set of classes named after all the HTML > elements, which validated themselves, could be added to and have items > removed... a simple use case might look something like this:Although I''m not sure what exists for this, I''ve totally had thoughts in this vein. (That comes from learning rails while learning this newfangled CSS stuff at the same time; I''m using to coding old skool 90s-esqe HTML in vim, etc, etc...) But yes, this sounds like a good idea. This might be more of an erb-interface IMHO, although I could see rails helping things along. -d> module MyWidgets > include RPML # fictional module for "Ruby Programmatic Markup Language" > > class RedBox < Div > attr :style => { ''background-color'' => ''red'' } > content P.new(''Hello World'') > end > > class RedBoxWithSubmit < RedBox > add_content Input(''type'' => ''submit'') > > def initialize(value, *extras) > content.last.attributes[''value''] = value > super(*extras) > end > end > > end > > box = MyWidgets::RedBoxWithSubmit.new('' Continue '') > > Something like that. Pardon any syntax errors. I only bring this up because > someone suggested I look at the seaside framework for smalltalk, and first > thing I notice was it had a programmatic HTML generator, which I liked. > > -Jeff > > ----- Original Message ----- > From: "Rick Olson" <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Sent: Monday, April 04, 2005 2:21 PM > Subject: Re: [Rails] Programmatic HTML generation > > > Rails has XML Builder support, which should work fine for XHTML: > > > > http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml > > http://builder.rubyforge.org/ > > > > -- > > rick > > http://techno-weenie.net > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
> (That comes from learning rails while learning this > newfangled CSS stuff at the same time;You too, huh? I swear, I am spending more time learning CSS/DHTML than Rails/Ruby on this app I am using to learn Rails. I spent maybe ten hours on coding the functionality, and over twice that on the interface goodness, which still isn''t finished. I sure wish CSS were as easy to use as Rails -- Phillip J. Birmingham Software Engineer PJB Software http://pjbsoftware.com
On Apr 4, 2005 3:46 PM, Phillip Birmingham <pbirmingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > (That comes from learning rails while learning this > > newfangled CSS stuff at the same time; > > You too, huh? I swear, I am spending more time learning CSS/DHTML > than Rails/Ruby on this app I am using to learn Rails.Hell, I''m a seasoned CSS/XHTML pro (never touched DHTML though), and I spent more time designing my website than actually coding the rails app. ;)> I sure wish CSS were as easy to use as RailsWhoa there, hold on cowboy! CSS _is_ easy! It makes it very easy and straightforward to maintain consistency across multiple pages (eg, lets say you want to change the font size of something that appears on multiple pages -- would you rather be forced to make that change uniformly across a slew of .html files, or make it once in the centralised .css file? It seems that not using CSS is a violation of DRY ;) -- Urban Artography http://artography.ath.cx
> I''m talking reusable components, not just like the HTML::Builder > package, more of an inheritable class library of "widgets". >Hi, I have been using something in this vein for a while. The building syntax is very similar to the rails builder, but it allows subclassing and other stuff. It generates an internal DOM which you can safely manipulate. I''m the the middle of reimplementing my dom/builder/forms stuff, as I was planning to announce a public release when done, but I don''t see any problem in let you or anyone else who''s interested take a peek in it right now. If anyone is interested, let me know and I''ll wrap up the libriaries for you. Here''s some sample code from a form view: <%= form :action => "save", :object => ''author'' do |fm| fm.table_sec do fm.text_field :name, :initial_focus => true fm.text_field :email fm.text_field :website fm.text_field :descr, :rows => 8, :multiple => true fm.check_box :publish end fm.save_sec :destroy => url_for(:action => ''destroy'', :id => @author.id) fm.hidden_field :id unless @author.new_record? end %> Here''s the generated form; - the label''s for attrs are missing in this revision, but will be fixed soon - the translated labels are achieved by overriding humanize, but basically, the label text is generated by calling humanize on the field name (unless an explicit label parameter is passed). <form action="/admin/autores/save" method="post"> <div class="form-sec"> <table> <tr> <th> <label >Nome:</label> </th> <td> <input name="author[name]" size="50" class="text initial-focus" type="text" value="" /> </td> </tr> <tr> <th> <label >Email:</label> </th> <td> <input name="author[email]" size="50" class="text" type="text" value="" /> </td> </tr> <tr> <th> <label >Website:</label> </th> <td> <input name="author[website]" size="50" class="text" type="text" value="" /> </td> </tr> <tr> <th> <label >Descrição:</label> </th> <td> <textarea name="author[descr]" value="" rows="8" cols="50"></textarea> </td> </tr> <tr> <th></th> <td> <label ><input name="author[publish]" checked="checked" class="checkbox" type="checkbox" value="1" /> <input name="author[publish]" type="hidden" value="0" />Publicar</label> </td> </tr> </table> </div> <div class="form-sec" id="form-sec-save"> <input class="button submit" type="submit" value="Salvar" /> </div> </form>
> > I sure wish CSS were as easy to use as Rails > > Whoa there, hold on cowboy! CSS _is_ easy! [...] > It seems that not using CSS is a violation of > DRY ;)Eventually it starts making more sense, (and is a better way of doing things) but it''s a totally different way of looking at the page (vs. the old school), and it''s not the *easiest* thing to maintain if you don''t have fancy tools. On one hand, I head Dreamweaver is pretty magical, but editing others'' CSS files in Vim isn''t that much fun. Perhaps not worse than reading somebody else''s somewhat oddly written code, but still... I think I just need to find the better tools for wielding CSS. Caio, that stuff looks great! I look forward to seeing it. -d
Great! This looks perfect. Does it use REXML or libxml or something else? -Jeff ----- Original Message ----- From: "Caio Chassot" <k@v2studio.com> To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> Sent: Monday, April 04, 2005 5:00 PM Subject: Re: [Rails] Programmatic HTML generation> I''m talking reusable components, not just like the HTML::Builder package, > more of an inheritable class library of "widgets". >Hi, I have been using something in this vein for a while. The building syntax is very similar to the rails builder, but it allows subclassing and other stuff. It generates an internal DOM which you can safely manipulate. I''m the the middle of reimplementing my dom/builder/forms stuff, as I was planning to announce a public release when done, but I don''t see any problem in let you or anyone else who''s interested take a peek in it right now. If anyone is interested, let me know and I''ll wrap up the libriaries for you. Here''s some sample code from a form view: <%= form :action => "save", :object => ''author'' do |fm| fm.table_sec do fm.text_field :name, :initial_focus => true fm.text_field :email fm.text_field :website fm.text_field :descr, :rows => 8, :multiple => true fm.check_box :publish end fm.save_sec :destroy => url_for(:action => ''destroy'', :id => @author.id) fm.hidden_field :id unless @author.new_record? end %> Here''s the generated form; - the label''s for attrs are missing in this revision, but will be fixed soon - the translated labels are achieved by overriding humanize, but basically, the label text is generated by calling humanize on the field name (unless an explicit label parameter is passed). <form action="/admin/autores/save" method="post"> <div class="form-sec"> <table> <tr> <th> <label >Nome:</label> </th> <td> <input name="author[name]" size="50" class="text initial-focus" type="text" value="" /> </td> </tr> <tr> <th> <label >Email:</label> </th> <td> <input name="author[email]" size="50" class="text" type="text" value="" /> </td> </tr> <tr> <th> <label >Website:</label> </th> <td> <input name="author[website]" size="50" class="text" type="text" value="" /> </td> </tr> <tr> <th> <label >Descrição:</label> </th> <td> <textarea name="author[descr]" value="" rows="8" cols="50"></textarea> </td> </tr> <tr> <th></th> <td> <label ><input name="author[publish]" checked="checked" class="checkbox" type="checkbox" value="1" /> <input name="author[publish]" type="hidden" value="0" />Publicar</label> </td> </tr> </table> </div> <div class="form-sec" id="form-sec-save"> <input class="button submit" type="submit" value="Salvar" /> </div> </form> _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jeffrey Moss wrote:> Great! This looks perfect. Does it use REXML or libxml or something else?It uses a custom dom i developed myself, which is more focused towards xhtml rather than plain xml. I don''t know how it fares against the libs you mention. I know I prefer it over the rails builder.
Hi Caio, I''d be very interested in seeing/using your code for generating forms etc. if you plan on releasing it or just making it available. Cheers, Gavin On Tuesday, April 5, 2005, 3:25:55 PM, Caio wrote about his HTML generation code: [...]