Class: Xhive::Router::Cells

Inherits:
Object
  • Object
show all
Defined in:
lib/xhive/router/cells.rb

Class Method Summary collapse

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

Yields:

  • (_self)

Yield Parameters:



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, options)
  @@routes << { :path => route, :options => options }
end

.process_routesObject

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]
    options = route[:options]

    cell, action = options[:to].split('#')
    widgets_base_route = Base.route_for('widgets', 'show').gsub(/\/\*\w*$/, '')
    widget_route = "#{widgets_base_route}/#{path}"
    tag_class_name = (options[:as] || "#{cell}_#{action}").to_s.classify.gsub('::', '')

    Route.add(widget_route, cell, action, options.except(:to))

    Xhive::TagFactory.create_class(tag_class_name, widget_route)
  end
end