ts_routes 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c6d751ca71ca6df642d568421ad9890985e3630
4
- data.tar.gz: 32eac32e26dfa6bb697a03e076a615c7e4c4d502
3
+ metadata.gz: 27b91ef355275cd7f79b055e8493485146c49362
4
+ data.tar.gz: 2e8d7e12cb04fe15d048b831b60599cb3cbef694
5
5
  SHA512:
6
- metadata.gz: 7c15b27aa28d02dcf9039523ff8a7614f0774f34c60eec31f2075794987142bdc51619b30d920ac100ef474ce7a4153e1d5c6a708fb2fde5f6fa6a64314e2aae
7
- data.tar.gz: 4350847473b664df39f22b15a9ec1fb3bf4cd1d2a0910ed1eba8bbc6330b51ff30e2f52d6f8670d98c37671c026e09f3853275224cae8efdf6f21a68344a90a0
6
+ metadata.gz: 5a81dce07a3cefa6151604d0b0a5841777632518e9fa5e7aa45dab0e3c2dd4fe6f4c0a512fed4577e1faccffaad64c51764df16bdf2ba275d4a1ea9ef6680c7d
7
+ data.tar.gz: 399ca6066a7183134f0d5ecf054dd7cfd8d2bfc82f23f7a8a34615e1039da9044de4c8b97aa5d77488e3360257d574be35d26809e9a14baf386b769b86391d87
data/.rubocop.yml CHANGED
@@ -4,18 +4,16 @@ AllCops:
4
4
  Exclude:
5
5
  - "vendor/**/*"
6
6
  - "node_modules/**/*"
7
+ DisabledByDefault: true
7
8
 
8
- Style:
9
- Enabled: false
9
+ Performance:
10
+ Enabled: true
10
11
 
11
- Layout:
12
+ Performance/RedundantBlockCall:
12
13
  Enabled: false
13
14
 
14
- Metrics:
15
- Enabled: false
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: true
16
17
 
17
- Bundler:
18
- Enabled: false
19
-
20
- Performance/RedundantBlockCall:
21
- Enabled: false
18
+ Style/EmptyLineAfterMagicComment:
19
+ Enabled: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # The Revision History of TsRoutes
2
+
3
+ ## v1.0.0 2017/06/27
4
+
5
+ * Initial stable version
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in ts_routes.gemspec
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # TsRoutes for Rails [![Gem Version](https://badge.fury.io/rb/ts_routes.svg)](https://badge.fury.io/rb/ts_routes) [![Build Status](https://travis-ci.org/bitjourney/ts_routes-rails.svg?branch=master)](https://travis-ci.org/bitjourney/ts_routes-rails)
2
2
 
3
- This gem generates Rails URL helpers in TypeScript, inspired by [js-routes](https://github.com/railsware/js-routes).
3
+ This gem generates Rails URL helpers in TypeScript, which is synchronized to `routes.rb`.
4
4
 
5
+ This is inspired by [js-routes](https://github.com/railsware/js-routes), which invents the great idea to export URL helpers to JavaScript.
5
6
 
6
7
  ## Usage
7
8
 
8
9
  In your `lib/tasks/ts_routes.rake`:
9
10
 
10
- ```ruby:ts_routes.rake
11
-
11
+ ```ruby
12
12
  namespace :ts do
13
13
  TS_ROUTES_FILENAME = "javascripts/generated/routes.ts"
14
14
 
@@ -27,9 +27,8 @@ Then, execute `rake ts:routes` to generate `routes.ts` in your favorite path.
27
27
 
28
28
  And you can import it in TypeScript code:
29
29
 
30
-
31
- ```foo.ts
32
- import * as Routes from './generated/RailsRoutes.ts';
30
+ ```typescript
31
+ import * as Routes from './generated/routes';
33
32
 
34
33
  console.log(Routes.entriesPath({ page: 1, per: 20 })); // => /entries?page=1&per=20
35
34
  console.log(Routes.entryPath(1)); // => /entries/1
@@ -39,10 +38,41 @@ Generated URL helpers are almost compatible with Rails, but they are more strict
39
38
 
40
39
  * You must pass required parameters to the helpers as non-named (i.e. normal) arguments
41
40
  * i.e. `Routes.entryPath(1)` for `/entries/:id`
42
- * `Routes.entryPath({ id })` is refused
41
+ * `Routes.entryPath({ id })` is not allowed
42
+ * Required parameters must not be `null` nor `undefined`
43
+ * i.e. `Routes.entyPath(null)` does not compile
43
44
  * You must pass optional parameters as the last argument
44
45
  * i.e. `Routes.entriesPath({ page: 1, per: 2 })`
45
46
 
47
+ ### Options
48
+
49
+ Here are options for `TsRoutes.generate`:
50
+
51
+ <table>
52
+ <tr><th>name</th><th>description</th><th>default</th></tr>
53
+ <tr><td>routes</td><td>Rails routes to export</td><td>Rails.application.routes</td></tr>
54
+ <tr><td>camel_case</td><td>naming style; doesn't change if false</td><td>true</td></tr>
55
+ <tr><td>route_suffix</td><td>suffix for each route</td><td>"path"</td></tr>
56
+ <tr><td>include</td><td>Array of Regexp patterns to include</td><td>nil</td></tr>
57
+ <tr><td>exclude</td><td>Array of Regexp patterns to exclude</td><td>nil</td></tr>
58
+ <tr><td>header</td><td>additional parts of generated files</td><td>"/* tslint:disable */"</td></tr>
59
+ </table>
60
+
61
+ Note that `TsRoutes.generate(options)` is a shortcut of `TsRoutes::Generator.new(options).generate`.
62
+
63
+ ### How to Keep routes.ts Up-To-Date
64
+
65
+ Use [Guard](https://github.com/guard/guard):
66
+
67
+ ```ruby
68
+ # In Guardfile
69
+
70
+ # Run `rake ts:routes` when routes.rb is updated.
71
+ guard :rake, task: 'ts:routes' do
72
+ watch(%r{config/routes\.rb$})
73
+ end
74
+ ```
75
+
46
76
  ## Installation
47
77
 
48
78
  Add this line to your application's Gemfile:
@@ -53,11 +83,15 @@ gem 'ts_routes'
53
83
 
54
84
  And then execute:
55
85
 
56
- $ bundle
86
+ ```console
87
+ $ bundle
88
+ ```
57
89
 
58
90
  Or install it yourself as:
59
91
 
60
- $ gem install ts_routes
92
+ ```console
93
+ $ gem install ts_routes
94
+ ```
61
95
 
62
96
  ## Development
63
97
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "ts_routes"
@@ -8,7 +8,7 @@ module TsRoutes
8
8
  FILTERED_DEFAULT_PARTS = [:controller, :action, :subdomain]
9
9
  URL_OPTIONS = [:protocol, :domain, :host, :port, :subdomain]
10
10
 
11
- DEFAULT_FILE_HEADER = "/* tslint:disable:max-line-length variable-name whitespace */"
11
+ DEFAULT_FILE_HEADER = "/* tslint:disable */"
12
12
 
13
13
  # @return [ActionDispatch::Routing::RouteSet]
14
14
  attr_reader :routes
@@ -88,8 +88,7 @@ module TsRoutes
88
88
  # @param [ActionDispatch::Journey::Route] route
89
89
  # @param [ActionDispatch::Journey::Route] parent_route
90
90
  def build_route_function(route, parent_route = nil)
91
- name_parts = [parent_route&.name, route.name].compact
92
- route_name = build_route_name(*name_parts, route_suffix)
91
+ route_name = build_route_name(parent_route&.name, route.name, route_suffix)
93
92
 
94
93
  required_param_declarations = route.required_parts.map do |name|
95
94
  symbol = find_spec(route.path.spec, name)
@@ -1,6 +1,6 @@
1
1
  /* This is generated by ts_routes-rails */
2
2
 
3
- type ScalarType = string | number | boolean;
3
+ export type ScalarType = string | number | boolean;
4
4
 
5
5
  function $buildOptions(options: any, names: string[]): string {
6
6
  if (options) {
@@ -12,7 +12,7 @@ function $buildOptions(options: any, names: string[]): string {
12
12
  continue;
13
13
  }
14
14
 
15
- const value = options[ key ];
15
+ const value = options[key];
16
16
 
17
17
  if (key === "anchor") {
18
18
  anchor = `#${$encode(value)}`;
@@ -33,9 +33,10 @@ function $buildQuery(q: string[], key: string, value: any) {
33
33
  for (const v of value) {
34
34
  $buildQuery(q, `${key}[]`, v);
35
35
  }
36
- } else if ($isNotNull(value)) { // i.e. non-null, non-scalar, non-array type
36
+ } else if ($isNotNull(value)) {
37
+ // i.e. non-null, non-scalar, non-array type
37
38
  for (const k of Object.keys(value)) {
38
- $buildQuery(q, `${key}[${k}]`, value[ k ]);
39
+ $buildQuery(q, `${key}[${k}]`, value[k]);
39
40
  }
40
41
  }
41
42
  }
@@ -49,7 +50,11 @@ function $isNotNull(value: any): boolean {
49
50
  }
50
51
 
51
52
  function $isScalarType(value: any): value is ScalarType {
52
- return typeof(value) === "string" || typeof(value) === "number" || typeof(value) === "boolean";
53
+ return (
54
+ typeof value === "string" ||
55
+ typeof value === "number" ||
56
+ typeof value === "boolean"
57
+ );
53
58
  }
54
59
 
55
60
  function $isPresent(value: any): boolean {
@@ -57,5 +62,5 @@ function $isPresent(value: any): boolean {
57
62
  }
58
63
 
59
64
  function $hasPresentOwnProperty(options: any, key: string): boolean {
60
- return options && options.hasOwnProperty(key) && $isPresent(options[ key ]);
65
+ return options && options.hasOwnProperty(key) && $isPresent(options[key]);
61
66
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TsRoutes
2
- VERSION = "0.9.0"
4
+ VERSION = "1.0.0"
3
5
  end
data/lib/ts_routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "./ts_routes/version"
2
4
  require_relative "./ts_routes/generator"
3
5
 
data/package-lock.json CHANGED
@@ -141,6 +141,12 @@
141
141
  "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
142
142
  "dev": true
143
143
  },
144
+ "prettier": {
145
+ "version": "1.4.4",
146
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.4.4.tgz",
147
+ "integrity": "sha512-GuuPazIvjW1DG26yLQgO+nagmRF/h9M4RaCtZWqu/eFW7csdZkQEwPJUeXX10d+LzmCnR9DuIZndqIOn3p2YoA==",
148
+ "dev": true
149
+ },
144
150
  "resolve": {
145
151
  "version": "1.3.3",
146
152
  "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz",
data/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "ts_routes",
3
3
  "version": "1.0.0",
4
- "description": "ts_routes-rails JavaScript runtime",
5
- "main": "index.js",
4
+ "description": "ts_routes-rails JavaScript runtime (not a standalone package)",
5
+ "private": true,
6
6
  "directories": {
7
7
  "lib": "lib",
8
8
  "test": "test"
@@ -11,10 +11,12 @@
11
11
  "typescript": "^2.4.0"
12
12
  },
13
13
  "devDependencies": {
14
+ "prettier": "*",
14
15
  "tslint": "*"
15
16
  },
16
17
  "scripts": {
17
- "test": "echo \"Error: no test specified\" && exit 1"
18
+ "format": "prettier --write 'lib/**/*.ts' 'test/**/*.ts'",
19
+ "test": "rake test"
18
20
  },
19
21
  "repository": "https://github.com/bitjourney/ts_routes-rails",
20
22
  "author": "FUJI Goro",
data/ts_routes.gemspec CHANGED
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path("../lib", __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require "ts_routes/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ts_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUJI Goro (gfx)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-24 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rubocop.yml"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md