webpacker-routes 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 70fd767b097d502da92cc505b9f7936a675991dd690a8a1e5a960116f53a697f
4
- data.tar.gz: 94f10933db96a86007a21859e0b566878174002c505fc62831f714bfec7ae4aa
3
+ metadata.gz: e97672c8e8fa59f10e40210007b6620c2a59bf0a257e6172731874f446cfb659
4
+ data.tar.gz: ffb9e82fcf9f6ed0bae01e66a7177092737aae410e738bd749b5344efd4f11e5
5
5
  SHA512:
6
- metadata.gz: 80c6521e15d0d474fb04a2d3927de21771410f7d3681bc24cca4cd1b8f195d7bd22cd15bcb4ecdc2c996446bdb7148924b6034aef28656fd318e1580ef708d64
7
- data.tar.gz: 73ce8b39b57f12a296eef660af0e5ac0e5e17a79c03b144fccb4fd15c965119ef97cbb58601d83e1e70a070e2af9bf27ae58e8ce926d28944d76774797b32cc4
6
+ metadata.gz: 3405c23a0877f10fc5b42404fb8b6f0fb2305fc5d158b649dbe83dcbce05151ac89fe2afc1b5032826f9a393a2a0ba7f19fa97e04addc1a76f9f0fc0a3d36abc
7
+ data.tar.gz: 1408d938a137462f15ee47f5f06e66d9e47e44478c0cefd57a4a16fb446b2e36c44660fc24d96a8940cc5ef703bbcaef895e98e191829bc354289edf623ffc64
data/README.md CHANGED
@@ -18,9 +18,33 @@ $ bundle exec rails webpacker:install:routes
18
18
  Import individual routes from any Webpacker-compiled file:
19
19
 
20
20
  ```javascript
21
- import { root_path } from 'routes'
21
+ import { root_path, root_url } from 'routes'
22
22
 
23
- console.log(root_path())
23
+ root_path()
24
+ // /
25
+
26
+ root_path({ foo: 'bar' })
27
+ // /?foo=bar
28
+
29
+ root_url({ host: 'https://example.com' })
30
+ // https://example.com/
31
+
32
+ root_url({ host: 'https://example.com', bar: 'baz' })
33
+ // https://example.com/?bar=baz
34
+
35
+ root_url({
36
+ anchor: 'abc',
37
+ host: 'example.com',
38
+ params: {
39
+ foo: 'bar'
40
+ },
41
+ port: 3000,
42
+ protocol: 'https',
43
+ relative_url_root: '/rel',
44
+ trailing_slash: true,
45
+ bar: 'baz'
46
+ })
47
+ // https://example.com:3000/rel/?bar=baz&foo=bar#abc
24
48
  ```
25
49
 
26
50
  The routes file is generated when Rails starts, including during `webpacker:compile` (or `assets:precompile`).
@@ -16,28 +16,33 @@ module Webpacker
16
16
  def generate(app)
17
17
  config = app.config.webpacker.routes
18
18
  var_name = -> (name) { config.camel_case ? name.camelize(:lower) : name }
19
- default_url_options = js(app.default_url_options.merge(config.default_url_options).except(*IGNORED_OPTIONS))
19
+
20
+ default_url_options = app.default_url_options.dup
21
+ default_url_options[:relative_url_root] = app.config.relative_url_root if app.config.relative_url_root
22
+ default_url_options.merge!(config.default_url_options)
23
+ default_url_options.except!(*IGNORED_OPTIONS)
24
+
20
25
  default_url_options_var = var_name.call('default_url_options')
21
26
 
22
27
  File.atomic_write(Webpacker.config.routes_path.join('index.js')) do |file|
23
28
  file.write(<<-JAVASCRIPT.strip_heredoc)
24
29
  import { urlFor, pathFor } from 'webpacker-routes'
25
- const #{default_url_options_var} = #{default_url_options}
30
+ const #{default_url_options_var} = #{js(default_url_options)}
26
31
  JAVASCRIPT
27
32
 
28
33
  app.routes.named_routes.sort_by(&:first).each do |name, route|
29
34
  raise `Invalid route name for javascript: ${name}` unless JAVASCRIPT_VARIABLE_NAME_REGEX =~ name
30
35
 
31
- spec = js(route.path.spec.to_s)
32
- segment_keys = js(route.segment_keys.uniq)
33
- options = js(route.defaults.except(*IGNORED_OPTIONS))
36
+ spec = route.path.spec.to_s
37
+ segment_keys = route.segment_keys.uniq
38
+ options = route.defaults.except(*IGNORED_OPTIONS)
34
39
 
35
40
  spec_var = var_name.call("#{name}_spec")
36
41
  url_var = var_name.call("#{name}_url")
37
42
  path_var = var_name.call("#{name}_path")
38
43
 
39
44
  file.write(<<-JAVASCRIPT.strip_heredoc)
40
- const #{spec_var} = [#{spec}, #{segment_keys}, { ...#{default_url_options_var}, ...#{options} }]
45
+ const #{spec_var} = [#{js(spec)}, #{js(segment_keys)}, { ...#{default_url_options_var}, ...#{js(options)} }]
41
46
  export const #{url_var} = (...args) => urlFor(#{spec_var}, ...args)
42
47
  export const #{path_var} = (...args) => pathFor(#{spec_var}, ...args)
43
48
  JAVASCRIPT
@@ -1,5 +1,5 @@
1
1
  module Webpacker
2
2
  module Routes
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpacker-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Harsha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-16 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails