rang 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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +195 -0
- data/Rakefile +1 -0
- data/TODO.md +43 -0
- data/app/controllers/rang/application_controller.rb +4 -0
- data/app/controllers/rang/root_controller.rb +7 -0
- data/config/routes.rb +3 -0
- data/lib/rails/generators/rang/add_root/add_root_generator.rb +12 -0
- data/lib/rails/generators/rang/api/configure/configure_generator.rb +70 -0
- data/lib/rails/generators/rang/api/configure/templates/active_model_serializer.rb +5 -0
- data/lib/rails/generators/rang/assets/init/init_generator.rb +52 -0
- data/lib/rails/generators/rang/assets/init/templates/_base.scss +11 -0
- data/lib/rails/generators/rang/assets/init/templates/application.js +14 -0
- data/lib/rails/generators/rang/assets/init/templates/application.scss +3 -0
- data/lib/rails/generators/rang/assets/init/templates/components.js +2 -0
- data/lib/rails/generators/rang/bower/add/add_generator.rb +48 -0
- data/lib/rails/generators/rang/bower/bower_generator.rb +28 -0
- data/lib/rails/generators/rang/bower/init/init_generator.rb +35 -0
- data/lib/rails/generators/rang/example/example_generator.rb +17 -0
- data/lib/rails/generators/rang/example/templates/frontend/application.js.tt +21 -0
- data/lib/rails/generators/rang/example/templates/frontend/application.scss +6 -0
- data/lib/rails/generators/rang/example/templates/frontend/components/components.js +2 -0
- data/lib/rails/generators/rang/example/templates/frontend/components/simple_format/simple_format.directive.js +12 -0
- data/lib/rails/generators/rang/example/templates/frontend/components/simple_format/simple_format.module.js +4 -0
- data/lib/rails/generators/rang/example/templates/frontend/posts/index.ctrl.js.tt +6 -0
- data/lib/rails/generators/rang/example/templates/frontend/posts/index.ctrl.spec.js.tt +12 -0
- data/lib/rails/generators/rang/example/templates/frontend/posts/index.slim.tt +14 -0
- data/lib/rails/generators/rang/example/templates/frontend/posts/posts.module.js.tt +12 -0
- data/lib/rails/generators/rang/example/templates/frontend/posts/posts.scss +3 -0
- data/lib/rails/generators/rang/example/templates/frontend/posts/posts.service.js.tt +44 -0
- data/lib/rails/generators/rang/example/templates/frontend/style/_base.scss +11 -0
- data/lib/rails/generators/rang/example/templates/frontend/style/_layout.scss +3 -0
- data/lib/rails/generators/rang/install/install_generator.rb +66 -0
- data/lib/rails/generators/rang/install/templates/rang.rb +25 -0
- data/lib/rails/generators/rang/teaspoon/install/install_generator.rb +75 -0
- data/lib/rang.rb +18 -0
- data/lib/rang/config.rb +12 -0
- data/lib/rang/engine/railtie.rb +5 -0
- data/lib/rang/helpers.rb +35 -0
- data/lib/rang/patcher.rb +50 -0
- data/lib/rang/util.rb +11 -0
- data/lib/rang/version.rb +3 -0
- data/rang.gemspec +29 -0
- data/spec/controllers/root_controller_spec.rb +12 -0
- data/spec/generators/add_root_spec.rb +21 -0
- data/spec/generators/api_configure_spec.rb +44 -0
- data/spec/generators/assets_init_spec.rb +91 -0
- data/spec/generators/bower_add_spec.rb +61 -0
- data/spec/generators/bower_init_spec.rb +57 -0
- data/spec/generators/install_spec.rb +40 -0
- data/spec/generators/teaspoon_install_spec.rb +123 -0
- data/spec/helpers_spec.rb +64 -0
- data/spec/patcher_spec.rb +103 -0
- data/spec/rails_app/.gitignore +16 -0
- data/spec/rails_app/Gemfile +41 -0
- data/spec/rails_app/README.rdoc +28 -0
- data/spec/rails_app/Rakefile +6 -0
- data/spec/rails_app/app/assets/images/.keep +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +16 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_app/app/controllers/application_controller.rb +5 -0
- data/spec/rails_app/app/controllers/concerns/.keep +0 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.keep +0 -0
- data/spec/rails_app/app/models/.keep +0 -0
- data/spec/rails_app/app/models/concerns/.keep +0 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_app/bin/bundle +3 -0
- data/spec/rails_app/bin/rails +8 -0
- data/spec/rails_app/bin/rake +8 -0
- data/spec/rails_app/bin/spring +18 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +23 -0
- data/spec/rails_app/config/boot.rb +4 -0
- data/spec/rails_app/config/database.yml +25 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +37 -0
- data/spec/rails_app/config/environments/production.rb +82 -0
- data/spec/rails_app/config/environments/test.rb +39 -0
- data/spec/rails_app/config/initializers/assets.rb +8 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails_app/config/initializers/inflections.rb +16 -0
- data/spec/rails_app/config/initializers/mime_types.rb +4 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/locales/en.yml +23 -0
- data/spec/rails_app/config/routes.rb +56 -0
- data/spec/rails_app/config/secrets.yml +22 -0
- data/spec/rails_app/db/seeds.rb +7 -0
- data/spec/rails_app/lib/assets/.keep +0 -0
- data/spec/rails_app/lib/tasks/.keep +0 -0
- data/spec/rails_app/log/.keep +0 -0
- data/spec/rails_app/public/404.html +67 -0
- data/spec/rails_app/public/422.html +67 -0
- data/spec/rails_app/public/500.html +66 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/robots.txt +5 -0
- data/spec/rails_app/test/controllers/.keep +0 -0
- data/spec/rails_app/test/fixtures/.keep +0 -0
- data/spec/rails_app/test/helpers/.keep +0 -0
- data/spec/rails_app/test/integration/.keep +0 -0
- data/spec/rails_app/test/mailers/.keep +0 -0
- data/spec/rails_app/test/models/.keep +0 -0
- data/spec/rails_app/test/test_helper.rb +10 -0
- data/spec/rails_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/rails_app/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +79 -0
- data/spec/util_spec.rb +27 -0
- data/spec/version_spec.rb +9 -0
- data/vendor/assets/javascripts/angular-templates.js.erb +14 -0
- metadata +327 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4b5157225917f1c648bc3240a8f378ec8f0a8a1a
|
|
4
|
+
data.tar.gz: fc62c25421d25039674ddabb1bdb01ad9a0c2269
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fb2196731bec62126ca4ac17cc99f0afbff3e3b8b4ef3afc7b2d8c59d7e15f075f61366a5a8e58e89915da2e9304cbfbf6fc09b9e31ca344ccb4c871e5f485ee
|
|
7
|
+
data.tar.gz: 8ecd855626c6e2661a5cf6eccf80020ec802d345a116cabb581d49b5e2af2af5f2d674db54251eeebf0b14d0e90dc082d08ef5c43e08f9cdb81d97a6b79a35ff
|
data/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Caden Lovelace
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Rang
|
|
2
|
+
|
|
3
|
+
__VERY EARLY DAYS — much of this is imagined__
|
|
4
|
+
|
|
5
|
+
This is a gem that makes Rails and Angular play nicely together.
|
|
6
|
+
|
|
7
|
+
It should replace all the strange initializers and bag of angular_* gems you've
|
|
8
|
+
got in your Rails & Angular project.
|
|
9
|
+
|
|
10
|
+
Where existing solutions are effective and well-maintained, they are included.
|
|
11
|
+
Otherwise, we've included our own.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this to your Gemfile:
|
|
16
|
+
|
|
17
|
+
`gem 'rang'`
|
|
18
|
+
|
|
19
|
+
Then:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
$ bundle install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Prompts you to run each of the generators below.
|
|
29
|
+
$ rails g rang:install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
This gem collects quite a few things. Summary:
|
|
35
|
+
|
|
36
|
+
* Facilitates the Angular best practice structure.
|
|
37
|
+
* Serves and precompiles Angular templates.
|
|
38
|
+
* Precompiles Angular with DI annotations.
|
|
39
|
+
* Uses [rails-assets](http://rails-assets.org) to manage Bower dependencies.
|
|
40
|
+
* Gets Angular + Rails working together on CSRF protection.
|
|
41
|
+
* Provides an `ng-view` root route.
|
|
42
|
+
* Provides a generator to install and configure [Teaspoon](https://github.com/modeset/teaspoon) for Angular.
|
|
43
|
+
* Configures slim, if available, to ignore `{` and `}`.
|
|
44
|
+
|
|
45
|
+
### Frontend structure
|
|
46
|
+
|
|
47
|
+
Instead of using `/assets/javascripts`, `/assets/stylesheets`, etc, this gem
|
|
48
|
+
supports following the best practice structure [recommended by Google](https://docs.google.com/a/cultivatehq.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub).
|
|
49
|
+
[This very readable post](https://github.com/yeoman/generator-angular/issues/109)
|
|
50
|
+
sets out the rationale and walks through the recommended structure.
|
|
51
|
+
|
|
52
|
+
What this means in practice is that assets in `assets/frontend` are served and
|
|
53
|
+
compiled just like `assets/javascripts` and `assets/stylesheets` would be.
|
|
54
|
+
|
|
55
|
+
To get started:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# This should be non-destructive, but it's your assets on the line.
|
|
59
|
+
$ rails g rang:assets:init
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This moves your existing `/app/assets` to `/app/assets.removed` and sets up a
|
|
63
|
+
fresh assets directory following the best practice structure.
|
|
64
|
+
|
|
65
|
+
Caveats:
|
|
66
|
+
|
|
67
|
+
* CSS might still need some special treatment.
|
|
68
|
+
* The structure is still under active refinement. However, this gem is flexible
|
|
69
|
+
enough to accept most changes.
|
|
70
|
+
|
|
71
|
+
### Templates
|
|
72
|
+
|
|
73
|
+
In line with the structure above, Rang also compiles templates into
|
|
74
|
+
Angular's `$templateCache`. You should load them in your routes like this:
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
angular
|
|
78
|
+
.module('blog.posts', ['ngRoute'])
|
|
79
|
+
.config(function($routeProvider) {
|
|
80
|
+
$routeProvider
|
|
81
|
+
.when('/posts', {
|
|
82
|
+
templateUrl: '/assets/posts/posts.html', // Use .html, not .slim, etc
|
|
83
|
+
controller: 'PostsController'
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
And then in your `application.js`, follow this structure:
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
//= require angular
|
|
92
|
+
//= require angular-route
|
|
93
|
+
//= require posts/posts
|
|
94
|
+
//= require angular-templates
|
|
95
|
+
|
|
96
|
+
angular.module('blog', ['blog.posts', 'ngRoute'])
|
|
97
|
+
.config(function($routeProvider){
|
|
98
|
+
$routeProvider.otherwise({
|
|
99
|
+
redirectTo: '/posts'
|
|
100
|
+
});
|
|
101
|
+
})
|
|
102
|
+
.run(AngularTemplates.load);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`AngularTemplates.load` is DI'd with `$templateCache` and includes all the templates
|
|
106
|
+
in your directory tree.
|
|
107
|
+
|
|
108
|
+
[Slim](https://github.com/slim-template/slim-rails) is automatically supported
|
|
109
|
+
for assets if it's in your `Gemfile`.
|
|
110
|
+
|
|
111
|
+
### Annotation (minification)
|
|
112
|
+
|
|
113
|
+
Rang employs [ng-annotate](https://github.com/olov/ng-annotate) (via
|
|
114
|
+
[ngannotiate-rails](https://github.com/kikonen/ngannotate-rails)) to make sure
|
|
115
|
+
your Angular code is minified properly.
|
|
116
|
+
|
|
117
|
+
### Bower dependencies
|
|
118
|
+
|
|
119
|
+
Rang uses [rails-assets.org](http://rails-assets.org/) to include
|
|
120
|
+
bower packages. While a little slow sometimes, it's still a better solution than
|
|
121
|
+
requiring npm and bower / having a load of useless stuff in source control. For now.
|
|
122
|
+
|
|
123
|
+
It manages the rails-assets dependencies in an auxilliary gemfile called
|
|
124
|
+
`Gemfile.bower`. This can be created and managed with generators.
|
|
125
|
+
|
|
126
|
+
Usage:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Not strictly necessary, but take a look at what it generates.
|
|
130
|
+
$ rails g rang:bower:init
|
|
131
|
+
|
|
132
|
+
# Adds angular-cookies gem to Gemfile.bower.
|
|
133
|
+
$ rails g rang:bower:add angular-cookies '~ 1.2.0'
|
|
134
|
+
|
|
135
|
+
# As above, but runs bundler after.
|
|
136
|
+
$ rails g rang:bower:add angular@ '~ 1.2.0'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Teaspoon
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
$ rails g rang:teaspoon:install
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
This does the following:
|
|
146
|
+
|
|
147
|
+
* Adds `teaspoon` & `phantomjs` to your Gemfile.
|
|
148
|
+
* Runs the normal `teaspoon:install` generator.
|
|
149
|
+
* Adds `angular-mocks` to your `Gemfile.bower` and includes it in `spec_helper.js`.
|
|
150
|
+
* Preconfigures Teaspoon to fix some issues ([#120](https://github.com/modeset/teaspoon/issues/120), [#197](https://github.com/modeset/teaspoon/issues/197)).
|
|
151
|
+
* Configures Teaspoon to enable putting specs alongside your code (optional).
|
|
152
|
+
|
|
153
|
+
### API Configuration
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
$ rails g rang:api:configure
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
This does the following:
|
|
160
|
+
|
|
161
|
+
* Installs and confgures [active_model_serializers](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
|
|
162
|
+
to serve Angular-appropriate JSON out of the box.
|
|
163
|
+
* Installs and requires [angular-restmod](https://github.com/platanus/angular-restmod),
|
|
164
|
+
a Rails-inspired ORM for Angular.
|
|
165
|
+
* Sets up an `api/` route and controller scope for your API controllers.
|
|
166
|
+
|
|
167
|
+
### CSRF
|
|
168
|
+
|
|
169
|
+
Rang uses [angular_rails_csrf](https://github.com/jsanders/angular_rails_csrf)
|
|
170
|
+
to join up Rails + Angular's CSRF protection.
|
|
171
|
+
|
|
172
|
+
So you don't need to feel bad turning it off anymore!
|
|
173
|
+
|
|
174
|
+
### Root route
|
|
175
|
+
|
|
176
|
+
To avoid having a controller just to serve 'ng-view' there's a convenience
|
|
177
|
+
action for you to wire your root to.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
$ rails g rang:add_root
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Adds this to `config/routes.rb`:
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
mount Rang::Engine => "/"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Contributing
|
|
190
|
+
|
|
191
|
+
1. Fork it ( https://github.com/[my-github-username]/rails-meet-angular/fork )
|
|
192
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
193
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
194
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
195
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/TODO.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
## Angular-rails Gem
|
|
2
|
+
|
|
3
|
+
### Requirements
|
|
4
|
+
|
|
5
|
+
#### Examples
|
|
6
|
+
|
|
7
|
+
#### Other
|
|
8
|
+
* Breakout bundle!
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Done
|
|
12
|
+
* ~~Docs for teaspoon installer.~~
|
|
13
|
+
* ~~Convenience root route to ng-view.~~
|
|
14
|
+
* ~~Consider where to put Gemfile.bower include.~~
|
|
15
|
+
* ~~Refactor bower:init generator to use bower:add~~
|
|
16
|
+
* ~~Support inline JS tests.~~
|
|
17
|
+
* ~~Neaten up generator when executed multiple times.~~
|
|
18
|
+
* ~~CSRF protection with [angular_rails_csrf](https://github.com/jsanders/angular_rails_csrf)~~
|
|
19
|
+
* ~~Get Asset precompilation working.~~
|
|
20
|
+
* ~~Check if asset precompilation is working.~~
|
|
21
|
+
* ~~Minification using ng-min/ng-annotate~~
|
|
22
|
+
* ~~Support modern structure for AngularJS assets.~~
|
|
23
|
+
* ~~Bower stuff thru [rails-assets](https://rails-assets.org/).~~
|
|
24
|
+
* ~~Rename it to something shorter.~~
|
|
25
|
+
* ~~Stop templates precompiling individually.~~
|
|
26
|
+
* ~~Add initializer for:~~
|
|
27
|
+
* ~~Disabling-disabling precompilation of htm files.~~
|
|
28
|
+
* ~~That one weird trick that sprockets developers don't want you to know!~~
|
|
29
|
+
* ~~Document weird trick.~~
|
|
30
|
+
* ~~Support for angular templates using ERB, Slim~~.
|
|
31
|
+
* ~~Add optional ng-app adjustments.~~
|
|
32
|
+
* ~~__??__ Provide structure for Angular JS assets thru generators.~~
|
|
33
|
+
* ~~Scope API routes~~
|
|
34
|
+
* ~~Smooth out API calls between Rails + Angular~~
|
|
35
|
+
- ~~[Angular restmod](https://github.com/platanus/angular-restmod)~~
|
|
36
|
+
- ~~Active model serializers?~~
|
|
37
|
+
* ~~Check if we can find out whether we're precompiling and stop injecting templates
|
|
38
|
+
in 'development' env.~~
|
|
39
|
+
* ~~Change docs/defaults for template precompilation.~~
|
|
40
|
+
* ~~Add minimal example/starter data.~~
|
|
41
|
+
* ~~Make assets.removed more obvious.~~
|
|
42
|
+
* ~~Add test example.~~
|
|
43
|
+
* ~~Add FDL for wikipedia content.~~
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Rang
|
|
2
|
+
module Api
|
|
3
|
+
module Generators
|
|
4
|
+
class ConfigureGenerator < Rails::Generators::Base
|
|
5
|
+
desc "Configures a sensible default API interface using active_model_serializers and angular-restmod."
|
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
7
|
+
|
|
8
|
+
def add_angular_restmod_to_gemfile
|
|
9
|
+
generate "rang:bower:add", "angular-restmod '~> 0.16' quiet"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_active_model_serializers_to_gemfile
|
|
13
|
+
gem "active_model_serializers", "~> 0.9.0"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def bundle_install
|
|
17
|
+
bundle!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_ams_initializer
|
|
21
|
+
template "active_model_serializer.rb", "config/initializers/active_model_serializer.rb"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add_route_api_scope
|
|
25
|
+
route "scope 'api(/:version)', :module => :api, :version => /v\d+?/, :defaults => {format: :json} do\n # API routes go here\n end\n"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_controller_api_namespace
|
|
29
|
+
empty_directory "app/controllers/api"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_example_serializer
|
|
33
|
+
generate "serializer", "example title:string body:string"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add_to_application_js
|
|
37
|
+
application_js_path = Rails.application.assets.find_asset("application.js").pathname.to_s
|
|
38
|
+
|
|
39
|
+
if !no? "\n\nAdd angular-restmod to application.js? [Yn]", :cyan
|
|
40
|
+
inject_into_file application_js_path, after: /^\/\/= require angular$/ do
|
|
41
|
+
"\n//= require angular-restmod/angular-restmod-bundle"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
rescue
|
|
45
|
+
say "Application.js not found, not adding require for angular-restmod.", :red
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def inform_of_actions
|
|
49
|
+
say "\n\n ****** \n\n"
|
|
50
|
+
say "\nAPI Configured, using:\n\n", :green
|
|
51
|
+
say "## Active_model_serializers", :bold
|
|
52
|
+
say "An example serializer has been written in app/serializers/example_serializer.rb", :cyan
|
|
53
|
+
say "You can (and should) read the full docs here: https://github.com/rails-api/active_model_serializers/tree/0-9-stable\n\n", :cyan
|
|
54
|
+
say "## Angular-restmod", :bold
|
|
55
|
+
say "A Rails-inspired ORM for Angular.", :cyan
|
|
56
|
+
say "Full docs here: https://github.com/platanus/angular-restmod", :cyan
|
|
57
|
+
say "You will need to include 'restmod' in the angular.module calls where you want to use it.\n\n", :cyan
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def bundle!
|
|
63
|
+
Bundler.with_clean_env do
|
|
64
|
+
run "bundle install"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Rang
|
|
2
|
+
module Assets
|
|
3
|
+
module Generators
|
|
4
|
+
class InitGenerator < Rails::Generators::Base
|
|
5
|
+
desc "Sets up assets for recommended Angular structure."
|
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
7
|
+
|
|
8
|
+
def deprecate_old_assets!
|
|
9
|
+
empty_directory 'app/assets.removed'
|
|
10
|
+
|
|
11
|
+
["javascripts", "stylesheets"].each do |dir|
|
|
12
|
+
if File.exist? "app/assets/#{dir}"
|
|
13
|
+
say_status :move, "app/assets/#{dir} -> app/assets.removed/#{dir}"
|
|
14
|
+
run "mv app/assets/#{dir} app/assets.removed/#{dir}", verbose: false
|
|
15
|
+
end
|
|
16
|
+
remove_dir "app/assets/#{dir}"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_assets!
|
|
21
|
+
template 'application.js', 'app/assets/frontend/application.js'
|
|
22
|
+
template 'application.scss', 'app/assets/frontend/application.scss'
|
|
23
|
+
template '_base.scss', 'app/assets/frontend/style/_base.scss'
|
|
24
|
+
template 'components.js', 'app/assets/frontend/components/components.js'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def add_html_attribute
|
|
28
|
+
if !no? "\n\nAdd ng-app='#{Rang::Util.application_name}' to application.html? [Yn]", :cyan
|
|
29
|
+
in_root do
|
|
30
|
+
if layout_handler == "ActionView::Template::Handlers::ERB"
|
|
31
|
+
gsub_file layout_file, "<html>", "<html ng-app='#{Rang::Util.application_name}'>"
|
|
32
|
+
elsif layout_handler == "Slim::RailsTemplate"
|
|
33
|
+
gsub_file layout_file, /^html$/, "html ng-app='#{Rang::Util.application_name}'"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def layout_file
|
|
42
|
+
::ApplicationController.new.send(:_layout).identifier
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def layout_handler
|
|
46
|
+
::ApplicationController.new.send(:_layout).handler.class.to_s
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|