lib/apotomo/widget.rb in apotomo-1.0.1 vs lib/apotomo/widget.rb in apotomo-1.0.2
- old
+ new
@@ -29,22 +29,22 @@
define_hook :after_add
attr_accessor :opts
attr_writer :visible
- attr_writer :controller
-
include TreeNode
include Onfire
include EventMethods
include Transition
include WidgetShortcuts
helper Apotomo::Rails::ViewHelper
+ abstract!
+ undef :display # We don't want #display to be listed in #internal_methods.
# 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
@@ -78,22 +78,26 @@
@visible
end
# Returns the rendered content for the widget by running the state method for <tt>state</tt>.
# This might lead us to some other state since the state method could call #jump_to_state.
- def invoke(state=nil, &block)
- @invoke_block = block ### DISCUSS: store block so we don't have to pass it 10 times?
+ def invoke(state=nil, event=nil)
logger.debug "\ninvoke on #{name} with #{state.inspect}"
if state.blank?
state = next_state_for(last_state) || @start_state
end
logger.debug "#{name}: transition: #{last_state} to #{state}"
logger.debug " ...#{state}"
- render_state(state)
+ #render_state(state)
+
+ return process(state, event) if method(state).arity == 1
+
+ opts[:event] = event
+ process(state)
end
# Render the view for the current state. Usually called at the end of a state method.
#
@@ -234,10 +238,10 @@
end
def address_for_event(type, options={})
options.reverse_merge! :source => name,
:type => type,
- :controller => parent_controller.controller_name # DISCUSS: dependency to parent_controller.
+ :controller => parent_controller.controller_path # DISCUSS: dependency to parent_controller.
end
def url_for_event(type, options={})
apotomo_event_path address_for_event(type, options)
end