Module: Apotomo::WidgetShortcuts

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

Overview

Shortcut methods for creating widget trees.

Instance Method Summary collapse

Instance Method Details

#widget(prefix, *args) ⇒ Object

Shortcut for creating an instance of class_name+"_widget" named id. Yields self.

Example:

widget(:comments)

will create a CommentsWidget with id :comments.

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


19
20
21
22
23
24
25
26
# File 'lib/apotomo/widget_shortcuts.rb', line 19

def widget(prefix, *args)
  options = args.extract_options!
  id      = args.shift || prefix
  
  constant_for(prefix).new(parent_controller, id, options).tap do |object|
    yield object if block_given?  
  end
end