ember-cli-rails 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 676773e5bb8b4ffc3d4fa4367993ca1255bb18c5
4
- data.tar.gz: 70dbbee466951684ec930bf0f82c91c9bc82ab65
3
+ metadata.gz: 6f7a15bd1d1e7f77df7e98e35264d3f0bc65eb85
4
+ data.tar.gz: 75608b21cf7b54146116bc3b6303573ff9b32623
5
5
  SHA512:
6
- metadata.gz: 5e492324bba74a6f59c8ff06f8b39b4933c5579755bae1979816acb41170adfa3dc989c4959860c8136c80e31795d5585a828f411ecbbb2809b4254facc1c9cf
7
- data.tar.gz: 7e02910135f01f81f21db5e5415a538f43268dd55fa4ef8d533dcb4fe62bd25be41a0399e3d5625dfe414bbcb3d3bf1937dc55ae2fa6c3622e6a7dd618bee982
6
+ metadata.gz: 76ec528e85b8ca4698a61b91645f6631d8afe9473357351ef435860cf4eb8c5023802fca59238ae4d35dd91475b2033e8f555a163d1ab554dac064d458900111
7
+ data.tar.gz: cf291820f9befdc3ccc18a598301b3893489b1111ae381d5ff486db54279dcfc72cf38721510f175f04e801c1047c96c16e9bee1b984d68d8176889c2275595b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,37 @@
1
1
  master
2
2
  ------
3
3
 
4
+ 0.5.0
5
+ -----
6
+
7
+ * Deprecate `include_ember_index_html` in favor of the renamed
8
+ `render_ember_app`.
9
+ * Always pass `--environment test` to Rails-generated `ember test` commands.
10
+ [#277]
11
+ * No longer check dependencies within the app. Defer to EmberCLI's `stderr`
12
+ streaming. [#267]
13
+ * Remove `enable` configuration in favor of using `mount_ember_app`. [#261]
14
+ * Introduce `mount_ember_app` route helper [#263]
15
+ * Remove support for viewing Ember tests through Rails. Instead, use `ember
16
+ test` or `ember test --serve` from within the Ember directory. [#264]
17
+ * Remove `build_timeout` configuration [#259]
18
+ * Disable JS minification when generating Heroku setup [#238]
19
+ * `BuildError#message` includes first line of backtrace. [#256]
20
+ * Symlink `dist/` directly to Asset Pipeline [#250]
21
+ * Merge EmberCLI-generated `manifest.json` into Sprocket's [#250]
22
+ * `manifest.json`. Since we now defer to EmberCLI, we no longer need to
23
+ manually resolve asset URLs. [#250]
24
+
25
+ [#277]: https://github.com/thoughtbot/ember-cli-rails/pull/277
26
+ [#267]: https://github.com/thoughtbot/ember-cli-rails/pull/267
27
+ [#264]: https://github.com/thoughtbot/ember-cli-rails/pull/264
28
+ [#263]: https://github.com/thoughtbot/ember-cli-rails/pull/263
29
+ [#259]: https://github.com/thoughtbot/ember-cli-rails/pull/259
30
+ [#238]: https://github.com/thoughtbot/ember-cli-rails/pull/238
31
+ [#256]: https://github.com/thoughtbot/ember-cli-rails/pull/256
32
+ [#250]: https://github.com/thoughtbot/ember-cli-rails/pull/250
33
+ [#261]: https://github.com/thoughtbot/ember-cli-rails/pull/261
34
+
4
35
  0.4.3
5
36
  -----
6
37
 
data/README.md CHANGED
@@ -21,124 +21,170 @@ 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
+ **EmberCLI-Rails Supports EmberCLI 1.13.x and later.**
25
+
24
26
  ## Installation
25
27
 
26
- Firstly, you'll have to include the gem in your `Gemfile` and `bundle install`
28
+ Add the following to your `Gemfile`:
27
29
 
28
30
  ```ruby
29
31
  gem "ember-cli-rails"
30
32
  ```
31
33
 
32
- Then you'll want to configure your installation by adding an `ember.rb`
33
- initializer. There is a generator to guide you, run:
34
+ Then run `bundle install`:
35
+
36
+ ```bash
37
+ $ bundle install
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ First, generate the gem's initializer:
34
43
 
35
- ```shell
36
- rails generate ember-cli:init
44
+ ```bash
45
+ $ rails generate ember-cli:init
37
46
  ```
38
47
 
39
- This will generate an initializer that looks like the following:
48
+ This will create the following initializer:
40
49
 
41
50
  ```ruby
42
- EmberCLI.configure do |c|
51
+ # config/initializers/ember.rb
52
+
53
+ EmberCli.configure do |c|
43
54
  c.app :frontend
44
55
  end
45
56
  ```
46
57
 
47
- ##### options
58
+ The initializer assumes that your Ember application exists in
59
+ `Rails.root.join("frontend")`.
48
60
 
49
- - `app` - this represents the name of the Ember CLI application.
61
+ If this is not the case, you could
62
+
63
+ * move your existing Ember application into `Rails.root.join("frontend")`
64
+ * configure `frontend` to look for the Ember application in its current
65
+ directory:
66
+
67
+ ```rb
68
+ c.app :frontend, path: "~/projects/my-ember-app"
69
+ ```
70
+
71
+ * generate a new Ember project:
72
+
73
+ ```bash
74
+ $ ember new frontend
75
+ ```
50
76
 
51
- - `build_timeout` - seconds to allow Ember to build the application before
52
- timing out
77
+ **Initializer options**
78
+
79
+ - `name` - this represents the name of the Ember CLI application.
53
80
 
54
81
  - `path` - the path where your Ember CLI application is located. The default
55
82
  value is the name of your app in the Rails root.
56
83
 
57
- - `enable` - a lambda that accepts each request's path. The default value is a
58
- lambda that returns `true`.
59
-
60
84
  ```ruby
61
- EmberCLI.configure do |c|
62
- c.app :adminpanel # path is "<your-rails-root>/adminpanel"
85
+ EmberCli.configure do |c|
86
+ c.app :adminpanel # path defaults to `Rails.root.join("adminpanel")`
63
87
  c.app :frontend,
64
- path: "/path/to/your/ember-cli-app/on/disk",
65
- enable: -> path { path.starts_with?("/app/") }
88
+ path: "/path/to/your/ember-cli-app/on/disk"
66
89
  end
67
90
  ```
68
91
 
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:
92
+ Next, install the [ember-cli-rails-addon][addon]:
70
93
 
71
- ```sh
72
- cd frontend
73
- ember init
94
+ ```bash
95
+ $ cd path/to/frontend
96
+ $ npm install --save-dev ember-cli-rails-addon
74
97
  ```
75
98
 
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:
99
+ Be sure that the addon's [`MAJOR` and `MINOR` version][semver] matches the gem's
100
+ `MAJOR` and `MINOR` versions.
77
101
 
78
- ```sh
79
- npm install --save-dev ember-cli-rails-addon@0.0.13
102
+ For instance, if you're using the `0.5.x` version of the gem, specify
103
+ `~> 0.5.0` ion in your Ember app's `package.json`:
104
+
105
+ ```json
106
+ {
107
+ "devDependencies": {
108
+ "ember-cli-rails-addon": "~> 0.5.0"
109
+ }
110
+ }
80
111
  ```
81
112
 
82
- And that's it! You should now be able to start up your Rails server and see your Ember CLI app.
113
+ [addon]: https://github.com/rondale-sc/ember-cli-rails-addon/
114
+ [semver]: http://semver.org/
83
115
 
84
- ### Multiple Ember CLI apps
116
+ Next, configure Rails to route requests to the `frontend` Ember application:
85
117
 
86
- In the initializer you may specify multiple Ember CLI apps, each of which can be
87
- referenced with the view helper independently. You'd accomplish this like so:
118
+ ```rb
119
+ # config/routes.rb
88
120
 
89
- ```ruby
90
- EmberCLI.configure do |c|
91
- c.app :frontend
92
- c.app :admin_panel, path: "/somewhere/else"
121
+ Rails.application.routes.draw do
122
+ mount_ember_app :frontend, to: "/"
93
123
  end
94
124
  ```
95
125
 
96
- ## Usage
126
+ Ember requests will be set `params[:ember_app]` to the name of the application.
127
+ In the above example, `params[:ember_app] == :frontend`.
97
128
 
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):
129
+ **Routing options**
130
+
131
+ * `to` - The path to handle as an Ember application. This will only apply to
132
+ `format: :html` requests. Additionally, this will handle child routes as well.
133
+ For instance, mounting `mount_ember_app :frontend, to: "/frontend"` will handle a
134
+ `format: :html` request to `/frontend/posts`.
135
+ * `controller` - Defaults to `"ember_cli/ember"`
136
+ * `action` - Defaults to `"index"`
137
+
138
+ You should now be able to boot your Rails application, navigate to the `root`
139
+ route, and see your EmberCLI app!
140
+
141
+ ## Configuring the Ember controller
142
+
143
+ By default, routes defined by `ember_app` will be rendered with the internal
144
+ `EmberCli::EmberController`. The `EmberCli::EmberController` renders the Ember
145
+ application's `index.html` and injects the Rails-generated CSRF tags into the
146
+ `<head>`.
147
+
148
+ To override this behavior, specify the `controller` and `action` options:
100
149
 
101
150
  ```rb
102
- # app/controllers/application.rb
103
- class ApplicationController < ActionController::Base
104
- def index
105
- render layout: false
106
- end
151
+ # config/routes
152
+
153
+ Rails.application.routes.draw do
154
+ mount_ember_app :frontend, to: "/", controller: "application", action: "index"
107
155
  end
108
156
  ```
109
157
 
110
- To render the EmberCLI generated `index.html` into the view,
111
- use the `include_ember_index_html` helper:
112
-
158
+ To serve the EmberCLI generated `index.html`, use the `render_ember_app`
159
+ helper in your view:
113
160
 
114
161
  ```erb
115
- <!-- /app/views/application/index.html.erb -->
116
- <%= include_ember_index_html :frontend %>
162
+ <!-- app/views/application/index.html.erb -->
163
+ <%= render_ember_app :frontend %>
117
164
  ```
118
165
 
119
166
  To inject markup into page, pass in a block that accepts the `head`, and
120
167
  (optionally) the `body`:
121
168
 
122
169
  ```erb
123
- <!-- /app/views/application/index.html.erb -->
124
- <%= include_ember_index_html :frontend do |head| %>
170
+ <!-- app/views/application/index.html.erb -->
171
+ <%= render_ember_app :frontend do |head| %>
125
172
  <% head.append do %>
126
173
  <%= csrf_meta_tags %>
127
174
  <% end %>
128
175
  <% end %>
129
176
  ```
130
177
 
131
- The asset paths will be replaced with asset pipeline generated paths.
132
-
133
- *NOTE*
178
+ When serving the EmberCLI generated `index.html`, don't use Rails' layout HTML:
134
179
 
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.
180
+ ```rb
181
+ # app/controllers/application.rb
182
+ class ApplicationController < ActionController::Base
183
+ def index
184
+ render layout: false
185
+ end
186
+ end
187
+ ```
142
188
 
143
189
  ### Rendering the EmberCLI generated JS and CSS
144
190
 
@@ -146,44 +192,43 @@ In addition to rendering the EmberCLI generated `index.html`, you can inject the
146
192
  `<script>` and `<link>` tags into your Rails generated views:
147
193
 
148
194
  ```erb
149
- <!-- /app/views/application/index.html.erb -->
195
+ <!-- app/views/application/index.html.erb -->
150
196
  <%= include_ember_script_tags :frontend %>
151
197
  <%= include_ember_stylesheet_tags :frontend %>
152
198
  ```
153
199
 
154
- ### Other routes
200
+ ### Multiple Ember CLI apps
155
201
 
156
- Rendering Ember applications at routes other than `/` requires additional setup to avoid an Ember `UnrecognizedURLError`.
202
+ In the initializer you may specify multiple Ember CLI apps, each of which can be
203
+ referenced with the view helper independently. You'd accomplish this like so:
157
204
 
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:
205
+ ```ruby
206
+ EmberCLI.configure do |c|
207
+ c.app :frontend
208
+ c.app :admin_panel, path: "/somewhere/else"
209
+ end
210
+ ```
211
+
212
+ Rendering Ember applications at routes other than `/` requires additional setup
213
+ to avoid an Ember `UnrecognizedURLError`.
214
+
215
+ For instance, if you had Ember applications named `:frontend` and
216
+ `:admin_panel` and you wanted to serve them at `/frontend` and `/admin_panel`,
217
+ you would set up the following Rails routes:
159
218
 
160
219
  ```rb
161
220
  # /config/routes.rb
162
221
  Rails.application.routes.draw do
163
- root 'application#index'
164
- get 'frontend' => 'frontend#index'
165
- get 'admin_panel' => 'admin_panel#index'
166
- end
167
-
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
177
- def index
178
- render :index
179
- end
222
+ mount_ember_app :frontend, to: "/frontend"
223
+ mount_ember_app :admin_panel, to: "/admin_panel"
180
224
  end
181
225
  ```
182
226
 
183
- Additionally, you would have to modify each Ember app's `baseURL` to point to the correct route:
227
+ You must modify each Ember app's `baseURL` to point to the correct route:
184
228
 
185
229
  ```javascript
186
- /* /app/frontend/config/environment.js */
230
+ // app/frontend/config/environment.js
231
+
187
232
  module.exports = function(environment) {
188
233
  var ENV = {
189
234
  modulePrefix: 'frontend',
@@ -193,7 +238,8 @@ module.exports = function(environment) {
193
238
  }
194
239
  }
195
240
 
196
- /* /app/admin_panel/config/environment.js */
241
+ // app/admin_panel/config/environment.js
242
+
197
243
  module.exports = function(environment) {
198
244
  var ENV = {
199
245
  modulePrefix: 'admin_panel',
@@ -203,7 +249,9 @@ module.exports = function(environment) {
203
249
  }
204
250
  }
205
251
  ```
206
- Lastly, you would configure each app's `router.js` file so that `rootURL` points to the `baseURL` you just created:
252
+
253
+ Finally, configure each app's `router.js` file so that `rootURL` refers to the
254
+ new `baseURL`:
207
255
 
208
256
  ```javascript
209
257
  /* app/frontend/app/router.js */
@@ -212,7 +260,8 @@ var Router = Ember.Router.extend({
212
260
  location: config.locationType
213
261
  });
214
262
  ```
215
- Repeat for `app/admin_panel/app/router.js`. Now your Ember apps will render properly at the alternative routes.
263
+
264
+ Repeat the process for `admin_panel/app/router.js`.
216
265
 
217
266
  ## CSRF Tokens
218
267
 
@@ -222,47 +271,38 @@ Without it you'll receive a `422 Unprocessable Entity` error, specifically: `Act
222
271
  In order to add that token to your requests, you need to add into your template:
223
272
 
224
273
  ```erb
225
- <!-- /app/views/application/index.html.erb -->
226
- # ... your ember script and stylesheet includes ...
227
- <%= csrf_meta_tags %>
274
+ <!-- app/views/application/index.html.erb -->
275
+ <%= render_ember_app :frontend do |head| %>
276
+ <% head.append do %>
277
+ <%= csrf_meta_tags %>
278
+ <% end %>
279
+ <% end %>
228
280
  ```
229
281
 
230
- This will add the tokens to your page.
282
+ The default `EmberCli::EmberController` and its accompanying view handle this
283
+ for you by default.
231
284
 
232
- You can then override the application `DS.RESTAdapter` (or whatever flavor of adapter you're using) to send that token with the requests:
285
+ However, if you specify your own controller, make sure to append CSRF tags to
286
+ your view's `<head>`.
233
287
 
234
- ```js
235
- // path/to/your/ember-cli-app/app/adapters/application.js
236
- import DS from 'ember-data';
237
- import $ from 'jquery';
288
+ The [ember-cli-rails-addon][addon] addon will inject an initializer into your
289
+ app to set outgoing requests' `X-CSRF-TOKEN` header to the value injected by
290
+ Rails.
238
291
 
239
- export default DS.RESTAdapter.extend({
240
- headers: {
241
- "X-CSRF-Token": $('meta[name="csrf-token"]').attr('content')
242
- }
243
- });
244
- ```
292
+ ### Integrating with Rake
245
293
 
246
- ## Ember Test Suite
294
+ EmberCLI Rails exposes the `ember:test` Rake task to execute Ember's test suite.
247
295
 
248
- To run an Ember app's tests in a browser, mount the `EmberCLI::Engine`:
296
+ If you're using Rake to run your test suite, make sure to configure your test
297
+ task to depend on `ember:test`.
249
298
 
250
- ```ruby
251
- # config/routes.rb
299
+ For example, to configure a bare `rake` command to run both RSpec and Ember test
300
+ suites, configure the `default` task to depend on both `spec` and `ember:test`.
252
301
 
253
- Rails.application.routes.draw do
254
- mount EmberCLI::Engine => "ember-tests" if Rails.env.development?
255
-
256
- root "application#index"
257
- end
302
+ ```rb
303
+ task default: [:spec, "ember:test"]
258
304
  ```
259
305
 
260
- Ember tests are served based on the route you mount the Engine on (in this
261
- example, `/ember-tests`) and the name of the Ember app.
262
-
263
- For example, to view tests of the `frontend` app, visit
264
- `http://localhost:3000/ember-tests/frontend`.
265
-
266
306
  ## Serving from multi-process servers in development
267
307
 
268
308
  If you're using a multi-process server ([Puma], [Unicorn], etc.) in development,
@@ -326,6 +366,21 @@ $ heroku config:unset SKIP_EMBER
326
366
 
327
367
  You should be ready to deploy.
328
368
 
369
+ The generator will disable Rails' JavaScript compression by declaring:
370
+
371
+ ```rb
372
+ config.assets.js_compressor = nil
373
+ ```
374
+
375
+ This is recommended, but might not work for projects that have both Asset
376
+ Pipeline and EmberCLI generated JavaScript.
377
+
378
+ To reverse this change, reconfigure Sprockets to use the `uglifier` gem:
379
+
380
+ ```rb
381
+ config.assets.js_compressor = :uglifier
382
+ ```
383
+
329
384
  **NOTE** Run the generator each time you introduce additional EmberCLI
330
385
  applications into the project.
331
386
 
@@ -404,6 +459,19 @@ environment, you can manually set the `config.use_ember_middleware` and
404
459
  `config.use_ember_live_recompilation` flags in the environment-specific config
405
460
  file.
406
461
 
462
+ ### `ASSET_HOST`
463
+
464
+ Used by [the addon][addon] during fingerprinting.
465
+
466
+ When compiling an Ember app named `"frontend"` from within Rails,
467
+ the addon will prepend the generated asset paths with:
468
+
469
+ ${ASSET_HOST}/assets/frontend/
470
+
471
+ ### `CDN_HOST`
472
+
473
+ Behaves the same way as `ASSET_HOST`, acting as a fallback.
474
+
407
475
  ### `RAILS_ENV`
408
476
 
409
477
  While being managed by EmberCLI Rails, EmberCLI process will have
@@ -450,7 +518,7 @@ from the Ember distribution. You can do so by setting the `exclude_ember_deps`
450
518
  option like so:
451
519
 
452
520
  ```ruby
453
- EmberCLI.configure do |c|
521
+ EmberCli.configure do |c|
454
522
  c.app :frontend, exclude_ember_deps: "jquery"
455
523
  c.app :admin_panel, exclude_ember_deps: ["jquery", "handlebars"]
456
524
  end