From: Michael Neumann Date: 2005-02-17T16:27:24+09:00 Subject: Re: Wee web-framework. It's great! Joao Pedrosa wrote: > Hi, > > I think it's important to say that the dynamic nature of Ruby > contributes to a nice development environment for Wee, that is, > whenever we are editing one of the components, and we save it, Wee > tries to reload it. If it had to be compiled it would slow this cycle > a little bit. And worse, because the compiler would complain at the > first sign of incorrectness, making errors appear when we surely new > that the component was not ready yet for compilation. Behind the > scenes, Wee remaps methods and creates components only when it's > necessary (time saving feature!) > > It makes it appear that I'm editing an HTML and not a Ruby file. > That's it! Lovely. > > Actually, it has less to do with editing an HTML and more with > creating the business logic of our application. The HTML is generated > automagically for us. > > Look at this: > > r.text_input.callback{|v| do_something_with v}.value(@original_value) And for assigning it back to @original_value one can use this short-cut: r.text_input.callback{|@original_value|}.value(@original_value) Yeah, this looks ugly ;-) Or alternativly without the need to create a block: r.text_input.callback(:instance_variable_set, :original_value) > That's all that's needed to create the INPUT TYPE=TEXT object and at > the same time fill it with the default value and save its returning > value. > > Add a submit button to it and you have your FORM. > > r.submit_button.callback{save_edition}.value('Save Edition') > > That's how everything is created, generally. There is more to it, > because it needs to support the simple and the complex, so it > "scales." Just want to add, that this is only *one way* to generate HTML in Wee. You can use other renderers simply by overwriting method #renderer_class of your component class. Or you could use ERb-templates directly: # c.rb class MyComponent < Wee::Component template :render end # c.tpl You can even define "block"-templates (this of course is a bad example, as templates do not accept parameters): # c.rb class MyComponent < Wee::Component template :render tempalte :render_item end # c.tpl # c.tpl-item
  • <%= @i %>
  • Or you can mix templates with programmatic html generation: # c.rb class MyComponent < Wee::Component template :render def render_item(i) r.li.with(i) end end # c.tpl Regards, Michael