Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Apotomo is a stateful widget component framework for Rails.

This branch is 401 commits behind apotonick:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app/cells/apotomo
generators/widget
lib
public/images
test
README
README.rdoc
Rakefile
TODO
init.rb

README.rdoc

how does Apotomo handle Ajax and JavaScript? framework abstraction with JavascriptGenerator

Apotomo

Apotomo is a stateful widget component framework for Rails.

A stateful WHAT?

Well, you know that. In Rails, people tend to have fat controllers. One controller action renders the complete page. While many programmers try to separate their code into helpers, controller actions, RJS logic and partials, it is still the controller that has to care about when to update what, and how!

In Apotomo, it is the opposite. Widgets are small, autonomous components that look and feel like controllers. These tiny monsters listen to events and thus keep updating themselves on the page via AJAX. However, there's no JavaScript for you - they're pure Ruby.

Man, gimme code!

Let's use the famous and tiresome counter example.

class CounterCell < Apotomo::StatefulWidget
  transition :from => :display, :to => :increment

  def display
    respond_to_event :counterClick, :with => :increment
 	  
    @count = 0
    render		# renders display.html.erb
  end

  def increment
    @count += 1	# @count is simply there - that's stateful.
    render :view => :display
  end
end

Since this widget calls render it surely needs a view.

<!-- I'm display.html.erb -->

<h1><%= @count %></h1>

<%= link_to_event "Increment me!", :counterClick %>

We now plug the widget in a page.

class ExistingController < ApplicationController
  include Apotomo::ControllerHelper

  def some_action
    # do what you want...

    use_widgets do |root|
      root << cell(:counter, :display, 'my_first_counter')
    end
  end
end

As soon as the widget is rendered it will jump to its :display state which initializes the counter and renders itself.

Speaking of rendering: how do we place the widget in our controller?

<!-- I'm some_action.html.erb -->
<p>
	<%= render_widget 'my_first_counter' %>

Ok, so this renders the widget in our controller page.

When clicking the link it updates automatically on the screen showing the incremented value. Wow.

That's cool!

Yes, it is.

Is there more?

Apotomo got a load of features.

Composability

Widgets can range from small standalone components to nested widget trees like dashboards or forms. Remember that each widget can have any number of children.

Bubbling events

Widgets can trigger events and watch out for them. While events bubble up from their triggering source to root they can be observed, providing a way to implement loosely coupled, distributable components.

Deep Linking

Apotomo deals with deep links (or url fragments) out-of-the-box while using SWFAddress. Components that register for deep linking will update as soon as the deep link changes. That makes your application back-button-safe!

Testing

Needless to say that it is simply easier to test small components instead of fat do-it-all controllers.

Give it a try- you will love the power and simplicity of real stateful components!

Bugs, Community

Please visit apotomo.de, the official project page with lots of examples. Join the mailing list and visit us in the IRC channel. More information is here.

License

Copyright © 2007-2010 Nick Sutterer <apotonick@gmail.com>

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.