Module: JsFromRoutes
- Defined in:
- lib/js_from_routes/version.rb,
lib/js_from_routes/generator.rb
Overview
Public: Automatically generates JS for Rails routes with { export: true }. Generates one file per controller, and one function per route.
Defined Under Namespace
Classes: ControllerRoutes, Railtie, Route, Template
Constant Summary collapse
- VERSION =
Public: This library adheres to semantic versioning.
"2.0.6"
Class Method Summary collapse
-
.config {|@config| ... } ⇒ Object
Public: Configuration of the code generator.
-
.generate!(app_or_routes = Rails.application) ⇒ Object
Public: Generates code for the specified routes with { export: true }.
Class Method Details
.config {|@config| ... } ⇒ Object
Public: Configuration of the code generator.
131 132 133 134 135 |
# File 'lib/js_from_routes/generator.rb', line 131 def config @config ||= OpenStruct.new(default_config(::Rails.root || Pathname.new(Dir.pwd))) yield(@config) if block_given? @config end |
.generate!(app_or_routes = Rails.application) ⇒ Object
Public: Generates code for the specified routes with { export: true }.
138 139 140 141 142 |
# File 'lib/js_from_routes/generator.rb', line 138 def generate!(app_or_routes = Rails.application) raise ArgumentError, "A Rails app must be defined, or you must specify a custom `output_folder`" if config.output_folder.blank? rails_routes = app_or_routes.is_a?(::Rails::Engine) ? app_or_routes.routes.routes : app_or_routes generate_files exported_routes_by_controller(rails_routes) end |