Sha256: 6ae438a3692313aac5d549087879b717b20ee5198ebd1a1cd56315cb547e3b9d
Contents?: true
Size: 1.58 KB
Versions: 21
Compression:
Stored size: 1.58 KB
Contents
require "scrivito/routing_extensions" 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 original_route_set = @set route_name = using.to_sym # route_set is actually an optional parameter # and should only be used in test scenarios delayed = proc do |route_set| route_set ||= original_route_set 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 if route_name == :permalink && false PresetRoutes.delayed[route_name] = delayed else delayed.call(original_route_set) 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
Version data entries
21 entries across 21 versions & 1 rubygems
Version | Path |
---|---|
infopark_fiona7-1.2.0.0.0 | lib/fiona7/scrivito_patches/routing_extensions.rb |