[Nitro] Questions on Element, Control and rendering

Jonas Pfenniger zimba.tm at gmail.com
Wed Jan 18 08:32:24 EST 2006


Hello list,

As an example, I want to code a generic calendar that I can use 
everywhere I need/want.

So I looked a little bit around. I understand that there are controls 
and elements. What I would like to be able to do, it use it like that in 
my html page :

<Calendar name="cal" date="30-12-2005" />

class Calendar < Nitro::Element
  attr :name
  attr :date

  def header
    %~
    '<script type="text/javascript" src="calendar.js" />
    ~
  end

  def render
    %~
<input type="text" name="#{name}" value="#{date.strftime('%d.%m.%Y')}" />
<script type="text/javascript"> new Calendar("#{name}") </script>
    ~
  end

end

= What is the difference between an Element and a Control ?

Elements are transformed by the renderer. They have a notion of childs 
and parent.
Controls are used by the form helper. They only represent a value.

= Can't these two classes be merged in one or are they too different ?

For me, elements are bit like actions outside a class. It's a bit like 
HMVC where you have subcontrollers.

= Is it possible to pass ruby objects to an Element instead of strings ?

In the previous example, "cal" and "30-12-2005" are strings. Also I 
don't know, bust is there a way to make them mandatory or optional like 
ruby's method parameters ?
And can I inject the values from the action ?

def index
  @page.getElementById('name').date = Time.now
end

= Is it possible to add javascript include in the page's header from the 
element ?

Taking that example again. Imagine we have a javascript library that 
adds calendar functionnalities. Like this popular one : 
http://www.dynarch.com/projects/calendar/ .
Is it possible to add a method in Element that would include the library 
once in the header for every instance of the calendar if used ?

= What is the workflow of Nitro ?

I wish I'd understand what Nitro does in general. Where it goes from the 
request to the result.


Sorry for that long email. I've looked for those questions in the wiki 
and they were missing so I'll update it when/if I get answers.

Cheers,
   Jonas Pfenniger





More information about the Nitro-general mailing list