lib/apotomo/widget.rb in apotomo-0.1.4 vs lib/apotomo/widget.rb in apotomo-1.0.0.beta1
- old
+ new
@@ -33,14 +33,10 @@
attr_writer :visible
attr_writer :controller
attr_accessor :version
- #class << self
- # include WidgetShortcuts
- #end
-
include TreeNode
include Onfire
include EventMethods
@@ -54,34 +50,33 @@
# 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) }
end
-
def add_has_widgets_blocks(*)
run_widget_hook(:has_widgets, self)
end
after_initialize :add_has_widgets_blocks
- # Constructor which needs a unique id for the widget and one or multiple start states.
- # <tt>start_state</tt> may be a symbol or an array of symbols.
- def initialize(id, start_state, opts={})
- @opts = opts
+ # Constructor which needs a unique id for the widget and one or multiple start states.
+ def initialize(parent_controller, id, start_state, opts={})
+ super(parent_controller, opts) # do that as long as cells do need a parent_controller.
+
@name = id
@start_state = start_state
@visible = true
- @version = 0
+ @version = 0 ### DISCUSS: neeed in stateLESS?
- @cell = self
+ @cell = self ### DISCUSS: needed?
run_hook(:after_initialize, id, start_state, opts)
end
def last_state
- @state_name
+ action_name
end
def visible?
@visible
end
@@ -91,11 +86,11 @@
def ivars_to_forget
unfreezable_ivars
end
def unfreezable_ivars
- [:@childrenHash, :@children, :@parent, :@controller, :@cell, :@invoke_block, :@rendered_children, :@page_updates, :@opts,
+ [:@childrenHash, :@children, :@parent, :@parent_controller, :@_request, :@_config, :@cell, :@invoke_block, :@rendered_children, :@page_updates, :@opts,
:@suppress_javascript ### FIXME: implement with ActiveHelper and :locals.
]
end
@@ -124,17 +119,10 @@
render_state(state)
end
-
- # called in Cell::Base#render_state
- def dispatch_state(state)
- send(state, &@invoke_block)
- end
-
-
# Render the view for the current state. Usually called at the end of a state method.
#
# ==== Options
# * <tt>:view</tt> - Specifies the name of the view file to render. Defaults to the current state name.
# * <tt>:template_format</tt> - Allows using a format different to <tt>:html</tt>.
@@ -182,15 +170,14 @@
rendered_children = render_children_for(options)
options[:locals].reverse_merge!(:rendered_children => rendered_children)
- @controller = controller # that dependency SUCKS.
@suppress_js = options[:suppress_js] ### FIXME: implement with ActiveHelper and :locals.
- render_view_for(options, @state_name) # defined in Cell::Base.
+ render_view_for(options, action_name) # defined in Cell::Base.
end
alias_method :emit, :render
# Wraps the rendered content in a replace statement targeted at your +Apotomo.js_framework+ setting.
@@ -240,11 +227,11 @@
render_children(options[:invoke])
end
def render_children(invoke_options={})
- returning rendered_children = ActiveSupport::OrderedHash.new do
+ ActiveSupport::OrderedHash.new.tap do |rendered_children|
visible_children.each do |kid|
child_state = decide_state_for(kid, invoke_options)
logger.debug " #{kid.name} -> #{child_state}"
rendered_children[kid.name] = render_child(kid, child_state)
@@ -293,11 +280,11 @@
# Returns the widget named <tt>widget_id</tt> as long as it is below self or self itself.
def find_widget(widget_id)
find {|node| node.name.to_s == widget_id.to_s}
end
- def controller
- root? ? @controller : root.controller
+ def url_for_event(*args)
+ parent_controller.url_for_event(*args)
end
alias_method :widget_id, :name
end
end