[ANN] Wee 0.9.0 - Nitro/Rails integration

Skip to first unread message

Michael Neumann

Jul 12, 2005, 5:40:38 AM7/12/05

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
> 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

Have Fun!



== 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


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

d.add_rule(/catalogue\/item\/(\d+)/, catalog) do |c, md|
c.item_no = Integer(md[1])
# 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

* r.label # => <label>...</label>

* r.hidden_input # => <input type="hidden" ...>

* r.anchor.info(info_url)
# => <a href="/app/info_url/session_id/page_id">

* Added support for radio buttons (methods r.new_radio_group and

* You can now use #value of textarea fields instead of #with.

* Implemented r.form.onsubmit_update method

* Method Brush::SelectListTag#selected takes optionally a block. In
this case, only those elements will be selected, for which the block
evaluates to true. This allows us to use some custom compare
functions instead of the default ones '==' or 'include?'.

* Method Brush::SelectListTag#labels also might be passed a block, in
which case the label is the return value of the block called with
the corresponding item as parameter.

* Added class Brush::CheckboxTag and corresponding methods
HtmlCanvas#check_box and alias #checkbox.

* Method HtmlCanvas#paragraph is no longer a single tag. It can now
contain other tags, e.g. like <p><a .../></p>.

* Added method HtmlCanvas#multiline_text, which replaces newline
characters (\n) in the text with <br/> tags.

== 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'

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
add_decoration(Wee::PageDecoration.new('Hello from Wee/Nitro!'))

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

Now point your browser to

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

# 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 ...

# In app/controllers/wee_controller.rb:

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

register_component "my" do

# 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

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

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

scaffold_with_component do

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

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))


[1]: http://rubyforge.org/projects/wee

George Moschovitis

Jul 12, 2005, 6:57:06 AM7/12/05
Congrats for the release!



Reply all
Reply to author
0 new messages