Skip to content

Commit

Permalink
Add repo link
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Sep 12, 2024
1 parent 7643307 commit 76d044c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
37 changes: 13 additions & 24 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ gem "js-routes"

There are several possible ways to setup JsRoutes:

* [Quick and easy](#quick-start) - Recommended
1. [Quick and easy](#quick-start) - Recommended
* Uses Rack Middleware to automatically update routes locally
* Automatically generates routes files on javascript build
* Works great for a simple Rails application
* [Advanced Setup](#advanced-setup)
1. [Advanced Setup](#advanced-setup)
* Allows very custom setups
* Automatic updates need to be customized
* [Webpacker ERB Loader](#webpacker) - Legacy
1. [Webpacker ERB Loader](#webpacker) - Legacy
* Requires ESM module system (the default)
* Doesn't support typescript definitions
* [Sprockets](#sprockets) - Legacy
1. [Sprockets](#sprockets) - Legacy
* Deprecated and not recommended for modern apps

<div id='quick-start'></div>

### Quick Start
### Quick Start {#quick-start}

Setup [Rack Middleware](https://guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack)
to automatically generate and maintain `routes.js` file and corresponding
Expand Down Expand Up @@ -77,13 +75,10 @@ Add js-routes files to `.gitignore`:
/app/javascript/routes.d.ts
```

<div id='webpacker'></div>

### Webpacker ERB loader
### Webpacker ERB loader {#webpack}

**IMPORTANT**: the setup doesn't support IDE autocompletion with [Typescript](https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html)


#### Use a Generator

Run a command:
Expand Down Expand Up @@ -133,24 +128,22 @@ Create routes file `app/javascript/routes.js.erb`:
<%= JsRoutes.generate() %>
```

Use routes wherever you need them:
Use routes wherever you need them:

``` javascript
import {post_path} from 'routes.js.erb';

alert(post_path(2));
```

<div id='advanced-setup'></div>

### Advanced Setup
### Advanced Setup {#advanced-setup}

**IMPORTANT**: that this setup requires the JS routes file to be updates manually

Routes file can be generated with a `rake` task:

``` sh
rake js:routes
rake js:routes
# OR for typescript support
rake js:routes:typescript
```
Expand Down Expand Up @@ -192,11 +185,9 @@ JsRoutes.generate!(
)
```

<div id='definitions'></div>

#### Typescript Definitions
#### Typescript Definitions {#definitions}

JsRoutes has typescript support out of the box.
JsRoutes has typescript support out of the box.

Restrictions:

Expand All @@ -208,16 +199,14 @@ More advanced setup would involve calling manually:

``` ruby
JsRoutes.definitions! # to output to file
# or
# or
JsRoutes.definitions # to output to string
```

Even more advanced setups can be achieved by setting `module_type` to `DTS` inside [configuration](#module_type)
which will cause any `JsRoutes` instance to generate defintions instead of routes themselves.

<div id="sprockets"></div>

### Sprockets (Deprecated)
### Sprockets (Deprecated) {#sprockets}

If you are using [Sprockets](https://github.com/rails/sprockets-rails) you may configure js-routes in the following way.

Expand Down
1 change: 1 addition & 0 deletions js-routes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |s|
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.summary = %q{Brings Rails named routes to javascript}
s.metadata = { "github_repo" => "ssh://github.com/railsware/js-routes" }

s.add_runtime_dependency(%q<railties>, [">= 4"])
s.add_runtime_dependency(%q<sorbet-runtime>)
Expand Down

0 comments on commit 76d044c

Please sign in to comment.