Class: Trellis::DefaultRouter
Overview
– DefaultRouter – The default routing scheme is in the form /page[.event][/value]
Constant Summary collapse
- ROUTE_REGEX =
%r{^/([^/]+)(?:/(?:events/(?:([^/\.]+)(?:\.([^/\.]+)?)?)(?:/(?:([^\.]+)?))?)?)?}
Constants inherited from Router
Instance Attribute Summary
Attributes inherited from Router
#application, #keys, #page, #path, #pattern, #score
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Router
#initialize, #inject_parameters_into_page_instance, #to_s
Constructor Details
This class inherits a constructor from Trellis::Router
Class Method Details
.to_uri(options = {}) ⇒ Object
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/trellis/trellis.rb', line 477 def self.to_uri(={}) # get options url_root = [:url_root] page = [:page] event = [:event] source = [:source] value = [:value] destination = page url_root = "/" if page.kind_of?(Trellis::Page) destination = page.path || page.class.class_to_sym root = page.class.url_root url_root = (root && !root.empty?) ? "/#{root}" : '/' end source = source ? ".#{source}" : '' value = value ? "/#{value}" : '' event_info = event ? "/events/#{event}#{source}#{value}" : '' "#{url_root}#{destination}#{event_info}" end |
Instance Method Details
#matches?(request) ⇒ Boolean
473 474 475 |
# File 'lib/trellis/trellis.rb', line 473 def matches?(request) request.path_info.match(ROUTE_REGEX) != nil end |
#route(request) ⇒ Object
465 466 467 468 469 470 471 |
# File 'lib/trellis/trellis.rb', line 465 def route(request) value, source, event, destination = request.path_info.match(ROUTE_REGEX).to_a.reverse destination = @application.class.homepage unless destination page = Page.get_page(destination.to_sym) Route.new(page, event, source, value) end |