Module: Apotomo::WidgetShortcuts

Included in:
Rails::ControllerMethods, TestCase, Widget
Defined in:
lib/apotomo/widget_shortcuts.rb

Overview

Create widget trees using the #widget DSL.

Defined Under Namespace

Modules: DSL Classes: FactoryProxy

Instance Method Summary (collapse)

Instance Method Details

- (Object) widget(*args, &block)

Shortcut for creating an instance of class_name+"_widget" named id. Yields self. Note that this creates a proxy object, only. The actual widget is built not until you added it, e.g. using #<<.

Example:

root << widget(:comments)

will create a CommentsWidget with id :comments attached to root.

widget(:comments, 'post-comments', :user => current_user)

sets id to 'posts_comments' and #options to the hash.

You can also use namespaces.

widget('jquery/tabs', 'panel')

Add a block if you need to grab the created widget right away.

root << widget(:comments) do |comments|
  comments.markdown!
end

Using #widget is just a shortcut, you can always use the constructor as well.

CommentsWidget.new(root, :comments)


31
32
33
# File 'lib/apotomo/widget_shortcuts.rb', line 31

def widget(*args, &block)
  FactoryProxy.new(*args, &block)
end