[Nitro] Using Facets Builder

George Moschovitis george.moschovitis at gmail.com
Thu Feb 8 05:00:05 EST 2007


It is an algternative way to generate html for your action. Here are two
examples:

  # This is a programmatic renderer example. Just for
  # demonstration purposes. Some people tend to like this
  # aproach, dunno why, really.

  def prender
    build do |r|
      labels = ['George', 'Stella', 'Renos']
      r.html {
        r.head {
          r.title 'A simple test'
        }
        r.body {
          10.times {
            r.strong 'Hello World'
            r.br
            r.i 'Hello World'
            r.br
          }
          r.select(:id => 'names') {
            r.options :labels => labels, :selected => 1
          }
        }
      }
    end
  end

  # The same example in different flavour :)

  def prender2
    build do
      labels = ['George', 'Stella', 'Renos']
      html {
        head {
          title 'A simple test'
        }
        body {
          10.times {
            strong 'Hello World'
            br
            i 'Hello World222'
            br
          }
          select(:id => 'names') {
            options :labels => labels, :selected => 1
          }
        }
      }
    end
  end


on a nutchell, build just returns a builder instance. Btw, do not change
your implementation to be compatible with this, just make build return your
builder instance. But please make sure that your implementation can be used
in the form helper (this helper, unlike the build command, is used very
often)

regards,
George.



On 2/8/07, transfire at gmail.com <transfire at gmail.com> wrote:
>
>
>
> On Feb 8, 4:08 am, "George Moschovitis" <george.moschovi... at gmail.com>
> wrote:
> > > i'll have a look.
> >
> > thanks! If you need something, let me know...
>
> render.rb, where does this get used?
>
>   # Access the programmatic renderer (builder).
>
>   def build(&block)
>     if block.arity == 1
>       yield XmlBuilder.new(@out)
>     else
>       XmlBuilder.new(@out).instance_eval(&block)
>     end
>   end
>
> T.
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>



-- 
http://blog.gmosx.com
http://cull.gr
http://www.joy.gr
http://nitroproject.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20070208/6ee409c7/attachment.html 


More information about the Nitro-general mailing list