lib/apotomo/widget.rb in apotomo-1.1.4 vs lib/apotomo/widget.rb in apotomo-1.2.0
- old
+ new
@@ -37,29 +37,25 @@
# @cheese = Cheese.find evt[:cheese_id]
class Widget < Cell::Base
DEFAULT_VIEW_PATHS = [
File.join('app', 'widgets'),
- File.join('app', 'widgets', 'layouts')
]
include Hooks
# Use this for setup code you're calling in every state. Almost like a +before_filter+ except that it's
# invoked after the initialization in #has_widgets.
#
# Example:
#
# class MouseWidget < Apotomo::Widget
- # after_initialize :setup_cheese
- #
- # # we need @cheese in every state:
- # def setup_cheese(*)
+ # after_initialize do
# @cheese = Cheese.find options[:cheese_id]
+ # end
define_hook :after_initialize
define_hook :has_widgets
- define_hook :after_add
attr_writer :visible
include TreeNode
@@ -71,36 +67,34 @@
helper Apotomo::Rails::ViewHelper
helper Apotomo::Rails::ActionViewMethods
abstract!
-
undef :display # We don't want #display to be listed in #internal_methods.
alias_method :widget_id, :name
-
- # Runs callbacks for +name+ hook in instance context.
- def run_widget_hook(name, *args)
- self.class.callbacks_for_hook(name).each { |blk| instance_exec(*args, &blk) }
+ after_initialize do
+ run_hook :has_widgets, self
end
- def add_has_widgets_blocks(*)
- run_widget_hook(:has_widgets, self)
- end
- after_initialize :add_has_widgets_blocks
-
- def initialize(parent_controller, id, options={})
- super(parent_controller, options) # do that as long as cells do need a parent_controller.
-
+ def initialize(parent, id, options={})
+ super(parent, options) # TODO: do that as long as cells do need a parent_controller. remember to remove options for cells 3.7.
@name = id
@visible = true
+ setup_tree_node(parent)
+
run_hook :after_initialize, self
end
+ def parent_controller
+ # i hope we'll get rid of any parent_controller dependency, soon.
+ root? ? @parent_controller : root.parent_controller
+ end
+
def visible?
@visible
end
# Invokes +state+ and hopefully returns the rendered content.
@@ -129,18 +123,9 @@
#
# issues a squeaking alert dialog on the page.
def render(*args, &block)
super
end
-
- alias_method :emit, :render
-
- def param(name)
- msg = "Deprecated. Use #options for widget constructor options or #params for request data."
- ActiveSupport::Deprecation.warn(msg)
- raise msg
- end
-
# Returns the widget named +widget_id+ if it's a descendent or self.
def find_widget(widget_id)
find {|node| node.name.to_s == widget_id.to_s}
end