Class: Crossroads::Router

Inherits:
Object
  • Object
show all
Includes:
Clearwater::Component
Defined in:
lib/crossroads/router.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, component: nil, render: nil, &block) ⇒ Router

Returns a new instance of Router.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/crossroads/router.rb', line 5

def initialize(attributes = {}, component: nil, render: nil, &block)
  @render = ->(params) { component.new(params) } if component
  @render = render               if render
  @render = block                if block

  location = attributes.delete(:location) || $$.window.location.pathname
  @attributes = attributes
  # @attributes[:key] ||= location

  @@locations = [ location ]
  @@matched   = [false]
end

Class Method Details

.locationsObject



22
23
24
# File 'lib/crossroads/router.rb', line 22

def self.locations
  return @@locations
end

.matchedObject



26
27
28
# File 'lib/crossroads/router.rb', line 26

def self.matched
  return @@matched
end

Instance Method Details

#renderObject



18
19
20
# File 'lib/crossroads/router.rb', line 18

def render
  div(@attributes, [@render.call])
end