-
Notifications
You must be signed in to change notification settings - Fork 157
Open
Description
Background
I am customizing the output of js-routes because of some customizations in our routing system and to split the path helpers up into multiple files. I am using JsRoutes::Route to generate the path helper but there is no built in way to generate the __jsr object without also generating the path helpers. I am using this workaround at the moment but it would be cleaner if I could just call a method.
# frozen_string_literal: true
# We want the js-routes JavaScript utils but need to customize the output of the JavaScript path helpers.
# To force js-routes to generate the JavaScript utils but not the JavaScript path helpers
# we can pass a fake `Rails::Application` object with empty `named_routes`.
# We then customize the output of the JavaScript path helpers in `lib/gitlab/js_routes.rb`
class EmptyRoutesApplication
Routes = Struct.new(:named_routes)
NamedRoutes = Struct.new do
def to_h
{}
end
end
def routes
Routes.new(NamedRoutes.new)
end
def reload_routes_unless_loaded; end
def reload_routes!; end
def is_a?(klass)
klass == Rails::Application
end
end
JsRoutes.setup do |c|
c.application = -> do
EmptyRoutesApplication.new
end
endProposal
Add a public method such as generate_jsr to lib/js_routes/instance.rb. This will allow more custom setups where you can fully customize the output.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels