[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] Wee 0.9.0 - Nitro/Rails integration

Michael Neumann

7/12/2005 9:41:00 AM

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

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(md[1])
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
========================================================================

* 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
r.radio_button)

* 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'
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....

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:

<html><body>
<%= show_component 'my' %>
</body></html>

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

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

[1]: http://rubyforge.org/pr...
[2]:
http://www.ntecs.de/viewcv...*checkout*/Wee/trunk/doc/rdoc/index.html


1 Answer

George Moschovitis

7/12/2005 10:57:00 AM

0

Congrats for the release!

-g.

--
http://www.n...