Skip to content

module Athena::Routing::Generator::Interface #

Allows generating a URL for a given ART::Route.

routes =
routes.add "blog_show", "/blog/{slug}"

generator = context
generator.generate "blog_show", slug: "bar-baz", source: "Crystal" # => "/blog/bar-baz?source=Crystal"

Parameter Default Values#

By default parameters with a default value the same as the provided parameter will be excluded from the generated URL. For example:

routes =
routes.add "articles", "/articles/{page}", {"page" => "1"}

ART.compile routes

generator =
generator.generate "articles"          # => "/articles"
generator.generate "articles", page: 1 # => "/articles"
generator.generate "articles", page: 2 # => "/articles/2"

If you want to always include a parameter, add a ! before the ART::Route#path, for example:

routes.add "users", "/users/{!page}", {"page" => "1"}

generator.generate "users"          # => "/users/1"
generator.generate "users", page: 1 # => "/users/1"
generator.generate "users", page: 2 # => "/users/2"

URL Types#

Athena::Routing supports various ways to generate the URL, via the reference_type parameter. See ART::Generator::ReferenceType for description/examples of the possible types.

Included modules


Direct including types

Athena::Routing::Generator::URLGenerator Athena::Routing::RouterInterface


abstract #generate(route : String, params : Hash(String, String?) = Hash(String, String | ::Nil).new, reference_type : ART::Generator::ReferenceType = :absolute_path) : String #

Generates a URL for the provided route, optionally with the provided params and reference_type.

View source