ember-cli-rails 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -0
- data/README.md +228 -69
- data/app/helpers/ember_rails_helper.rb +20 -4
- data/lib/ember-cli/app.rb +113 -26
- data/lib/ember-cli/asset_resolver.rb +54 -0
- data/lib/ember-cli/capture.rb +76 -0
- data/lib/ember-cli/configuration.rb +5 -1
- data/lib/ember-cli/html_page.rb +56 -0
- data/lib/ember-cli/path_set.rb +12 -0
- data/lib/ember-cli/version.rb +1 -1
- data/lib/generators/ember-cli/heroku/USAGE +17 -0
- data/lib/generators/ember-cli/heroku/heroku_generator.rb +26 -0
- data/lib/generators/ember-cli/heroku/templates/bin_heroku_install.erb +13 -0
- data/lib/generators/ember-cli/heroku/templates/package.json.erb +15 -0
- data/lib/tasks/ember-cli.rake +8 -1
- metadata +15 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0ced9f81d08893b0a32775f612145b178f26186
|
4
|
+
data.tar.gz: da368e823ef425a5dd400d87cac02ed2d4761142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f097c1b1201e2a1d46ae8f78eaf0ba550dadb36ea10768dbce51840ad1d9a633d80a22160e5cb41e03f4c3727b15f923b9b5c73b685888c65322ba56a216129e
|
7
|
+
data.tar.gz: e2829b586d65a12e8592e3f74ebe501eb443f1ab713bd241ef42215d4772cf24c61f2dcfdec05ac1bdad4d285595ac3bd549b9711fdd0e868dc36ffa0ca83600
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
master
|
2
|
+
------
|
3
|
+
|
4
|
+
0.4.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
* Extend `include_ember_index_html` helper to accept a block. The contents of
|
8
|
+
the block will be injected into the page
|
9
|
+
* Drop support for Ruby `< 2.1.0` and Rails `4.0.0, < 3.2.0`
|
10
|
+
* Introduce `rails g ember-cli:heroku` generator to configure a project for
|
11
|
+
deploying to Heroku
|
12
|
+
* Introduce `include_ember_index_html` helper
|
13
|
+
|
1
14
|
0.3.5
|
2
15
|
-----
|
3
16
|
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# Ember CLI Rails
|
2
2
|
|
3
|
-
|
3
|
+
Ember CLI Rails is an integration story between (surprise surprise) Ember CLI and
|
4
4
|
Rails 3.1 and up. It is designed to provide an easy way to organize your Rails backed
|
5
|
-
|
6
|
-
[slash
|
5
|
+
Ember CLI application with a specific focus on upgradeability. Rails and Ember
|
6
|
+
[slash Ember CLI] are maintained by different teams with different goals. As
|
7
7
|
such, we believe that it is important to ensure smooth upgrading of both
|
8
8
|
aspects of your application.
|
9
9
|
|
10
10
|
A large contingent of Ember developers use Rails. And Rails is awesome. With
|
11
11
|
the upcoming changes to Ember 2.0 and the Ember community's desire to unify
|
12
|
-
around
|
13
|
-
|
12
|
+
around Ember CLI it is now more important than ever to ensure that Rails and
|
13
|
+
Ember CLI can coexist and development still be fun!
|
14
14
|
|
15
15
|
To this end we have created a minimum set of features (which we will outline
|
16
16
|
below) to allow you keep your Rails workflow while minimizing the risk of
|
@@ -19,7 +19,7 @@ upgrade pain with your Ember build tools.
|
|
19
19
|
For example, end-to-end tests with frameworks like Cucumber should just work.
|
20
20
|
You should still be able leverage the asset pipeline, and all the conveniences
|
21
21
|
that Rails offers. And you should get all the new goodies like ES6 modules and
|
22
|
-
|
22
|
+
Ember CLI addons too! Without further ado, let's get in there!
|
23
23
|
|
24
24
|
## Installation
|
25
25
|
|
@@ -46,12 +46,15 @@ end
|
|
46
46
|
|
47
47
|
##### options
|
48
48
|
|
49
|
-
- app - this represents the name of the
|
49
|
+
- `app` - this represents the name of the Ember CLI application.
|
50
50
|
|
51
|
-
-
|
51
|
+
- `build_timeout` - seconds to allow Ember to build the application before
|
52
|
+
timing out
|
53
|
+
|
54
|
+
- `path` - the path where your Ember CLI application is located. The default
|
52
55
|
value is the name of your app in the Rails root.
|
53
56
|
|
54
|
-
- enable - a lambda that accepts each
|
57
|
+
- `enable` - a lambda that accepts each request's path. The default value is a
|
55
58
|
lambda that returns `true`.
|
56
59
|
|
57
60
|
```ruby
|
@@ -63,20 +66,24 @@ EmberCLI.configure do |c|
|
|
63
66
|
end
|
64
67
|
```
|
65
68
|
|
66
|
-
Once you've updated your initializer to taste,
|
67
|
-
|
69
|
+
Once you've updated your initializer to taste, install Ember CLI if it is not already installed, and use it to generate your Ember CLI app in the location/s specified in the initializer. For example:
|
70
|
+
|
71
|
+
```sh
|
72
|
+
cd frontend
|
73
|
+
ember init
|
74
|
+
```
|
68
75
|
|
69
|
-
For each of your
|
76
|
+
You will also need to install the [ember-cli-rails-addon](https://github.com/rondale-sc/ember-cli-rails-addon). For each of your Ember CLI applications, run:
|
70
77
|
|
71
78
|
```sh
|
72
|
-
npm install --save-dev ember-cli-rails-addon@0.0.
|
79
|
+
npm install --save-dev ember-cli-rails-addon@0.0.13
|
73
80
|
```
|
74
81
|
|
75
|
-
And that's it!
|
82
|
+
And that's it! You should now be able to start up your Rails server and see your Ember CLI app.
|
76
83
|
|
77
|
-
### Multiple
|
84
|
+
### Multiple Ember CLI apps
|
78
85
|
|
79
|
-
In the initializer you may specify multiple
|
86
|
+
In the initializer you may specify multiple Ember CLI apps, each of which can be
|
80
87
|
referenced with the view helper independently. You'd accomplish this like so:
|
81
88
|
|
82
89
|
```ruby
|
@@ -88,35 +95,124 @@ end
|
|
88
95
|
|
89
96
|
## Usage
|
90
97
|
|
91
|
-
|
92
|
-
|
98
|
+
First, specify in your controller that you don't want to render the layout
|
99
|
+
(since EmberCLI's `index.html` is a fully-formed HTML document):
|
100
|
+
|
101
|
+
```rb
|
102
|
+
# app/controllers/application.rb
|
103
|
+
class ApplicationController < ActionController::Base
|
104
|
+
def index
|
105
|
+
render layout: false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
To render the EmberCLI generated `index.html` into the view,
|
111
|
+
use the `include_ember_index_html` helper:
|
112
|
+
|
113
|
+
|
114
|
+
```erb
|
115
|
+
<!-- /app/views/application/index.html.erb -->
|
116
|
+
<%= include_ember_index_html :frontend %>
|
117
|
+
```
|
118
|
+
|
119
|
+
To inject markup into page, pass in a block that accepts the `head`, and
|
120
|
+
(optionally) the `body`:
|
121
|
+
|
122
|
+
```erb
|
123
|
+
<!-- /app/views/application/index.html.erb -->
|
124
|
+
<%= include_ember_index_html :frontend do |head| %>
|
125
|
+
<%= head.append do %>
|
126
|
+
<%= csrf_meta_tags %>
|
127
|
+
<% end %>
|
128
|
+
<% end %>
|
129
|
+
```
|
130
|
+
|
131
|
+
The asset paths will be replaced with asset pipeline generated paths.
|
93
132
|
|
94
|
-
|
133
|
+
*NOTE*
|
134
|
+
|
135
|
+
This helper **requires** that the `index.html` file exists.
|
136
|
+
|
137
|
+
If you see `Errno::ENOENT` errors in development, your requests are timing out
|
138
|
+
before EmberCLI finishes compiling the application.
|
139
|
+
|
140
|
+
To prevent race conditions, increase your `build_timeout` to ensure that the
|
141
|
+
build finishes before your request is processed.
|
142
|
+
|
143
|
+
### Rendering the EmberCLI generated JS and CSS
|
144
|
+
|
145
|
+
In addition to rendering the EmberCLI generated `index.html`, you can inject the
|
146
|
+
`<script>` and `<link>` tags into your Rails generated views:
|
147
|
+
|
148
|
+
```erb
|
149
|
+
<!-- /app/views/application/index.html.erb -->
|
150
|
+
<%= include_ember_script_tags :frontend %>
|
151
|
+
<%= include_ember_stylesheet_tags :frontend %>
|
152
|
+
```
|
153
|
+
|
154
|
+
### Other routes
|
155
|
+
|
156
|
+
Rendering Ember applications at routes other than `/` requires additional setup to avoid an Ember `UnrecognizedURLError`.
|
157
|
+
|
158
|
+
For instance, if you had Ember applications named `:frontend` and `:admin_panel` and you wanted to serve them at `/frontend` and `/admin_panel`, you would set up the following Rails routes:
|
95
159
|
|
96
160
|
```rb
|
97
161
|
# /config/routes.rb
|
98
162
|
Rails.application.routes.draw do
|
99
163
|
root 'application#index'
|
164
|
+
get 'frontend' => 'frontend#index'
|
165
|
+
get 'admin_panel' => 'admin_panel#index'
|
100
166
|
end
|
101
167
|
|
102
|
-
# /app/controllers/
|
103
|
-
class
|
168
|
+
# /app/controllers/frontend_controller.rb
|
169
|
+
class FrontendController < ActionController::Base
|
170
|
+
def index
|
171
|
+
render :index
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# /app/controllers/admin_panel_controller.rb
|
176
|
+
class AdminPanelController < ActionController::Base
|
104
177
|
def index
|
105
178
|
render :index
|
106
179
|
end
|
107
180
|
end
|
108
181
|
```
|
109
182
|
|
110
|
-
|
111
|
-
could render your app at the `/` route with the following view:
|
183
|
+
Additionally, you would have to modify each Ember app's `baseURL` to point to the correct route:
|
112
184
|
|
113
|
-
```
|
114
|
-
|
115
|
-
|
116
|
-
|
185
|
+
```javascript
|
186
|
+
/* /app/frontend/config/environment.js */
|
187
|
+
module.exports = function(environment) {
|
188
|
+
var ENV = {
|
189
|
+
modulePrefix: 'frontend',
|
190
|
+
environment: environment,
|
191
|
+
baseURL: '/frontend', // originally '/'
|
192
|
+
...
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
/* /app/admin_panel/config/environment.js */
|
197
|
+
module.exports = function(environment) {
|
198
|
+
var ENV = {
|
199
|
+
modulePrefix: 'admin_panel',
|
200
|
+
environment: environment,
|
201
|
+
baseURL: '/admin_panel', // originally '/'
|
202
|
+
...
|
203
|
+
}
|
204
|
+
}
|
117
205
|
```
|
206
|
+
Lastly, you would configure each app's `router.js` file so that `rootURL` points to the `baseURL` you just created:
|
118
207
|
|
119
|
-
|
208
|
+
```javascript
|
209
|
+
/* app/frontend/app/router.js */
|
210
|
+
var Router = Ember.Router.extend({
|
211
|
+
rootURL: config.baseURL, // add this line
|
212
|
+
location: config.locationType
|
213
|
+
});
|
214
|
+
```
|
215
|
+
Repeat for `app/admin_panel/app/router.js`. Now your Ember apps will render properly at the alternative routes.
|
120
216
|
|
121
217
|
## CSRF Tokens
|
122
218
|
|
@@ -167,9 +263,21 @@ example, `/ember-tests`) and the name of the Ember app.
|
|
167
263
|
For example, to view tests of the `frontend` app, visit
|
168
264
|
`http://localhost:3000/ember-tests/frontend`.
|
169
265
|
|
266
|
+
## Serving from multi-process servers in development
|
267
|
+
|
268
|
+
If you're using a multi-process server ([Puma], [Unicorn], etc.) in development,
|
269
|
+
make sure it's configured to run a single worker process.
|
270
|
+
|
271
|
+
Without restricting the server to a single process, [it is possible for multiple
|
272
|
+
EmberCLI runners to clobber each others' work][#94].
|
273
|
+
|
274
|
+
[Puma]: https://github.com/puma/puma
|
275
|
+
[Unicorn]: https://rubygems.org/gems/unicorn
|
276
|
+
[#94]: https://github.com/thoughtbot/ember-cli-rails/issues/94#issuecomment-77627453
|
277
|
+
|
170
278
|
## Enabling LiveReload
|
171
279
|
|
172
|
-
In order to get LiveReload up and running with
|
280
|
+
In order to get LiveReload up and running with Ember CLI Rails, you can install
|
173
281
|
[guard](https://github.com/guard/guard) and
|
174
282
|
[guard-livereload](https://github.com/guard/guard-livereload) gems, run `guard
|
175
283
|
init` and then add the following to your `Guardfile`.
|
@@ -182,12 +290,12 @@ guard "livereload" do
|
|
182
290
|
end
|
183
291
|
```
|
184
292
|
|
185
|
-
This tells Guard to watch your
|
293
|
+
This tells Guard to watch your Ember CLI app for any changes to the JavaScript,
|
186
294
|
Handlebars, HTML, or CSS files within `app` path. Take note that other
|
187
295
|
extensions can be added to the line (such as `coffee` for CoffeeScript) to
|
188
296
|
watch them for changes as well.
|
189
297
|
|
190
|
-
*NOTE:*
|
298
|
+
*NOTE:* Ember CLI creates symlinks in `your-appname/tmp` directory, which cannot
|
191
299
|
be handled properly by Guard. This might lead to performance issues on some
|
192
300
|
platforms (most notably on OSX), as well as warnings being printed by latest
|
193
301
|
versions of Guard. As a work-around, one might use
|
@@ -202,62 +310,58 @@ directories %w[app config lib spec your-appname/app]
|
|
202
310
|
|
203
311
|
## Heroku
|
204
312
|
|
205
|
-
|
313
|
+
To configure your Ember CLI Rails app to be ready to deploy on Heroku:
|
206
314
|
|
207
|
-
|
315
|
+
1. Run `rails g ember-cli:heroku` generator
|
316
|
+
1. [Add the NodeJS buildpack][buildpack] and configure NPM to include the
|
317
|
+
`bower` dependency's executable file.
|
208
318
|
|
209
319
|
```sh
|
210
|
-
heroku buildpacks:
|
320
|
+
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-nodejs
|
321
|
+
heroku config:set NPM_CONFIG_PRODUCTION=false
|
211
322
|
```
|
212
323
|
|
213
|
-
|
324
|
+
You should be ready to deploy.
|
214
325
|
|
215
|
-
|
216
|
-
|
217
|
-
https://github.com/heroku/heroku-buildpack-ruby
|
218
|
-
```
|
326
|
+
**NOTE** Run the generator each time you introduce additional EmberCLI
|
327
|
+
applications into the project.
|
219
328
|
|
220
|
-
|
221
|
-
install`:
|
329
|
+
[buildpack]: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app#adding-a-buildpack
|
222
330
|
|
223
|
-
|
224
|
-
gem "rails_12factor", group: :production
|
225
|
-
```
|
226
|
-
|
227
|
-
Add a `package.json` file containing `{}` to the root of your Rails project.
|
228
|
-
This is to make sure it'll be detected by the NodeJS buildpack.
|
331
|
+
## Capistrano
|
229
332
|
|
230
|
-
|
333
|
+
To deploy an EmberCLI-Rails application with Capistrano, make sure your
|
334
|
+
EmberCLI app's `package.json` file includes the `bower` package as a development
|
335
|
+
dependency:
|
231
336
|
|
232
|
-
|
233
|
-
ensure that during the deployment process, Heroku will install all dependencies
|
234
|
-
found in both `node_modules` and `bower_components`.
|
235
|
-
|
236
|
-
```javascript
|
337
|
+
```json
|
237
338
|
{
|
238
|
-
|
239
|
-
|
240
|
-
# ...
|
241
|
-
"postinstall": "node_modules/bower/bin/bower install"¬
|
339
|
+
"devDependencies": {
|
340
|
+
"bower": "*"
|
242
341
|
}
|
243
342
|
}
|
244
343
|
```
|
245
344
|
|
246
|
-
|
345
|
+
## Experiencing Slow Build/Deploy Times?
|
346
|
+
Remove `ember-cli-uglify` from your `package.json` file, and run
|
347
|
+
`npm remove ember-cli-uglify`. This will improve your build/deploy
|
348
|
+
time by about 10 minutes.
|
247
349
|
|
248
|
-
|
350
|
+
The reason build/deploy times were slow is because ember uglified the JS and
|
351
|
+
then added the files to the asset pipeline. Rails would then try and uglify
|
352
|
+
the JS again, and this would be considerably slower than normal.
|
249
353
|
|
250
354
|
## Additional Information
|
251
355
|
|
252
|
-
When running in the development environment,
|
356
|
+
When running in the development environment, Ember CLI Rails runs `ember build`
|
253
357
|
with the `--output-path` and `--watch` flags on. The `--watch` flag tells
|
254
|
-
|
358
|
+
Ember CLI to watch for file system events and rebuild when an Ember CLI file is
|
255
359
|
changed. The `--output-path` flag specifies where the distribution files will
|
256
|
-
be put.
|
360
|
+
be put. Ember CLI Rails does some fancy stuff to get it into your asset path
|
257
361
|
without polluting your git history. Note that for this to work, you must have
|
258
362
|
`config.consider_all_requests_local = true` set in
|
259
363
|
`config/environments/development.rb`, otherwise the middleware responsible for
|
260
|
-
building
|
364
|
+
building Ember CLI will not be enabled.
|
261
365
|
|
262
366
|
Alternatively, if you want to override the default behavior in any given Rails
|
263
367
|
environment, you can manually set the `config.use_ember_middleware` and
|
@@ -290,6 +394,17 @@ if (environment === 'development') {
|
|
290
394
|
|
291
395
|
[ember-cli-mirage]: http://ember-cli-mirage.com/docs/latest/
|
292
396
|
|
397
|
+
### `SKIP_EMBER`
|
398
|
+
|
399
|
+
To disable asset compilation entirely, set an environment variable
|
400
|
+
`SKIP_EMBER=1`.
|
401
|
+
|
402
|
+
This can be useful when an application's frontend is developed locally with
|
403
|
+
EmberCLI-Rails, but deployed separately (for example, with
|
404
|
+
[ember-cli-deploy][ember-cli-deploy]).
|
405
|
+
|
406
|
+
[ember-cli-deploy]: https://github.com/ember-cli/ember-cli-deploy
|
407
|
+
|
293
408
|
#### Ember Dependencies
|
294
409
|
|
295
410
|
Ember has several dependencies. Some of these dependencies might already be
|
@@ -307,10 +422,54 @@ end
|
|
307
422
|
|
308
423
|
jQuery and Handlebars are the main use cases for this flag.
|
309
424
|
|
425
|
+
## Ruby and Rails support
|
426
|
+
|
427
|
+
This project supports:
|
428
|
+
|
429
|
+
* Ruby versions `>= 2.1.0`
|
430
|
+
* Rails `3.2.x` and `>=4.1.x`.
|
431
|
+
|
432
|
+
To learn more about supported versions and upgrades, read the [upgrading guide].
|
433
|
+
|
434
|
+
[upgrading guide]: /UPGRADING.md
|
435
|
+
|
310
436
|
## Contributing
|
311
437
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
438
|
+
See the [CONTRIBUTING] document.
|
439
|
+
Thank you, [contributors]!
|
440
|
+
|
441
|
+
[CONTRIBUTING]: CONTRIBUTING.md
|
442
|
+
[contributors]: https://github.com/thoughtbot/ember-cli-rails/graphs/contributors
|
443
|
+
|
444
|
+
## License
|
445
|
+
|
446
|
+
Open source templates are Copyright (c) 2015 thoughtbot, inc.
|
447
|
+
It contains free software that may be redistributed
|
448
|
+
under the terms specified in the [LICENSE] file.
|
449
|
+
|
450
|
+
[LICENSE]: /LICENSE.txt
|
451
|
+
|
452
|
+
## About
|
453
|
+
|
454
|
+
ember-cli-rails was originally created by
|
455
|
+
[Pavel Pravosud][rwz] and
|
456
|
+
[Jonathan Jackson][rondale-sc].
|
457
|
+
|
458
|
+
ember-cli-rails is maintained by [Sean Doyle][seanpdoyle] and [Jonathan
|
459
|
+
Jackson][rondale-sc].
|
460
|
+
|
461
|
+
[rwz]: https://github.com/rwz
|
462
|
+
[rondale-sc]: https://github.com/rondale-sc
|
463
|
+
[seanpdoyle]: https://github.com/seanpdoyle
|
464
|
+
|
465
|
+
![thoughtbot](https://thoughtbot.com/logo.png)
|
466
|
+
|
467
|
+
ember-cli-rails is maintained and funded by thoughtbot, inc.
|
468
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
469
|
+
|
470
|
+
We love open source software!
|
471
|
+
See [our other projects][community]
|
472
|
+
or [hire us][hire] to help build your product.
|
473
|
+
|
474
|
+
[community]: https://thoughtbot.com/community?utm_source=github
|
475
|
+
[hire]: https://thoughtbot.com/hire-us?utm_source=github
|
@@ -1,9 +1,25 @@
|
|
1
|
+
require "ember-cli/capture"
|
2
|
+
|
1
3
|
module EmberRailsHelper
|
2
|
-
def
|
3
|
-
|
4
|
+
def include_ember_index_html(name, &block)
|
5
|
+
markup_capturer = EmberCLI::Capture.new(sprockets: self, &block)
|
6
|
+
|
7
|
+
head, body = markup_capturer.capture
|
8
|
+
|
9
|
+
html = EmberCLI[name].index_html(
|
10
|
+
sprockets: self,
|
11
|
+
head: head,
|
12
|
+
body: body,
|
13
|
+
)
|
14
|
+
|
15
|
+
render inline: html
|
16
|
+
end
|
17
|
+
|
18
|
+
def include_ember_script_tags(name, **options)
|
19
|
+
javascript_include_tag(*EmberCLI[name].exposed_js_assets, options)
|
4
20
|
end
|
5
21
|
|
6
|
-
def include_ember_stylesheet_tags(name, options
|
7
|
-
stylesheet_link_tag
|
22
|
+
def include_ember_stylesheet_tags(name, **options)
|
23
|
+
stylesheet_link_tag(*EmberCLI[name].exposed_css_assets, options)
|
8
24
|
end
|
9
25
|
end
|
data/lib/ember-cli/app.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require "timeout"
|
2
|
+
require "ember-cli/html_page"
|
3
|
+
require "ember-cli/asset_resolver"
|
2
4
|
|
3
5
|
module EmberCLI
|
4
6
|
class App
|
5
|
-
ADDON_VERSION = "0.0.
|
7
|
+
ADDON_VERSION = "0.0.13"
|
6
8
|
EMBER_CLI_VERSIONS = [ "~> 0.1.5", "~> 0.2.0", "~> 1.13" ]
|
7
9
|
|
8
10
|
class BuildError < StandardError; end
|
@@ -11,7 +13,7 @@ module EmberCLI
|
|
11
13
|
|
12
14
|
delegate :root, to: :paths
|
13
15
|
|
14
|
-
def initialize(name, options
|
16
|
+
def initialize(name, **options)
|
15
17
|
@name, @options = name.to_s, options
|
16
18
|
@paths = PathSet.new(self)
|
17
19
|
end
|
@@ -21,13 +23,29 @@ module EmberCLI
|
|
21
23
|
prepare
|
22
24
|
silence_build{ exec command }
|
23
25
|
check_for_build_error!
|
26
|
+
copy_index_html_file
|
24
27
|
true
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def install_dependencies
|
29
|
-
|
30
|
-
|
32
|
+
if gemfile_path.exist?
|
33
|
+
exec "#{bundler_path} install"
|
34
|
+
end
|
35
|
+
|
36
|
+
exec "#{npm_path} prune && #{npm_path} install"
|
37
|
+
|
38
|
+
if bower_path.nil?
|
39
|
+
fail <<-FAIL
|
40
|
+
Bower is required by EmberCLI.
|
41
|
+
|
42
|
+
Install it with:
|
43
|
+
|
44
|
+
$ npm install -g bower
|
45
|
+
FAIL
|
46
|
+
else
|
47
|
+
exec "#{bower_path} prune && #{bower_path} install"
|
48
|
+
end
|
31
49
|
end
|
32
50
|
|
33
51
|
def run
|
@@ -36,6 +54,7 @@ module EmberCLI
|
|
36
54
|
cmd = command(watch: true)
|
37
55
|
@pid = exec(cmd, method: :spawn)
|
38
56
|
Process.detach pid
|
57
|
+
copy_index_html_file
|
39
58
|
set_on_exit_callback
|
40
59
|
end
|
41
60
|
|
@@ -49,12 +68,32 @@ module EmberCLI
|
|
49
68
|
@pid = nil
|
50
69
|
end
|
51
70
|
|
71
|
+
def index_html(sprockets:, head:, body:)
|
72
|
+
asset_resolver = AssetResolver.new(
|
73
|
+
app: self,
|
74
|
+
sprockets: sprockets,
|
75
|
+
)
|
76
|
+
html_page = HtmlPage.new(
|
77
|
+
asset_resolver: asset_resolver,
|
78
|
+
content: index_file.read,
|
79
|
+
head: head,
|
80
|
+
body: body,
|
81
|
+
)
|
82
|
+
|
83
|
+
html_page.render
|
84
|
+
end
|
85
|
+
|
52
86
|
def exposed_js_assets
|
53
|
-
|
87
|
+
[vendor_assets, application_assets]
|
54
88
|
end
|
89
|
+
alias exposed_css_assets exposed_js_assets
|
55
90
|
|
56
|
-
def
|
57
|
-
|
91
|
+
def vendor_assets
|
92
|
+
"#{name}/vendor"
|
93
|
+
end
|
94
|
+
|
95
|
+
def application_assets
|
96
|
+
"#{name}/#{ember_app_name}"
|
58
97
|
end
|
59
98
|
|
60
99
|
def wait
|
@@ -150,6 +189,7 @@ module EmberCLI
|
|
150
189
|
|
151
190
|
def prepare
|
152
191
|
@prepared ||= begin
|
192
|
+
check_dependencies!
|
153
193
|
check_addon!
|
154
194
|
check_ember_cli_version!
|
155
195
|
reset_build_error!
|
@@ -189,8 +229,39 @@ module EmberCLI
|
|
189
229
|
end
|
190
230
|
end
|
191
231
|
|
232
|
+
def check_dependencies!
|
233
|
+
unless node_modules_present?
|
234
|
+
fail <<-MSG.strip_heredoc
|
235
|
+
EmberCLI app dependencies are not installed. From your Rails application root please run:
|
236
|
+
|
237
|
+
$ bundle exec rake ember:install
|
238
|
+
|
239
|
+
If you do not require Ember at this URL, you can restrict this check using the `enable`
|
240
|
+
option in the EmberCLI initializer.
|
241
|
+
MSG
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def assets_path
|
246
|
+
paths.assets.join(name)
|
247
|
+
end
|
248
|
+
|
249
|
+
def copy_index_html_file
|
250
|
+
if environment == "production"
|
251
|
+
FileUtils.cp(assets_path.join("index.html"), index_file)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def index_file
|
256
|
+
if environment == "production"
|
257
|
+
applications_path.join("#{name}.html")
|
258
|
+
else
|
259
|
+
dist_path.join("index.html")
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
192
263
|
def symlink_to_assets_root
|
193
|
-
assets_path.
|
264
|
+
assets_path.make_symlink dist_path.join("assets")
|
194
265
|
rescue Errno::EEXIST
|
195
266
|
# Sometimes happens when starting multiple Unicorn workers.
|
196
267
|
# Ignoring...
|
@@ -200,14 +271,18 @@ module EmberCLI
|
|
200
271
|
Rails.configuration.assets.precompile << /\A#{name}\//
|
201
272
|
end
|
202
273
|
|
203
|
-
def command(
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
274
|
+
def command(watch: false)
|
275
|
+
watch_flag = ""
|
276
|
+
|
277
|
+
if watch
|
278
|
+
watch_flag = "--watch"
|
279
|
+
|
280
|
+
if watcher
|
281
|
+
watch_flag += " --watcher #{watcher}"
|
282
|
+
end
|
208
283
|
end
|
209
284
|
|
210
|
-
"#{ember_path} build #{
|
285
|
+
"#{ember_path} build #{watch_flag} --environment #{environment} --output-path #{dist_path} #{log_pipe}"
|
211
286
|
end
|
212
287
|
|
213
288
|
def log_pipe
|
@@ -223,7 +298,17 @@ module EmberCLI
|
|
223
298
|
end
|
224
299
|
|
225
300
|
def package_json
|
226
|
-
@package_json ||=
|
301
|
+
@package_json ||=
|
302
|
+
JSON.parse(package_json_file_path.read).with_indifferent_access
|
303
|
+
end
|
304
|
+
|
305
|
+
def addon_package_json
|
306
|
+
@addon_package_json ||=
|
307
|
+
JSON.parse(addon_package_json_file_path.read).with_indifferent_access
|
308
|
+
end
|
309
|
+
|
310
|
+
def addon_version
|
311
|
+
addon_package_json.fetch("version")
|
227
312
|
end
|
228
313
|
|
229
314
|
def dev_dependencies
|
@@ -231,8 +316,12 @@ module EmberCLI
|
|
231
316
|
end
|
232
317
|
|
233
318
|
def addon_present?
|
234
|
-
|
235
|
-
|
319
|
+
addon_package_json_file_path.exist? &&
|
320
|
+
addon_version == ADDON_VERSION
|
321
|
+
end
|
322
|
+
|
323
|
+
def node_modules_present?
|
324
|
+
node_modules_path.exist?
|
236
325
|
end
|
237
326
|
|
238
327
|
def excluded_ember_deps
|
@@ -240,19 +329,17 @@ module EmberCLI
|
|
240
329
|
end
|
241
330
|
|
242
331
|
def env_hash
|
243
|
-
ENV.
|
244
|
-
vars
|
245
|
-
vars
|
246
|
-
vars
|
247
|
-
vars
|
332
|
+
ENV.to_h.tap do |vars|
|
333
|
+
vars["RAILS_ENV"] = Rails.env
|
334
|
+
vars["DISABLE_FINGERPRINTING"] = "true"
|
335
|
+
vars["EXCLUDE_EMBER_ASSETS"] = excluded_ember_deps
|
336
|
+
vars["BUNDLE_GEMFILE"] = gemfile_path.to_s if gemfile_path.exist?
|
248
337
|
end
|
249
338
|
end
|
250
339
|
|
251
|
-
def exec(cmd,
|
252
|
-
method_name = options.fetch(:method, :system)
|
253
|
-
|
340
|
+
def exec(cmd, method: :system)
|
254
341
|
Dir.chdir root do
|
255
|
-
Kernel.public_send(
|
342
|
+
Kernel.public_send(method, env_hash, cmd, err: :out)
|
256
343
|
end
|
257
344
|
end
|
258
345
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module EmberCLI
|
2
|
+
class AssetResolver
|
3
|
+
def initialize(app:, sprockets:)
|
4
|
+
@app = app
|
5
|
+
@sprockets = sprockets
|
6
|
+
end
|
7
|
+
|
8
|
+
def resolve_urls(html_content)
|
9
|
+
mappings.reduce(html_content) do |resolved_content, (asset, new_path)|
|
10
|
+
resolved_content.gsub(%{"assets/#{asset}"}, %{"#{new_path}"})
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def mappings
|
17
|
+
{
|
18
|
+
"#{name}.js" => application.js,
|
19
|
+
"#{name}.css" => application.css,
|
20
|
+
"vendor.js" => vendor.js,
|
21
|
+
"vendor.css" => vendor.css,
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
@app.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def application
|
30
|
+
AssetPath.new(@sprockets, @app.application_assets)
|
31
|
+
end
|
32
|
+
|
33
|
+
def vendor
|
34
|
+
AssetPath.new(@sprockets, @app.vendor_assets)
|
35
|
+
end
|
36
|
+
|
37
|
+
class AssetPath
|
38
|
+
def initialize(sprockets, assets)
|
39
|
+
@sprockets = sprockets
|
40
|
+
@assets = assets
|
41
|
+
end
|
42
|
+
|
43
|
+
def js
|
44
|
+
@sprockets.asset_path(@assets, type: :javascript)
|
45
|
+
end
|
46
|
+
|
47
|
+
def css
|
48
|
+
@sprockets.asset_path(@assets, type: :stylesheet)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private_constant :AssetPath
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module EmberCLI
|
2
|
+
SKIP_CAPTURE = ["", ""].freeze
|
3
|
+
|
4
|
+
class Capture
|
5
|
+
def initialize(sprockets:, &block)
|
6
|
+
@sprockets = sprockets
|
7
|
+
@block = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def capture
|
11
|
+
if block.present?
|
12
|
+
capture_block
|
13
|
+
else
|
14
|
+
SKIP_CAPTURE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :block, :sprockets
|
21
|
+
|
22
|
+
def capture_block
|
23
|
+
if block.arity > 0
|
24
|
+
block.call(*block_arguments)
|
25
|
+
end
|
26
|
+
|
27
|
+
[captured_head.content, captured_body.content]
|
28
|
+
end
|
29
|
+
|
30
|
+
def block_arguments
|
31
|
+
[captured_head, captured_body].first(block.arity)
|
32
|
+
end
|
33
|
+
|
34
|
+
def captured_body
|
35
|
+
@captured_body ||= Block.new(sprockets)
|
36
|
+
end
|
37
|
+
|
38
|
+
def captured_head
|
39
|
+
@captured_head ||= begin
|
40
|
+
if block.arity < 1
|
41
|
+
BlockWithoutArguments.new(sprockets, &block)
|
42
|
+
else
|
43
|
+
Block.new(sprockets)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class BlockWithoutArguments
|
49
|
+
def initialize(sprockets, &block)
|
50
|
+
@sprockets = sprockets
|
51
|
+
@block = block
|
52
|
+
end
|
53
|
+
|
54
|
+
def content
|
55
|
+
@sprockets.capture(&@block)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
private_constant :BlockWithoutArguments
|
59
|
+
|
60
|
+
class Block
|
61
|
+
def initialize(sprockets)
|
62
|
+
@sprockets = sprockets
|
63
|
+
@content = []
|
64
|
+
end
|
65
|
+
|
66
|
+
def append(&block)
|
67
|
+
@content.push(@sprockets.capture(&block))
|
68
|
+
end
|
69
|
+
|
70
|
+
def content
|
71
|
+
@content.join
|
72
|
+
end
|
73
|
+
end
|
74
|
+
private_constant :Block
|
75
|
+
end
|
76
|
+
end
|
@@ -4,7 +4,7 @@ module EmberCLI
|
|
4
4
|
class Configuration
|
5
5
|
include Singleton
|
6
6
|
|
7
|
-
def app(name, options
|
7
|
+
def app(name, **options)
|
8
8
|
apps.store name, App.new(name, options)
|
9
9
|
end
|
10
10
|
|
@@ -17,6 +17,10 @@ module EmberCLI
|
|
17
17
|
@tee_path = Helpers.which("tee")
|
18
18
|
end
|
19
19
|
|
20
|
+
def bower_path
|
21
|
+
@bower_path ||= Helpers.which("bower")
|
22
|
+
end
|
23
|
+
|
20
24
|
def npm_path
|
21
25
|
@npm_path ||= Helpers.which("npm")
|
22
26
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module EmberCLI
|
2
|
+
class HtmlPage
|
3
|
+
def initialize(content:, asset_resolver:, head: "", body: "")
|
4
|
+
@content = content
|
5
|
+
@asset_resolver = asset_resolver
|
6
|
+
@head = head
|
7
|
+
@body = body
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
if has_head_tag?
|
12
|
+
insert_head_content
|
13
|
+
end
|
14
|
+
|
15
|
+
if has_body_tag?
|
16
|
+
insert_body_content
|
17
|
+
end
|
18
|
+
|
19
|
+
html
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def has_head_tag?
|
25
|
+
head_tag_index >= 0
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_body_tag?
|
29
|
+
body_tag_index >= 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def insert_head_content
|
33
|
+
html.insert(head_tag_index, @head.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def insert_body_content
|
37
|
+
html.insert(body_tag_index, @body.to_s)
|
38
|
+
end
|
39
|
+
|
40
|
+
def html
|
41
|
+
@html ||= resolved_html
|
42
|
+
end
|
43
|
+
|
44
|
+
def head_tag_index
|
45
|
+
html.index("</head") || -1
|
46
|
+
end
|
47
|
+
|
48
|
+
def body_tag_index
|
49
|
+
html.index("</body") || -1
|
50
|
+
end
|
51
|
+
|
52
|
+
def resolved_html
|
53
|
+
@asset_resolver.resolve_urls(@content)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ember-cli/path_set.rb
CHANGED
@@ -37,6 +37,10 @@ module EmberCLI
|
|
37
37
|
EmberCLI.root.join("assets").tap(&:mkpath)
|
38
38
|
end
|
39
39
|
|
40
|
+
define_path :applications do
|
41
|
+
Rails.root.join("public", "_apps").tap(&:mkpath)
|
42
|
+
end
|
43
|
+
|
40
44
|
define_path :gemfile do
|
41
45
|
root.join("Gemfile")
|
42
46
|
end
|
@@ -49,6 +53,10 @@ module EmberCLI
|
|
49
53
|
root.join("package.json")
|
50
54
|
end
|
51
55
|
|
56
|
+
define_path :node_modules do
|
57
|
+
root.join("node_modules")
|
58
|
+
end
|
59
|
+
|
52
60
|
define_path :ember do
|
53
61
|
root.join("node_modules", ".bin", "ember").tap do |path|
|
54
62
|
fail <<-MSG.strip_heredoc unless path.executable?
|
@@ -70,6 +78,10 @@ module EmberCLI
|
|
70
78
|
app_options.fetch(:tee_path){ configuration.tee_path }
|
71
79
|
end
|
72
80
|
|
81
|
+
define_path :bower do
|
82
|
+
app_options.fetch(:bower_path) { configuration.bower_path }
|
83
|
+
end
|
84
|
+
|
73
85
|
define_path :npm do
|
74
86
|
app_options.fetch(:npm_path){ configuration.npm_path }
|
75
87
|
end
|
data/lib/ember-cli/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
Configures a project for deploying to Heroku.
|
3
|
+
|
4
|
+
Once the generator is complete, execute the following:
|
5
|
+
|
6
|
+
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-nodejs
|
7
|
+
heroku config:set NPM_CONFIG_PRODUCTION=false
|
8
|
+
|
9
|
+
Example:
|
10
|
+
rails generate ember-cli:heroku
|
11
|
+
|
12
|
+
This will install the following gems:
|
13
|
+
rails_12factor
|
14
|
+
|
15
|
+
This will create:
|
16
|
+
bin/heroku_install
|
17
|
+
package.json
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EmberCLI
|
2
|
+
class HerokuGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
namespace "ember-cli:heroku"
|
6
|
+
|
7
|
+
def copy_package_json_file
|
8
|
+
template "package.json.erb", "package.json"
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_setup_heroku_file
|
12
|
+
template "bin_heroku_install.erb", "bin/heroku_install"
|
13
|
+
run "chmod a+x bin/heroku_install"
|
14
|
+
end
|
15
|
+
|
16
|
+
def inject_12factor_gem
|
17
|
+
gem "rails_12factor", group: [:staging, :production]
|
18
|
+
end
|
19
|
+
|
20
|
+
def app_paths
|
21
|
+
EmberCLI.apps.values.map do |app|
|
22
|
+
app.root.relative_path_from(Rails.root)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"scripts": {
|
3
|
+
"postinstall": "./bin/heroku_install"
|
4
|
+
},
|
5
|
+
"devDependencies": {
|
6
|
+
"bower": "*"
|
7
|
+
},
|
8
|
+
"cacheDirectories": [
|
9
|
+
<%- app_paths.each do |app_path| -%>
|
10
|
+
"<%= app_path %>/node_modules",
|
11
|
+
"<%= app_path %>/bower_components",
|
12
|
+
<%- end -%>
|
13
|
+
"node_modules"
|
14
|
+
]
|
15
|
+
}
|
data/lib/tasks/ember-cli.rake
CHANGED
@@ -15,4 +15,11 @@ namespace :ember do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
unless EmberCLI.skip?
|
19
|
+
# Hook into assets:precompile:all for Rails 3.1+
|
20
|
+
if Rails::VERSION::MAJOR < 4
|
21
|
+
task "assets:precompile:all" => "ember:compile"
|
22
|
+
else
|
23
|
+
task "assets:precompile" => "ember:compile"
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ember-cli-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
21
|
+
version: '3.2'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: '5'
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '3.
|
31
|
+
version: '3.2'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '5'
|
@@ -63,18 +63,25 @@ files:
|
|
63
63
|
- config/routes.rb
|
64
64
|
- lib/ember-cli-rails.rb
|
65
65
|
- lib/ember-cli/app.rb
|
66
|
+
- lib/ember-cli/asset_resolver.rb
|
67
|
+
- lib/ember-cli/capture.rb
|
66
68
|
- lib/ember-cli/configuration.rb
|
67
69
|
- lib/ember-cli/engine.rb
|
68
70
|
- lib/ember-cli/helpers.rb
|
71
|
+
- lib/ember-cli/html_page.rb
|
69
72
|
- lib/ember-cli/middleware.rb
|
70
73
|
- lib/ember-cli/path_set.rb
|
71
74
|
- lib/ember-cli/runner.rb
|
72
75
|
- lib/ember-cli/version.rb
|
76
|
+
- lib/generators/ember-cli/heroku/USAGE
|
77
|
+
- lib/generators/ember-cli/heroku/heroku_generator.rb
|
78
|
+
- lib/generators/ember-cli/heroku/templates/bin_heroku_install.erb
|
79
|
+
- lib/generators/ember-cli/heroku/templates/package.json.erb
|
73
80
|
- lib/generators/ember-cli/init/USAGE
|
74
81
|
- lib/generators/ember-cli/init/init_generator.rb
|
75
82
|
- lib/generators/ember-cli/init/templates/initializer.rb
|
76
83
|
- lib/tasks/ember-cli.rake
|
77
|
-
homepage: https://github.com/
|
84
|
+
homepage: https://github.com/thoughtbot/ember-cli-rails
|
78
85
|
licenses:
|
79
86
|
- MIT
|
80
87
|
metadata: {}
|
@@ -86,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
93
|
requirements:
|
87
94
|
- - ">="
|
88
95
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
96
|
+
version: 2.1.0
|
90
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
98
|
requirements:
|
92
99
|
- - ">="
|
@@ -94,8 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
101
|
version: '0'
|
95
102
|
requirements: []
|
96
103
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.4.
|
104
|
+
rubygems_version: 2.4.5.1
|
98
105
|
signing_key:
|
99
106
|
specification_version: 4
|
100
107
|
summary: Integration between Ember CLI and Rails
|
101
108
|
test_files: []
|
109
|
+
has_rdoc:
|