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: Configuration, ControllerRoutes, Railtie, Route, Template, TemplateConfig
Constant Summary collapse
- VERSION =
Public: This library adheres to semantic versioning.
"4.0.1"
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.
169 170 171 172 173 |
# File 'lib/js_from_routes/generator.rb', line 169 def config @config ||= Configuration.new(::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 }.
176 177 178 179 180 |
# File 'lib/js_from_routes/generator.rb', line 176 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 |