README.rdoc in apotomo-1.0.0.beta2 vs README.rdoc in apotomo-1.0.0
- old
+ new
@@ -20,11 +20,11 @@
Easy as hell.
=== Rails 3
- gem install apotomo
+ gem install apotomo --pre
=== Rails 2.3
gem install apotomo -v 0.1.4
@@ -40,16 +40,16 @@
== Generate
Go and generate a widget stub.
- $ rails generate apotomo:widget CommentsWidget display process --haml
+ $ rails generate apotomo:widget CommentsWidget display write --haml
create app/cells/
create app/cells/comments_widget
create app/cells/comments_widget.rb
create app/cells/comments_widget/display.html.haml
- create app/cells/comments_widget/process.html.haml
+ create app/cells/comments_widget/write.html.haml
create test/widgets/comments_widget_test.rb
Nothing special.
== Plug it in
@@ -58,14 +58,14 @@
class PostsController < ApplicationController
include Apotomo::Rails::ControllerMethods
has_widgets do |root|
- root << widget('comments_widget', 'post-comments', :display, :post => post)
+ root << widget('comments_widget', 'post-comments', :post => @post)
end
-The widget is named <tt>post-comments</tt> and jumps to the <tt>:display</tt> state per default. Assuming your controller has a method +post+ we pass the current post into the widget.
+The widget is named <tt>post-comments</tt>. We pass the current post into the widget - the block is executed in controller instance context, that's were <tt>@post</tt> comes from. Handy, isn't it?
== Render the widget
Rendering usually happens in your controller view, <tt>views/posts/show.haml</tt>, for instance.
@@ -80,22 +80,22 @@
== Write the widget
A widget is like a cell which is like a mini-controller.
class CommentsWidget < Apotomo::Widget
- responds_to_event :submit, :with => :process
+ responds_to_event :submit, :with => :write
def display
@comments = param(:post).comments # the parameter from outside.
render
end
-The +display+ state collects comments to show and renders its view.
+Having +display+ as the default state when rendering, this method collects comments to show and renders its view.
-And look at line 2 - if encountering a <tt>:submit</tt> event we invoke +process+, which is simply another state. How cool is that?
+And look at line 2 - if encountering a <tt>:submit</tt> event we invoke +write+, which is simply another state. How cool is that?
- def process
+ def write
@comment = Comment.new(:post => param(:post))
@comment.update_attributes param(:comment) # like params[].
update :state => :display
end
@@ -158,26 +158,44 @@
$("post-comments").replaceWith(<the rendered view>);
If that's not what you want, do
- def process
+ def write
if param(:comment)[:text].explicit?
render :text => 'alert("Hey, you wanted to submit a pervert comment!");'
end
end
Apotomo doesn't depend on _any_ JS framework - you choose!
+== Testing
+Apotomo comes with its own test case and assertions to <b>build rock-solid web components</b>.
+
+ class CommentsWidgetTest < Apotomo::TestCase
+ has_widgets do |root|
+ root << widget(:comments_widget, 'me', :post => @pervert_post)
+ end
+
+ def test_render
+ render_widget 'me'
+ assert_select "li#me"
+
+ trigger :submit, :comment => {:text => "Sex on the beach"}
+ assert_response 'alert("Hey, you wanted to submit a pervert comment!");'
+ end
+ end
+
+You can render your widgets, spec the markup, trigger events and assert the event responses, so far. If you need more, let us know!
+
== More features
There's even more, too much for a simple README.
[Statefulness] Deriving your widget from +StatefulWidget+ gives you free statefulness.
[Composability] Widgets can range from small standalone components to nested widget trees like complex dashboards.
-[Bubbling events] Events bubble up from their triggering source to root and thus can be observed, providing a way to implement loosely coupled, distributable components.
-[Testing] Apotomo comes with testing assertions to build rock-solid web components.
+[Bubbling events] Events bubble up from their triggering source to root and thus can be observed, providing a way to implement loosely coupled, distributable components.
[Team-friendly] Widgets encourage encapsulation and help having different developers working on different components without getting out of bounds.
Give it a try- you will love the power and simplicity of real web components!