Class: Xhive::Router::Cells
- Inherits:
-
Object
- Object
- Xhive::Router::Cells
- Defined in:
- lib/xhive/router/cells.rb
Class Method Summary collapse
-
.draw {|_self| ... } ⇒ Object
Public: draws the internal widget routes for cell based widgets.
-
.mount(route, options) ⇒ Object
Public: mounts a cell based route and creates the Liquid tag.
-
.process_routes ⇒ Object
Public: process the previously stored routes.
Class Method Details
.draw {|_self| ... } ⇒ Object
Public: draws the internal widget routes for cell based widgets.
Example:
Xhive::Routes.draw do |router|
mount 'my_widget', :to => 'my_cell#action'
end
12 13 14 15 |
# File 'lib/xhive/router/cells.rb', line 12 def self.draw class_variable_set("@@routes", []) yield self end |
.mount(route, options) ⇒ Object
Public: mounts a cell based route and creates the Liquid tag.
route - The String containing the route. options - The Hash containing the route endpoint.
Example: mount ‘my_widget’, :to => ‘my_cell#action’
It stores the route in internal storage for later processing
26 27 28 |
# File 'lib/xhive/router/cells.rb', line 26 def self.mount(route, ) @@routes << { :path => route, :options => } end |
.process_routes ⇒ Object
Public: process the previously stored routes
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xhive/router/cells.rb', line 32 def self.process_routes return unless defined?(@@routes) @@routes.each do |route| path = route[:path] = route[:options] cell, action = [:to].split('#') = Base.route_for('widgets', 'show').gsub(/\/\*\w*$/, '') = "#{}/#{path}" tag_class_name = ([:as] || "#{cell}_#{action}").to_s.classify.gsub('::', '') Route.add(, cell, action, .except(:to)) Xhive::TagFactory.create_class(tag_class_name, ) end end |