lieutenant_governor 0.1.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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +6 -0
- data/bin/console +13 -0
- data/bin/setup +8 -0
- data/client/paths.js +0 -0
- data/lib/lieutenant_governor/generators/js_route_helpers.rb +27 -0
- data/lib/lieutenant_governor/routing/extractor.rb +53 -0
- data/lib/lieutenant_governor/templates/js_paths.rb +19 -0
- data/lib/lieutenant_governor/templates/js_paths_template_str.rb +125 -0
- data/lib/lieutenant_governor/version.rb +3 -0
- data/lib/lieutenant_governor.rb +12 -0
- data/lieutenant_governor.gemspec +28 -0
- metadata +118 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: db59e80cc30f17c8fdce83886172e77f3d2743f2
|
|
4
|
+
data.tar.gz: bcc17cb24b5727a794bf8ce443fc68633f9dbd4d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f9bfbb3841cd49260a632027f159501c8e245dc74fd3ab21f8c81b13cf3fa014be7412ec499f859982bb0c7b6d3343083c4968d0637d8a8f24b84ff5e35f8a1e
|
|
7
|
+
data.tar.gz: 900fa98bebe2fe092df553abd59d8088de0171555fe965aa9fac60a60643097851b39802f332dcae9ccf2c3403d786d6d4bb6ca2bdeb4325cda2e2c604210e93
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at jordanlittell@yahoo.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 jordanlittell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Lieutenant Governor
|
|
2
|
+
|
|
3
|
+
**Objective**: A rails gem to make it simple to define your endpoints once in your ```routes.rb``` file and have them automatically generated for use on the client.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'lieutenant_governor'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install lieutenant_governor
|
|
21
|
+
|
|
22
|
+
In the initialization of your app (ex. `config/initializers/lieutenant_governor.rb` ), invoke the generator:
|
|
23
|
+
|
|
24
|
+
$ LieutenantGovernor::Generator.generate(path_to_js_helper)
|
|
25
|
+
|
|
26
|
+
The path_to_js_helper is a required param that specifies the location of the generated helper.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Example Usage
|
|
31
|
+
|
|
32
|
+
Creating a basic URL
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// questions/:questions_id
|
|
36
|
+
|
|
37
|
+
import * as paths from 'paths';
|
|
38
|
+
|
|
39
|
+
// questions function is created and exported by lieutenant governor
|
|
40
|
+
const url = paths.questions({
|
|
41
|
+
|
|
42
|
+
// params to be used in the url
|
|
43
|
+
// number of params must match number in url
|
|
44
|
+
params: [ 1 ],
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
console.log(url);
|
|
49
|
+
// questions/1
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
Creating a URL with query strings appended
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
// questions/:questions_id
|
|
58
|
+
|
|
59
|
+
import * as paths from 'paths';
|
|
60
|
+
|
|
61
|
+
const url = paths.questions({
|
|
62
|
+
|
|
63
|
+
params: [ 1 ],
|
|
64
|
+
|
|
65
|
+
// query strings to be appended to the url
|
|
66
|
+
query: {
|
|
67
|
+
firstName: 'Fred',
|
|
68
|
+
lastName: 'Flintstone'
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(url);
|
|
73
|
+
// questions/1?firstName=Fred&lastName=Flintstone
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Creating a nested URL
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
// questions/:questions_id/answers/:answer_id/votes
|
|
82
|
+
|
|
83
|
+
import * as paths from 'paths';
|
|
84
|
+
|
|
85
|
+
const url = paths.questionAnswerVotes({
|
|
86
|
+
|
|
87
|
+
params: [ 1, 'abc' ],
|
|
88
|
+
|
|
89
|
+
query: {
|
|
90
|
+
firstName: 'Fred',
|
|
91
|
+
lastName: 'Flintstone'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
console.log(url);
|
|
96
|
+
// questions/1/answers/abc/votes?firstName=Fred&lastName=Flintstone
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
Lieutentant governor parses ```routes.rb``` and generates client side functions to create paths
|
|
103
|
+
|
|
104
|
+
Route | Controller Method | Generated Function
|
|
105
|
+
----------------------- | ---------------------- | -----------
|
|
106
|
+
`/api/answer` | `api_answer` | paths.apiAnswer
|
|
107
|
+
`/api/answers` | `api_answers` | paths.apiAnswers
|
|
108
|
+
`/api/questions/:question_id/answers` | `api_question_answers` | paths.apiQuestionAnswers
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
When creating the path, the function takes an object so that the developer can specify params and query strings
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
paths#generatedFunction({
|
|
116
|
+
params: [],
|
|
117
|
+
query: {},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Key | Type | Description
|
|
122
|
+
-------------------- | --------- | -----------
|
|
123
|
+
`params` | `array` | Params to be used in the url. Length must equal count of params expected in url.
|
|
124
|
+
`query` | `object` | Query strings to be appended to the url
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
## Requirements
|
|
128
|
+
|
|
129
|
+
1. Build system must support transpiling ES6
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
135
|
+
|
|
136
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jordanlittell/lieutenant_governor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
146
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require "bundler/setup"
|
|
3
|
+
require "lieutenant_governor"
|
|
4
|
+
|
|
5
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
6
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
7
|
+
|
|
8
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
9
|
+
# require "pry"
|
|
10
|
+
# Pry.start
|
|
11
|
+
|
|
12
|
+
require "irb"
|
|
13
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/client/paths.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'thor/group'
|
|
2
|
+
require_relative '../routing/extractor'
|
|
3
|
+
require_relative '../templates/js_paths.rb'
|
|
4
|
+
require_relative '../templates/js_paths_template_str'
|
|
5
|
+
|
|
6
|
+
module LieutenantGovernor
|
|
7
|
+
|
|
8
|
+
module Generators
|
|
9
|
+
class JsRouteHelpers < Thor::Group
|
|
10
|
+
extend Thor::Actions
|
|
11
|
+
# Use the extractor to get the hash
|
|
12
|
+
# assume function exists to translate hash to javascript text
|
|
13
|
+
# using Thor, open up a file, and then write the javascript text to
|
|
14
|
+
# the file
|
|
15
|
+
|
|
16
|
+
def self.generate_paths_file(path='app/assets/javascripts/pathHelpers.js')
|
|
17
|
+
routes = Rails.application.routes.routes
|
|
18
|
+
route_table = LieutenantGovernor::Routing::Extractor.extract(routes)
|
|
19
|
+
template = LieutenantGovernor::Templates::JsPaths.new(route_table)
|
|
20
|
+
# create_file '/client/paths.js', template.render
|
|
21
|
+
File.open(path, 'w') do |f|
|
|
22
|
+
f.puts template.render
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# require 'action_dispatch/routing'
|
|
2
|
+
|
|
3
|
+
module LieutenantGovernor
|
|
4
|
+
# singleton holding config for gem
|
|
5
|
+
module Routing
|
|
6
|
+
|
|
7
|
+
class Extractor
|
|
8
|
+
|
|
9
|
+
attr_reader :routes
|
|
10
|
+
|
|
11
|
+
# Takes applications routes and converts to hash
|
|
12
|
+
# @param [ActionDispatch::Routing::RouteSet]
|
|
13
|
+
# @return [Hash] table mapping names to paths
|
|
14
|
+
def self.extract(routes)
|
|
15
|
+
instance = new(routes)
|
|
16
|
+
instance.extract
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def initialize(routes)
|
|
20
|
+
@routes = routes
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def extract
|
|
24
|
+
table = {}
|
|
25
|
+
# possible to get blank strings as keys here
|
|
26
|
+
routes.reduce(table) do |memo, obj|
|
|
27
|
+
name = get_name(obj)
|
|
28
|
+
path = get_path(obj)
|
|
29
|
+
table[name] = path if name.present? && path.present?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
table
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# @param [ActionDispatch::Routing::Journey]
|
|
38
|
+
def get_name(obj)
|
|
39
|
+
wrap(obj).name.camelcase
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param [ActionDispatch::Routing::Journey]
|
|
43
|
+
def get_path(obj)
|
|
44
|
+
wrap(obj).path.split('(.:format)')[0]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @param [ActionDispatch::Routing::Journey]
|
|
48
|
+
def wrap(obj)
|
|
49
|
+
ActionDispatch::Routing::RouteWrapper.new(obj)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'erb'
|
|
2
|
+
|
|
3
|
+
module LieutenantGovernor
|
|
4
|
+
module Templates
|
|
5
|
+
class JsPaths
|
|
6
|
+
|
|
7
|
+
attr_reader :routes
|
|
8
|
+
|
|
9
|
+
def initialize(routes)
|
|
10
|
+
@routes = routes
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def render
|
|
14
|
+
b = binding
|
|
15
|
+
ERB.new(LieutenantGovernor::Templates::JS_PATHS_TEMPLATE_STR).result b
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
module LieutenantGovernor
|
|
2
|
+
module Templates
|
|
3
|
+
JS_PATHS_TEMPLATE_STR =
|
|
4
|
+
%{
|
|
5
|
+
const STRING = 'string';
|
|
6
|
+
const PARAM = 'param';
|
|
7
|
+
const path;
|
|
8
|
+
|
|
9
|
+
const makeFullURL = ({
|
|
10
|
+
path = [],
|
|
11
|
+
params = [],
|
|
12
|
+
query = {},
|
|
13
|
+
} = {}) => {
|
|
14
|
+
|
|
15
|
+
path = makePath({
|
|
16
|
+
path,
|
|
17
|
+
params,
|
|
18
|
+
});
|
|
19
|
+
const queryStrings = makeQueryStrings(query);
|
|
20
|
+
return queryStrings.length > 0 ? `${path}?${queryStrings}`:path;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const makePath = ({ path, params }) => {
|
|
24
|
+
const isArray = obj => Object.prototype.toString.call(obj) === '[object Array]';
|
|
25
|
+
|
|
26
|
+
if(!isArray(params)) {
|
|
27
|
+
throw 'params argument must of type array';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const numRequiredParams = path.reduce((acc, param) => {
|
|
31
|
+
return acc + (param.type == PARAM);
|
|
32
|
+
}, 0);
|
|
33
|
+
|
|
34
|
+
if(params.length !== numRequiredParams) {
|
|
35
|
+
throw `${params.length} params given, but ${numRequiredParams} are required`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let numUsedParams = 0;
|
|
39
|
+
return path.map(obj => {
|
|
40
|
+
if(obj.type === STRING) {
|
|
41
|
+
return obj.name;
|
|
42
|
+
} else if(obj.type === PARAM) {
|
|
43
|
+
numUsedParams+=1;
|
|
44
|
+
return params[numUsedParams - 1];
|
|
45
|
+
}
|
|
46
|
+
}).join('/');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const makeQueryStrings = a => {
|
|
50
|
+
const s = [];
|
|
51
|
+
const rbracket = /\[\]$/;
|
|
52
|
+
const isArray = obj => Object.prototype.toString.call(obj) === '[object Array]';
|
|
53
|
+
|
|
54
|
+
const add = (k, v) => {
|
|
55
|
+
v = typeof v === 'function' ? v() : v === null ? '' : v === undefined ? '' : v;
|
|
56
|
+
s[s.length] = `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const buildParams = (prefix, obj) => {
|
|
60
|
+
let i, len, key;
|
|
61
|
+
|
|
62
|
+
if (prefix) {
|
|
63
|
+
if (isArray(obj)) {
|
|
64
|
+
for (i = 0, len = obj.length; i < len; i++) {
|
|
65
|
+
if (rbracket.test(prefix)) {
|
|
66
|
+
add(prefix, obj[i]);
|
|
67
|
+
} else {
|
|
68
|
+
buildParams(`${prefix}[${typeof obj[i] === 'object' ? i : ''}]`, obj[i]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else if (obj && String(obj) === '[object Object]') {
|
|
72
|
+
for (key in obj) {
|
|
73
|
+
buildParams(`${prefix}[${key}]`, obj[key]);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
add(prefix, obj);
|
|
77
|
+
}
|
|
78
|
+
} else if (isArray(obj)) {
|
|
79
|
+
for (i = 0, len = obj.length; i < len; i++) {
|
|
80
|
+
add(obj[i].name, obj[i].value);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
for (key in obj) {
|
|
84
|
+
buildParams(key, obj[key]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return s;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return buildParams('', a).join('&');
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
<% @routes.each do |n, s_path| %>
|
|
94
|
+
|
|
95
|
+
const <%= n %>Path = [
|
|
96
|
+
<% s_path.split('/').each_with_index do |frag, idx| %>
|
|
97
|
+
<% next if frag.blank? %>
|
|
98
|
+
<% if frag[0] == ':' %>
|
|
99
|
+
{
|
|
100
|
+
type: PARAM
|
|
101
|
+
} <%= ',' if idx < s_path.split('/').count - 1 %>
|
|
102
|
+
<% else %>
|
|
103
|
+
{
|
|
104
|
+
type: STRING,
|
|
105
|
+
name: '<%= frag %>'
|
|
106
|
+
} <%= ',' if idx < s_path.split('/').count - 1 %>
|
|
107
|
+
<% end %>
|
|
108
|
+
<% end %>
|
|
109
|
+
];
|
|
110
|
+
export function <%= n %>({ // pluralized model name
|
|
111
|
+
params = [], // params must be given in order inserted
|
|
112
|
+
query = {},
|
|
113
|
+
} = {}) {
|
|
114
|
+
|
|
115
|
+
return makeFullURL({
|
|
116
|
+
path: <%= n %>Path,
|
|
117
|
+
params,
|
|
118
|
+
query,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
<% end %>
|
|
123
|
+
}
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require_relative "lieutenant_governor/version"
|
|
2
|
+
require_relative 'lieutenant_governor/generators/js_route_helpers'
|
|
3
|
+
|
|
4
|
+
module LieutenantGovernor
|
|
5
|
+
|
|
6
|
+
class Generator
|
|
7
|
+
def self.generate(path)
|
|
8
|
+
Generators::JsRouteHelpers.generate_paths_file(path)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'lieutenant_governor/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "lieutenant_governor"
|
|
8
|
+
spec.version = LieutenantGovernor::VERSION
|
|
9
|
+
spec.authors = ["jordanlittell"]
|
|
10
|
+
spec.email = ["jordanlittell@yahoo.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Sync routes in rails with client code"
|
|
13
|
+
spec.description = "Sync routes in rails with client code"
|
|
14
|
+
spec.homepage = "https://github.com/JordanLittell/lieutenant_governor"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
# spec.add_dependency "actionpack"
|
|
24
|
+
spec.add_dependency "thor"
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lieutenant_governor
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- jordanlittell
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: thor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.14'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.14'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.0'
|
|
69
|
+
description: Sync routes in rails with client code
|
|
70
|
+
email:
|
|
71
|
+
- jordanlittell@yahoo.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- CODE_OF_CONDUCT.md
|
|
80
|
+
- Gemfile
|
|
81
|
+
- LICENSE.txt
|
|
82
|
+
- README.md
|
|
83
|
+
- Rakefile
|
|
84
|
+
- bin/console
|
|
85
|
+
- bin/setup
|
|
86
|
+
- client/paths.js
|
|
87
|
+
- lib/lieutenant_governor.rb
|
|
88
|
+
- lib/lieutenant_governor/generators/js_route_helpers.rb
|
|
89
|
+
- lib/lieutenant_governor/routing/extractor.rb
|
|
90
|
+
- lib/lieutenant_governor/templates/js_paths.rb
|
|
91
|
+
- lib/lieutenant_governor/templates/js_paths_template_str.rb
|
|
92
|
+
- lib/lieutenant_governor/version.rb
|
|
93
|
+
- lieutenant_governor.gemspec
|
|
94
|
+
homepage: https://github.com/JordanLittell/lieutenant_governor
|
|
95
|
+
licenses:
|
|
96
|
+
- MIT
|
|
97
|
+
metadata: {}
|
|
98
|
+
post_install_message:
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
require_paths:
|
|
101
|
+
- lib
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
requirements: []
|
|
113
|
+
rubyforge_project:
|
|
114
|
+
rubygems_version: 2.4.5.1
|
|
115
|
+
signing_key:
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: Sync routes in rails with client code
|
|
118
|
+
test_files: []
|