[ANN] Wee 0.9.0 - Nitro/Rails integration

Hi,

I’m proud to release Wee 0.9.0. Lots of refactorings, bug fixes and new
features, most notably the integration of Wee into Nitro and Rails,
which means, that you can put Wee components into your existing Nitro or
Rails applications (for more information, read section Nitro/Rails
integration below).

WHAT is Wee? It’s a framwork for very dynamic, component-oriented,
stateful web applications, largely inspired by Seaside. See 1 and 2
for further information.

To get started quickly:

Install Wee:

gem install wee

Write your first example

irb

require ‘rubygems’
require ‘wee’

class HelloWorld < Wee::Component
def render
r.h1 “Hello World!”
r.anchor.callback{@flag = !@flag}.with(@flag ? ‘ON’ : ‘OFF’)
end
end

Wee.run(HelloWorld)

Now point your browser at http://127.0.0.1:2000/app

Have Fun!

Regards,

Michael

···

========================================================================
== New components

  • Wee::ComponentDispatcher
    For an example see examples/dispatcher.rb.

    This allows bookmarkable URLs like /catalog/item/171323 to be
    used with Wee.

    class CatalogComponent < Wee::Component
    attr_accessor :item_no

     ...
    

    end

    catalog = CatalogComponent.new
    d = Wee::ComponentDispatcher.new

    d.add_rule(/catalogue/item/(\d+)/, catalog) do |c, md|
    c.item_no = Integer(md1)
    end

    add further rules here…

    Keep in mind, that now, your anchor tags within
    CatalogComponent should look like:

     r.anchor.info("catalogue/item/#{ new_item_no }").callback ....
    

    By default, all links will leave the current URI as is.

  • Wee::LoginDecoration
    You just need to overwrite it’s logged_in? method and add it to
    your components that need access controll.

  • Wee::Pager

  • Wee::Examples::Counter
    You need to require ‘wee/examples/counter’

  • Wee::Examples::EditableCounter
    You need to require ‘wee/examples/editable_counter’

  • Wee::Examples::Calculator
    You need to require ‘wee/examples/calculator’

========================================================================
== Changes in Html renderer

========================================================================
== Changes in Templating

  • Added :local option, with which one can
    specify a template file relative to the component file, e.g:

    class MyComponent < Wee::Component
    template :render_this, :local => ‘this.tmpl’
    end

    Futhermore, added an :r_as_param option, which generates a render
    method that takes a renderer object as parameter ‘r’.

========================================================================
== New Examples

  • examples/dispatcher.rb
  • examples/nitro/*
  • examples/demo.rb
  • examples/radio.rb

========================================================================
== Nitro/Rails integration

Wee can now be used from within Nitro or Rails, but it’s functionality
is still limited (may change in future releases).

A brief example using Nitro+Wee:

require ‘wee’
require ‘wee/adaptors/nitro’
require ‘wee/examples/calculator’
require ‘nitro’
require ‘nitro/contoller’

class AppController < Nitro::Controller
include Wee::Nitro::ControllerMixin

 scaffold_with_component do
   Wee::Examples::Calculator.new.
   add_decoration(Wee::FormDecoration.new).
   add_decoration(Wee::PageDecoration.new('Hello from Wee/Nitro!'))
 end

end

Nitro.run(:host => ‘127.0.0.1’, :port => 9999, :dispatcher =>
Nitro::Dispatcher.new(‘/app’ => AppController))

Now point your browser to http://127.0.0.1:9999/app/index.

An example how to use Rails+Wee follows (most stuff applies to Nitro as
well):

In config/environment.rb add:

require ‘wee’
require ‘wee/adaptors/rails’
require ‘components/mycomponent’

In components/mycomponent.rb:

class MyComponent < Wee::Component
# … your Wee component …
end

In app/controllers/wee_controller.rb:

class WeeController < ApplicationController
include Wee::Rails::ControllerMixin

 register_component "my" do
   MyComponent.new
 end

end

In app/views/index.rhtml:

<%= show_component 'my' %>

Of course you can render as many components as you like on one page.
You can create components dynamically at runtime with:

make_component component_name, component_object

For example instead of using ‘register_component’ in the WeeController
shown above, you could write:

def index
make_component(‘my’, MyComponent.new) unless has_component?(‘my’)
# render the view
end

If you don’t need the component anymore, drop it:

drop_component ‘my’

If you want to map 1:1 a Wee::Component to an ActionController, you can
use:

class WeeController < ApplicationController
include Wee::Rails::ControllerMixin

 scaffold_with_component do
   MyComponent.new
 end

end

At the moment, only pageless mode is possible, so no backtracking is
performed.

NOTE: Your Wee components must be fully marshallable to work with Rails
CGI mode. That means, you are not allowed to use continuations, and no
code blocks (callbacks). For example instead of:

r.anchor.callback { answer true }

You have to write:

r.anchor.callback(:answer, true)

Or more general:

r.anchor.callback(Wee::LiteralMethodCallback.new(self, :answer, true))

========================================================================

Congrats for the release!

-g.

···

--
http://www.nitrohq.com