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 +4 -4
 - data/README.md +26 -2
 - data/lib/webpacker/routes.rb +11 -6
 - data/lib/webpacker/routes/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e97672c8e8fa59f10e40210007b6620c2a59bf0a257e6172731874f446cfb659
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ffb9e82fcf9f6ed0bae01e66a7177092737aae410e738bd749b5344efd4f11e5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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`).
         
     | 
    
        data/lib/webpacker/routes.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
      
 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 =  
     | 
| 
       32 
     | 
    
         
            -
                        segment_keys =  
     | 
| 
       33 
     | 
    
         
            -
                        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
         
     | 
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-03-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     |