lib/apotomo/widget.rb in apotomo-1.0.0.beta2 vs lib/apotomo/widget.rb in apotomo-1.0.0
- old
+ new
@@ -4,11 +4,10 @@
require 'apotomo/tree_node'
require 'apotomo/event'
require 'apotomo/event_methods'
require 'apotomo/transition'
-require 'apotomo/caching'
require 'apotomo/widget_shortcuts'
require 'apotomo/rails/view_helper'
module Apotomo
class Widget < Cell::Base
@@ -29,21 +28,19 @@
define_hook :has_widgets
define_hook :after_add
attr_accessor :opts
attr_writer :visible
-
+
attr_writer :controller
- attr_accessor :version
include TreeNode
include Onfire
include EventMethods
include Transition
- include Caching
include WidgetShortcuts
helper Apotomo::Rails::ViewHelper
@@ -64,50 +61,25 @@
@name = id
@start_state = start_state
@visible = true
- @version = 0 ### DISCUSS: neeed in stateLESS?
-
@cell = self ### DISCUSS: needed?
@params = parent_controller.params.dup.merge(opts)
- run_hook(:after_initialize, id, start_state, opts)
+ run_hook :after_initialize, self
end
def last_state
action_name
end
def visible?
@visible
end
-
- # Defines the instance vars that should <em>not</em> survive between requests,
- # which means they're not frozen in Apotomo::StatefulWidget#freeze.
- def ivars_to_forget
- unfreezable_ivars
- end
- def unfreezable_ivars
- [:@childrenHash, :@children, :@parent, :@parent_controller, :@_request, :@_config, :@cell, :@invoke_block, :@rendered_children, :@page_updates, :@opts, :@params,
- :@suppress_javascript ### FIXME: implement with ActiveHelper and :locals.
-
- ]
- end
-
- # Defines the instance vars which should <em>not</em> be copied to the view.
- # Called in Cell::Base.
- def ivars_to_ignore
- []
- end
-
- ### FIXME:
- def logger; self; end
- def debug(*args); puts args; 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?
logger.debug "\ninvoke on #{name} with #{state.inspect}"
@@ -254,39 +226,22 @@
def param(name)
@params[name]
end
- # Returns the address hash to the event controller and the targeted widget.
- #
- # Reserved options for <tt>way</tt>:
- # :source explicitly specifies an event source.
- # The default is to take the current widget as source.
- # :type specifies the event type.
- #
- # Any other option will be directly passed into the address hash and is
- # available via StatefulWidget#param in the widget.
- #
- # Can be passed to #url_for.
- #
- # Example:
- # address_for_event :type => :squeak, :volume => 9
- # will result in an address that triggers a <tt>:click</tt> event from the current
- # widget and also provides the parameter <tt>:item_id</tt>.
- def address_for_event(options)
- raise "please specify the event :type" unless options[:type]
-
- options[:source] ||= self.name
- options
- end
-
# 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 url_for_event(*args)
- parent_controller.url_for_event(*args)
+ def address_for_event(type, options={})
+ options.reverse_merge! :source => name,
+ :type => type,
+ :controller => parent_controller.controller_name # DISCUSS: dependency to parent_controller.
+ end
+
+ def url_for_event(type, options={})
+ apotomo_event_path address_for_event(type, options)
end
alias_method :widget_id, :name
end
end