module Scrivito module RoutingExtensions def scrivito_route(path, using:, format: nil, via: :get) assert_scrivito_route_enabled # @set is a ActionDispatch::Routing::RouteSet # see: http://git.io/v4UYF and http://git.io/v4UOI route_set = @set route_name = using.to_sym route = Route.register(route_set, route_name) options = { to: 'scrivito/cms_dispatch#index', via: via, format: format, as: route.helper_name, } # removed fixed length constraint on ids options[:constraints] = {id: /[0-9]{4,}/} if route_name == :slug_id begin match(path, options) rescue ArgumentError => error if error.message.include?(route.helper_name) raise ScrivitoError, %(You have already defined a Scrivito route with the name "#{route_name}".) else raise error end end end private def assert_scrivito_route_enabled unless Scrivito::Configuration.scrivito_route_enabled? raise ScrivitoError, 'The preset routes are still enabled. Please disable them by ' \ 'setting the configuration "inject_preset_routes" to false before using scrivito_route' end end end end