ember-rails-lite 0.12.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +220 -47
  3. data/lib/{ember-rails.rb → ember-rails-lite.rb} +0 -0
  4. data/lib/ember/rails/engine.rb +9 -4
  5. data/lib/ember/rails/version.rb +1 -1
  6. data/lib/ember_rails.rb +39 -28
  7. data/lib/generators/ember/adapter_generator.rb +21 -0
  8. data/lib/generators/ember/bootstrap_generator.rb +27 -9
  9. data/lib/generators/ember/component_generator.rb +28 -0
  10. data/lib/generators/ember/controller_generator.rb +1 -0
  11. data/lib/generators/ember/generator_helpers.rb +32 -5
  12. data/lib/generators/ember/install_generator.rb +169 -13
  13. data/lib/generators/ember/model_generator.rb +1 -0
  14. data/lib/generators/ember/resource_generator.rb +1 -0
  15. data/lib/generators/ember/resource_override.rb +8 -2
  16. data/lib/generators/ember/route_generator.rb +1 -0
  17. data/lib/generators/ember/template_generator.rb +4 -1
  18. data/lib/generators/ember/view_generator.rb +1 -0
  19. data/lib/generators/templates/adapter.js +5 -0
  20. data/lib/generators/templates/adapter.js.coffee +5 -0
  21. data/lib/generators/templates/adapter.js.em +3 -0
  22. data/lib/generators/templates/app.js +4 -2
  23. data/lib/generators/templates/app.js.coffee +3 -1
  24. data/lib/generators/templates/app.js.em +11 -0
  25. data/lib/generators/templates/{application.handlebars → application.hbs} +0 -0
  26. data/lib/generators/templates/application.js +4 -2
  27. data/lib/generators/templates/application.js.coffee +3 -1
  28. data/lib/generators/templates/application.js.em +10 -0
  29. data/lib/generators/templates/application_adapter.js +5 -0
  30. data/lib/generators/templates/application_adapter.js.coffee +5 -0
  31. data/lib/generators/templates/application_adapter.js.em +3 -0
  32. data/lib/generators/templates/array_controller.js +1 -1
  33. data/lib/generators/templates/array_controller.js.em +3 -0
  34. data/lib/generators/templates/component.js +4 -0
  35. data/lib/generators/templates/component.js.coffee +6 -0
  36. data/lib/generators/templates/component.js.em +6 -0
  37. data/lib/generators/templates/component.template.hbs +2 -0
  38. data/lib/generators/templates/controller.js.em +3 -0
  39. data/lib/generators/templates/model.js +1 -1
  40. data/lib/generators/templates/model.js.coffee +1 -1
  41. data/lib/generators/templates/model.js.em +12 -0
  42. data/lib/generators/templates/object_controller.js.em +3 -0
  43. data/lib/generators/templates/route.js.em +3 -0
  44. data/lib/generators/templates/router.js.em +5 -0
  45. data/lib/generators/templates/{template.handlebars → template.hbs} +0 -0
  46. data/lib/generators/templates/view.js.em +4 -0
  47. metadata +112 -92
  48. data/lib/ember/handlebars/template.rb +0 -102
  49. data/lib/ember/handlebars/version.rb +0 -5
  50. data/lib/generators/templates/store.js +0 -6
  51. data/lib/generators/templates/store.js.coffee +0 -6
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5acffc3e20012e7fc795e19984e9b91c353ac820
4
+ data.tar.gz: cd1a0aef3ffc856aed8ded04fafeed9ce4193b62
5
+ SHA512:
6
+ metadata.gz: f355b6562ad79ed46cd716928c4cb8c9b6f60c695268425d146cb5fc770092a3d47b49de19ca3f7d16748673c41d1d24e94e2b43639107aa863a7d9ac33a1d5e
7
+ data.tar.gz: 6bf2c080ca4f1b8dc6076fd0dc80a0d37e169c4e6996fc399314fa853870e184fce8ee0f5ce76c7b914ba05c79076841b1705f441b937338ddfa3198294f517b
data/README.md CHANGED
@@ -1,74 +1,183 @@
1
- # ember-rails [![Build Status](https://secure.travis-ci.org/emberjs/ember-rails.png?branch=master)](http://travis-ci.org/emberjs/ember-rails) [![Dependency Status](https://gemnasium.com/emberjs/ember-rails.png)](https://gemnasium.com/emberjs/ember-rails)
1
+ # ember-rails [![Build Status](https://secure.travis-ci.org/emberjs/ember-rails.svg?branch=master)](http://travis-ci.org/emberjs/ember-rails) [![Dependency Status](https://gemnasium.com/emberjs/ember-rails.png)](https://gemnasium.com/emberjs/ember-rails)
2
2
 
3
- ember-rails allows you to include [Ember.JS](http://emberjs.com/) into your Rails 3.1+ application.
3
+ ember-rails makes developing an [Ember.JS](http://emberjs.com/) application much easier in Rails 3.1+.
4
4
 
5
- The gem will also pre-compile your handlebars templates when building your asset pipeline. It includes development and production copies of Ember.
5
+ The following functionalities are included in this gem:
6
+ - Pre-compiling of your handlebars templates when building your asset pipeline.
7
+ - Inclusion of development and production copies of Ember, [Ember Data](https://github.com/emberjs/data) and [Handlebars](https://github.com/wycats/handlebars.js).
8
+ - Inclusion of [ActiveModel::Serializer](https://github.com/rails-api/active_model_serializers) for integration with Ember Data.
6
9
 
7
- You can see an example of how to use the gem [here](https://github.com/keithpitt/ember-rails-example). There is also a great tutorial by [Dan Gebhardt](https://twitter.com/#!/dgeb) called "[Beginning Ember.js on Rails](http://www.cerebris.com/blog/2012/01/24/beginning-ember-js-on-rails-part-1/)" which is a great read if you're just starting out with Rails and Ember.js
10
+ You can see an example of how to use the gem [here](https://github.com/keithpitt/ember-rails-example). There is also a great tutorial by [Dan Gebhardt](https://twitter.com/#!/dgeb) called "[Beginning Ember.js on Rails](http://www.cerebris.com/blog/2012/01/24/beginning-ember-js-on-rails-part-1/)" which is a great read if you're just starting out with Rails and Ember.js.
8
11
 
9
12
  ## Getting started
10
- 1. Add the gem to your application Gemfile:
13
+ * Add the gem to your application Gemfile:
14
+
11
15
  ```ruby
12
16
  gem 'ember-rails'
13
- gem 'ember-source', '1.0.0.rc4' # or the version you need
14
- gem 'handlebars-source', '1.0.0.rc4' # or the version you need
17
+ gem 'ember-source', '~> 1.9.0' # or the version you need
15
18
  ```
16
19
 
17
- 2. Run `bundle install`
20
+ * Run `bundle install`
21
+ * Next, generate the application structure:
18
22
 
19
- 3. [Optional] Configure the ember variant in your environment files (i.e. development.rb, production.rb). If you don't configure this, the version of Ember used defaults to development when the Rails environment is development, and similarly for production.
20
- ```ruby
21
- config.ember.variant = :development # or :production
22
- ```
23
-
24
- 4. Next, generate the application structure:
25
23
  ```shell
26
- bundle exec rails generate ember:bootstrap
24
+ rails generate ember:bootstrap
27
25
  ```
28
26
 
29
- 5. Restart your server (if it's running)
27
+ * Restart your server (if it's running)
28
+
29
+ ## Building a new project from scratch
30
+
31
+ Rails supports the ability to build projects from a template source ruby file.
32
+
33
+ To build an Ember centric Rails project you can simply type the following into your command line:
34
+
35
+ ```
36
+ rails new my_app -m http://emberjs.com/edge_template.rb
37
+ ```
30
38
 
39
+ Read more about [Rails application templates](http://edgeguides.rubyonrails.org/rails_application_templates.html) and take a look at the edge_template.rb [source code](https://github.com/emberjs/website/blob/master/source/edge_template.rb).
31
40
 
32
41
  Notes:
33
42
 
34
- To install the latest builds of ember and ember-data:
43
+ To install the latest builds of ember and ember-data. It should be noted that the
44
+ examples in the [getting started guide](http://emberjs.com/guides/getting-started/)
45
+ have been designed to use the released version of ember:
46
+
35
47
  ```shell
36
- bundle exec rails generate ember:install --head
48
+ rails generate ember:install
37
49
  ```
38
50
 
51
+ You'll probably need to clear out your cache after doing this with:
52
+
53
+ ```shell
54
+ rake tmp:clear
55
+ ```
56
+
57
+ Also, ember-rails includes some flags for the bootstrap generator:
58
+
59
+ ```
60
+ --ember-path or -d # custom ember path
61
+ --skip-git or -g # skip git keeps
62
+ --javascript-engine # engine for javascript (js, coffee or em)
63
+ --app-name or -n # custom ember app name
64
+ ```
65
+
66
+
39
67
  ## For CoffeeScript support
40
- 1. Add coffee-rails to the Gemfile
68
+
69
+ Add coffee-rails to the Gemfile
41
70
  ```ruby
42
71
  gem 'coffee-rails'
43
72
  ```
44
73
 
45
- 2. Run the bootstrap generator in step 4 with an extra flag instead:
74
+ Run the bootstrap generator in step 4 with an extra flag instead:
46
75
  ```sh
47
76
  rails g ember:bootstrap -g --javascript-engine coffee
48
77
  ```
49
78
 
79
+ ## For EmberScript support
80
+
81
+ [EmberScript](http://www.emberscript.com) is a dialect of CoffeeScript
82
+ with extra support for computed properties (which do not have to be
83
+ explicitly declared), the `class` / `extends` syntax, and extra syntax
84
+ to support observers and mixins.
85
+
86
+ To get EmberScript support, make sure you have the following in your
87
+ Gemfile:
88
+
89
+ ```ruby
90
+ gem 'ember_script-rails', :github => 'ghempton/ember-script-rails'
91
+ ```
92
+
93
+ You can now use the flag `--javascript-engine=em` to specify EmberScript
94
+ assets in your generators, but all of the generators will default to
95
+ using an EmberScript variant first.
96
+
97
+ Note:
98
+
99
+ Ember-rails include some flags options for bootstrap generator:
100
+
101
+ ```
102
+ --ember-path or -d # custom ember path
103
+ --skip-git or -g # skip git keeps
104
+ --javascript-engine # engine for javascript (js, coffee or em)
105
+ --app-name or -n # custom ember app name
106
+ ```
107
+
108
+ ## Configuration Options
109
+
110
+ The following options are available for configuration in your application or environment-level
111
+ config files (`config/application.rb`, `config/environments/development.rb`, etc.):
112
+
113
+ | Configuration Option | Description |
114
+ |----------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
115
+ | `config.ember.variant` | Determines which Ember variant to use. Valid options: `:development`, `:production`. Defaults to `:production` in production, and `:development` everywhere else. |
116
+ | `config.ember.app_name` | Specificies a default application name for all generators. |
117
+ | `config.ember.ember_path` | Specifies a default custom root path for all generators. |
118
+ | `config.handlebars.precompile` | Enables or disables precompilation. Default value: `true`. |
119
+ | `config.handlebars.templates_root` | Sets the root path (under `app/assets/javascripts`) for templates to be looked up in. Default value: `"templates"`. |
120
+ | `config.handlebars.templates_path_separator` | The path separator to use for templates. Default value: `'/'`. |
121
+ | `config.handlebars.output_type` | Configures the style of output (options are `:amd` and `:global`). Default value: `:global`. |
122
+ | `config.handlebars.amd_namespace` | Configures the module prefix for AMD formatted output. Default value: `nil`. |
123
+ | `config.handlebars.ember_template` | Default which Ember template type to compile. Valid options: `'Handlebars', `HTMLBars`. Defaults to 'Handlebars`' when `Ember::VERSION` is under 1.10.0, `HTMLBars` when `Ember::VERSION` is over 1.10.0. |
124
+
125
+ Note:
126
+
127
+ In a mountable engine, ember-rails will not recognize any configurations.
128
+ Instead, use command line options.
129
+
130
+ ## Enabling Features with Feature Flags
131
+ See [the guide](http://emberjs.com/guides/configuring-ember/feature-flags/#toc_flagging-details) and check [features.json](https://github.com/emberjs/ember.js/blob/master/features.json) for the version of Ember you're using.
132
+
133
+ If a feature is set to false, you will need to compile ember from source yourself to include it.
134
+
135
+ ### Important note for projects that render JSON responses
136
+
137
+ ember-rails includes [active_model_serializers](https://github.com/rails-api/active_model_serializers) which affects how ActiveModel and ActiveRecord objects get serialized to JSON, such as when using `render json:` or `respond_with`. By default active_model_serializers adds root elements to these responses (such as adding `{"posts": [...]}` for `render json: @posts`) which will affect the structure of your JSON responses.
138
+
139
+ To disable this effect on your JSON responses, put this in an initializer:
140
+ ```Ruby
141
+ # Stop active_model_serializers from adding root elements to JSON responses.
142
+ ActiveModel::Serializer.root = false
143
+ ActiveModel::ArraySerializer.root = false
144
+ ```
145
+
146
+ See the [active_model_serializers](https://github.com/rails-api/active_model_serializers) documentation for a more complete understanding of other effects this dependency might have on your app.
147
+
50
148
  ## Architecture
51
149
 
52
150
  Ember does not require an organized file structure. However, ember-rails allows you
53
151
  to use `rails g ember:bootstrap` to create the following directory structure under `app/assets/javascripts`:
54
152
 
55
- controllers/
56
- helpers/
57
- models/
58
- routes/
59
- templates/
60
- views/
153
+ ```
154
+ ├── adapters
155
+ ├── components
156
+ ├── controllers
157
+ ├── helpers
158
+ ├── mixins
159
+ ├── models
160
+ ├── practicality.js.coffee
161
+ ├── router.js.coffee
162
+ ├── routes
163
+ ├── store.js.coffee
164
+ ├── templates
165
+ │ └── components
166
+ └── views
167
+ ```
61
168
 
62
169
  Additionally, it will add the following lines to `app/assets/javascripts/application.js`.
63
170
  By default, it uses the Rails Application's name and creates an `rails_app_name.js`
64
- file to setup application namespace and initial requires:
65
-
66
- //= require handlebars
67
- //= require ember
68
- //= require ember-data
69
- //= require_self
70
- //= require rails_app_name
71
- RailsAppName = Ember.Application.create();
171
+ file to set up application namespace and initial requires:
172
+
173
+ ```javascript
174
+ //= require handlebars
175
+ //= require ember
176
+ //= require ember-data
177
+ //= require_self
178
+ //= require rails_app_name
179
+ RailsAppName = Ember.Application.create();
180
+ ```
72
181
 
73
182
  *Example:*
74
183
 
@@ -82,8 +191,16 @@ file to setup application namespace and initial requires:
82
191
  create app/assets/javascripts/views/.gitkeep
83
192
  create app/assets/javascripts/helpers
84
193
  create app/assets/javascripts/helpers/.gitkeep
194
+ create app/assets/javascripts/components
195
+ create app/assets/javascripts/components/.gitkeep
85
196
  create app/assets/javascripts/templates
86
197
  create app/assets/javascripts/templates/.gitkeep
198
+ create app/assets/javascripts/templates/components
199
+ create app/assets/javascripts/templates/components/.gitkeep
200
+ create app/assets/javascripts/mixins
201
+ create app/assets/javascripts/mixins/.gitkeep
202
+ create app/assets/javascripts/adapters
203
+ create app/assets/javascripts/adapters/.gitkeep
87
204
  create app/assets/javascripts/app.js
88
205
 
89
206
  If you want to avoid `.gitkeep` files, use the `skip git` option like
@@ -96,8 +213,7 @@ and including the assets in your layout:
96
213
 
97
214
  <%= javascript_include_tag "templates/admin_panel" %>
98
215
 
99
- If you want to strip template root from template names, add `templates_root` option to your application configuration block.
100
- By default, `templates_root` is `'templates'`.
216
+ If you want to avoid the `templates` prefix, set the `templates_root` option in your application configuration block:
101
217
 
102
218
  config.handlebars.templates_root = 'ember_templates'
103
219
 
@@ -122,20 +238,47 @@ Now a single line in the layout loads everything:
122
238
 
123
239
  <%= javascript_include_tag "templates/all" %>
124
240
 
125
- If you use Slim or Haml templates, you can use handlebars filter :
241
+ ### Note about ember components
242
+
243
+ When necessary, ember-rails adheres to a conventional folder structure. To create an ember component you must define the handlebars file *inside* the *components* folder under the templates folder of your project to properly register your handlebars component file.
244
+
245
+ *Example*
246
+
247
+ Given the following folder structure:
126
248
 
127
- handlebars:
128
- <button {{action anActionName}}>OK</button>
249
+ ```
250
+ ├── adapters
251
+ ├── components
252
+ ├── controllers
253
+ ├── helpers
254
+ ├── mixins
255
+ ├── models
256
+ ├── practicality.js.coffee
257
+ ├── router.js.coffee
258
+ ├── routes
259
+ ├── store.js.coffee
260
+ ├── templates
261
+ │ └── components
262
+ │ └── my-component.handlebars
263
+ └── views
264
+ ```
265
+
266
+ and a `my-component.handlebars` file with the following contents:
129
267
 
130
- It will be translated as :
268
+ <h1>My Component</h1>
131
269
 
132
- <script type="text/x-handlebars">
133
- <button {{action anActionName}}>OK</button>
270
+ It will produce the following handlebars output:
271
+
272
+ <script type="text/x-handlebars" id="components/my-component">
273
+ <h1>My Component</h1>
134
274
  </script>
135
275
 
276
+ You can reference your component inside your other handlebars template files by the handlebars file name:
277
+
278
+ {{ my-component }}
279
+
136
280
  ## Specifying Different Versions of Ember/Handlebars/Ember-Data
137
281
 
138
- ![Ember Data Warning](ember-data-in-progress.png)
139
282
  By default, ember-rails ships with the latest version of
140
283
  [Ember](https://rubygems.org/gems/ember-source/versions),
141
284
  [Handlebars](https://rubygems.org/gems/handlebars-source/versions),
@@ -145,7 +288,7 @@ To specify a different version that'll be used for both template
145
288
  precompilation and serving to the browser, you can specify the desired
146
289
  version of one of the above-linked gems in the Gemfile, e.g.:
147
290
 
148
- gem 'ember-source', '1.0.0.pre4.2'
291
+ gem 'ember-source', '1.7.0'
149
292
 
150
293
  You can also specify versions of 'handlebars-source' and
151
294
  'ember-data-source', but note that an appropriate 'handlebars-source'
@@ -163,11 +306,41 @@ you've specified in your app's configuration, e.g.:
163
306
 
164
307
  ## Updating Ember
165
308
 
166
- If at any point you need to update Ember.js from master, you can do that with
309
+ If at any point you need to update Ember.js from any of the release channels, you can do that with
310
+
311
+ rails generate ember:install --channel=<channel>
312
+
313
+ This will fetch both Ember.js and Ember Data from [http://builds.emberjs.com/](http://builds.emberjs.com/) and copy to the right directory. You can choose between the following channels:
314
+ * canary - This references the 'master' branch and is not recommended for production use.
315
+ * beta - This references the 'beta' branch, and will ultimately become the next stable version. It is not recommended for production use.
316
+ * release - This references the 'stable' branch, and is recommended for production use.
317
+
318
+ When you don't specify a channel, the release channel is used.
167
319
 
168
- rails generate ember:install --head
320
+ It is also possible to download a specific tagged release. To do this, use the following syntax:
169
321
 
170
- This will fetch both Ember.js and Ember Data from [http://builds.emberjs.com/](http://builds.emberjs.com/) and copy to the right directory.
322
+
323
+ rails generate ember:install --tag=v1.2.0-beta.2 --ember
324
+
325
+ or for ember-data
326
+
327
+ rails generate ember:install --tag=v1.0.0-beta.2 --ember-data
328
+
329
+ ## CSRF Token
330
+
331
+ Rails [`protect_from_forgery`](http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#method-i-protect_from_forgery) requires CSRF token for every XHR except GET.
332
+ The CSRF token is normally found in `app/views/layouts/application.html.*` inserted with the rails helper: [`csrf_meta_tags`](http://api.rubyonrails.org/classes/ActionView/Helpers/CsrfHelper.html#method-i-csrf_meta_tags).
333
+
334
+ When you use [jquery-ujs](https://github.com/rails/jquery-ujs),
335
+ the CSRF token will be sent to the rails application on every XHR automatically.
336
+ If not so, the following JavaScript is required in your code.
337
+
338
+ ``` javascript
339
+ $.ajaxPrefilter(function(options, originalOptions, xhr) {
340
+ var token = $('meta[name="csrf-token"]').attr('content');
341
+ xhr.setRequestHeader('X-CSRF-Token', token);
342
+ });
343
+ ```
171
344
 
172
345
  ## Note on Patches/Pull Requests
173
346
 
@@ -1,13 +1,18 @@
1
1
  require 'ember/handlebars/template'
2
+ require 'sprockets/railtie'
2
3
 
3
4
  module Ember
4
5
  module Rails
5
6
  class Engine < ::Rails::Engine
6
- config.handlebars = ActiveSupport::OrderedOptions.new
7
+ Ember::Handlebars::Template.configure do |handlebars_config|
8
+ config.handlebars = handlebars_config
7
9
 
8
- config.handlebars.precompile = true
9
- config.handlebars.templates_root = "templates"
10
- config.handlebars.templates_path_separator = '/'
10
+ config.handlebars.precompile = true
11
+ config.handlebars.templates_root = 'templates'
12
+ config.handlebars.templates_path_separator = '/'
13
+ config.handlebars.output_type = :global
14
+ config.handlebars.ember_template = Ember::VERSION =~ /\A1.[0-9]\./ ? 'Handlebars' : 'HTMLBars'
15
+ end
11
16
 
12
17
  config.before_initialize do |app|
13
18
  Sprockets::Engines #force autoloading
@@ -1,5 +1,5 @@
1
1
  module Ember
2
2
  module Rails
3
- VERSION = '0.12.0'
3
+ VERSION = '0.18.0'
4
4
  end
5
5
  end
@@ -1,9 +1,15 @@
1
1
  require 'rails'
2
- require 'ember/rails/version'
3
- require 'ember/rails/engine'
4
2
  require 'ember/source'
5
3
  require 'ember/data/source'
6
- require 'handlebars/source'
4
+ require 'ember/rails/version'
5
+ require 'ember/rails/engine'
6
+
7
+ # Use handlebars if it possible. Because it is an optional feature.
8
+ begin
9
+ require 'handlebars/source'
10
+ rescue LoadError => e
11
+ raise e unless e.message == 'cannot load such file -- handlebars/source'
12
+ end
7
13
 
8
14
  module Ember
9
15
  module Rails
@@ -20,34 +26,39 @@ module Ember
20
26
  require "generators/ember/resource_override"
21
27
  end
22
28
 
23
- initializer "ember_rails.setup_vendor", :after => "ember_rails.setup", :group => :all do |app|
24
- if variant = app.config.ember.variant
25
- # Copy over the desired ember, ember-data, and handlebars bundled in
26
- # ember-source, ember-data-source, and handlebars-source to a tmp folder.
27
- tmp_path = app.root.join("tmp/ember-rails")
28
- ext = variant == :production ? ".prod.js" : ".js"
29
- FileUtils.mkdir_p(tmp_path)
30
- FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ext}"), tmp_path.join("ember.js"))
31
- FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ext}"), tmp_path.join("ember-data.js"))
32
- app.assets.append_path(tmp_path)
33
-
34
- # Make the handlebars.js and handlebars.runtime.js bundled
35
- # in handlebars-source available.
36
- app.assets.append_path(File.expand_path('../', ::Handlebars::Source.bundled_path))
37
-
38
- # Allow a local variant override
39
- ember_path = app.root.join("vendor/assets/ember/#{variant}")
40
- app.assets.prepend_path(ember_path.to_s) if ember_path.exist?
29
+ initializer "ember_rails.setup_vendor_on_locale", :after => "ember_rails.setup", :group => :all do |app|
30
+ variant = app.config.ember.variant || (::Rails.env.production? ? :production : :development)
41
31
 
32
+ # Allow a local variant override
33
+ ember_path = app.root.join("vendor/assets/ember/#{variant}")
34
+ app.assets.prepend_path(ember_path.to_s) if ember_path.exist?
35
+ end
36
+
37
+ initializer "ember_rails.copy_vendor_to_local", :after => "ember_rails.setup", :group => :all do |app|
38
+ variant = app.config.ember.variant || (::Rails.env.production? ? :production : :development)
39
+
40
+ # Copy over the desired ember and ember-data bundled in
41
+ # ember-source and ember-data-source to a tmp folder.
42
+ tmp_path = app.root.join("tmp/ember-rails")
43
+ FileUtils.mkdir_p(tmp_path)
44
+
45
+ if variant == :production
46
+ ember_ext = ".prod.js"
42
47
  else
43
- warn "No ember.js variant was specified in your config environment."
44
- warn "You can set a specific variant in your application config in "
45
- warn "order for sprockets to locate ember's assets:"
46
- warn ""
47
- warn " config.ember.variant = :development"
48
- warn ""
49
- warn "Valid values are :development and :production"
48
+ ember_ext = ".debug.js"
49
+ ember_ext = ".js" unless File.exist?(::Ember::Source.bundled_path_for("ember#{ember_ext}")) # Ember.js 1.9.0 or earlier has no "ember.debug.js"
50
50
  end
51
+ FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ember_ext}"), tmp_path.join("ember.js"))
52
+ ember_data_ext = variant == :production ? ".prod.js" : ".js"
53
+ FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ember_data_ext}"), tmp_path.join("ember-data.js"))
54
+
55
+ app.assets.append_path(tmp_path)
56
+ end
57
+
58
+ initializer "ember_rails.setup_vendor", :after => "ember_rails.copy_vendor_to_local", :group => :all do |app|
59
+ app.assets.append_path(::Ember::Source.bundled_path_for(nil))
60
+ app.assets.append_path(::Ember::Data::Source.bundled_path_for(nil))
61
+ app.assets.append_path(File.expand_path('../', ::Handlebars::Source.bundled_path)) if defined?(::Handlebars::Source)
51
62
  end
52
63
 
53
64
  initializer "ember_rails.es5_default", :group => :all do |app|