ember-rails 0.13.0 → 0.18.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +209 -46
  3. data/lib/ember/rails/engine.rb +11 -7
  4. data/lib/ember/rails/version.rb +1 -1
  5. data/lib/ember_rails.rb +64 -30
  6. data/lib/generators/ember/adapter_generator.rb +21 -0
  7. data/lib/generators/ember/bootstrap_generator.rb +29 -9
  8. data/lib/generators/ember/component_generator.rb +28 -0
  9. data/lib/generators/ember/controller_generator.rb +1 -1
  10. data/lib/generators/ember/generator_helpers.rb +28 -3
  11. data/lib/generators/ember/install_generator.rb +165 -13
  12. data/lib/generators/ember/resource_generator.rb +1 -1
  13. data/lib/generators/ember/resource_override.rb +8 -2
  14. data/lib/generators/ember/template_generator.rb +4 -1
  15. data/lib/generators/templates/adapter.js +5 -0
  16. data/lib/generators/templates/adapter.js.coffee +5 -0
  17. data/lib/generators/templates/adapter.js.em +3 -0
  18. data/lib/generators/templates/app.js +4 -2
  19. data/lib/generators/templates/app.js.coffee +3 -1
  20. data/lib/generators/templates/app.js.em +11 -0
  21. data/lib/generators/templates/{application.handlebars → application.hbs} +0 -0
  22. data/lib/generators/templates/application.js +4 -2
  23. data/lib/generators/templates/application.js.coffee +3 -1
  24. data/lib/generators/templates/application.js.em +10 -0
  25. data/lib/generators/templates/application_adapter.js +5 -0
  26. data/lib/generators/templates/application_adapter.js.coffee +5 -0
  27. data/lib/generators/templates/application_adapter.js.em +3 -0
  28. data/lib/generators/templates/array_controller.js +1 -1
  29. data/lib/generators/templates/array_controller.js.em +3 -0
  30. data/lib/generators/templates/component.js +4 -0
  31. data/lib/generators/templates/component.js.coffee +6 -0
  32. data/lib/generators/templates/component.js.em +6 -0
  33. data/lib/generators/templates/component.template.hbs +2 -0
  34. data/lib/generators/templates/controller.js.em +3 -0
  35. data/lib/generators/templates/model.js +1 -1
  36. data/lib/generators/templates/model.js.coffee +1 -1
  37. data/lib/generators/templates/model.js.em +12 -0
  38. data/lib/generators/templates/object_controller.js +1 -1
  39. data/lib/generators/templates/object_controller.js.coffee +1 -1
  40. data/lib/generators/templates/object_controller.js.em +3 -0
  41. data/lib/generators/templates/route.js.em +3 -0
  42. data/lib/generators/templates/router.js.em +5 -0
  43. data/lib/generators/templates/{template.handlebars → template.hbs} +0 -0
  44. data/lib/generators/templates/view.js.em +4 -0
  45. metadata +141 -94
  46. data/lib/ember/handlebars/template.rb +0 -102
  47. data/lib/generators/templates/store.js +0 -6
  48. data/lib/generators/templates/store.js.coffee +0 -6
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ff97dd7b40a93758ef542f4a1743c0c6d5a00b7
4
+ data.tar.gz: ed0d46f1dd9ea3a6b8796db07dc8f5a3fd030863
5
+ SHA512:
6
+ metadata.gz: 9a98d995f779563de591541ed3b138400630d00cbd9535e1a7dbb23f3d61ce7fda0038448b10d606d071d23540541a1211e92bc2df8fd33c18440011424e89cd
7
+ data.tar.gz: 7dc095c8c6c2b879ae5b68df12fd3d2ae33e76fe86e2784c88ed5193b4e86b064b41b67d54015894658e61fc6a9ba14e59c621caa73eefaf688eb5647262243f
data/README.md CHANGED
@@ -1,74 +1,173 @@
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) [![Code Climate](https://codeclimate.com/github/emberjs/ember-rails/badges/gpa.svg)](https://codeclimate.com/github/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.rc5' # 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
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
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
+ ```
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
+
47
+ ```shell
48
+ rails generate ember:install
49
+ ```
50
+
51
+ You'll probably need to clear out your cache after doing this with:
52
+
35
53
  ```shell
36
- rails generate ember:install --head
54
+ rake tmp:clear
37
55
  ```
38
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
+
98
+ ## Configuration Options
99
+
100
+ The following options are available for configuration in your application or environment-level
101
+ config files (`config/application.rb`, `config/environments/development.rb`, etc.):
102
+
103
+ | Configuration Option | Description |
104
+ |----------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
105
+ | `config.ember.variant` | Determines which Ember variant to use. Valid options: `:development`, `:production`. Defaults to `:production` in production, and `:development` everywhere else. |
106
+ | `config.ember.app_name` | Specificies a default application name for all generators. |
107
+ | `config.ember.ember_path` | Specifies a default custom root path for all generators. |
108
+ | `config.handlebars.precompile` | Enables or disables precompilation. Default value: `true`. |
109
+ | `config.handlebars.templates_root` | Sets the root path (under `app/assets/javascripts`) for templates to be looked up in. Default value: `"templates"`. |
110
+ | `config.handlebars.templates_path_separator` | The path separator to use for templates. Default value: `'/'`. |
111
+ | `config.handlebars.output_type` | Configures the style of output (options are `:amd` and `:global`). Default value: `:global`. |
112
+ | `config.handlebars.amd_namespace` | Configures the module prefix for AMD formatted output. Default value: `nil`. |
113
+ | `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. |
114
+
115
+ Note:
116
+
117
+ In a mountable engine, ember-rails will not recognize any configurations.
118
+ Instead, use command line options.
119
+
120
+ ## Enabling Features with Feature Flags
121
+ 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.
122
+
123
+ If a feature is set to false, you will need to compile ember from source yourself to include it.
124
+
125
+ ### Important note for projects that render JSON responses
126
+
127
+ 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.
128
+
129
+ To disable this effect on your JSON responses, put this in an initializer:
130
+ ```Ruby
131
+ # Stop active_model_serializers from adding root elements to JSON responses.
132
+ ActiveModel::Serializer.root = false
133
+ ActiveModel::ArraySerializer.root = false
134
+ ```
135
+
136
+ 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.
137
+
50
138
  ## Architecture
51
139
 
52
140
  Ember does not require an organized file structure. However, ember-rails allows you
53
141
  to use `rails g ember:bootstrap` to create the following directory structure under `app/assets/javascripts`:
54
142
 
55
- controllers/
56
- helpers/
57
- models/
58
- routes/
59
- templates/
60
- views/
143
+ ```
144
+ ├── adapters
145
+ ├── components
146
+ ├── controllers
147
+ ├── helpers
148
+ ├── mixins
149
+ ├── models
150
+ ├── practicality.js.coffee
151
+ ├── router.js.coffee
152
+ ├── routes
153
+ ├── store.js.coffee
154
+ ├── templates
155
+ │ └── components
156
+ └── views
157
+ ```
61
158
 
62
159
  Additionally, it will add the following lines to `app/assets/javascripts/application.js`.
63
160
  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();
161
+ file to set up application namespace and initial requires:
162
+
163
+ ```javascript
164
+ //= require handlebars
165
+ //= require ember
166
+ //= require ember-data
167
+ //= require_self
168
+ //= require rails_app_name
169
+ RailsAppName = Ember.Application.create();
170
+ ```
72
171
 
73
172
  *Example:*
74
173
 
@@ -82,8 +181,16 @@ file to setup application namespace and initial requires:
82
181
  create app/assets/javascripts/views/.gitkeep
83
182
  create app/assets/javascripts/helpers
84
183
  create app/assets/javascripts/helpers/.gitkeep
184
+ create app/assets/javascripts/components
185
+ create app/assets/javascripts/components/.gitkeep
85
186
  create app/assets/javascripts/templates
86
187
  create app/assets/javascripts/templates/.gitkeep
188
+ create app/assets/javascripts/templates/components
189
+ create app/assets/javascripts/templates/components/.gitkeep
190
+ create app/assets/javascripts/mixins
191
+ create app/assets/javascripts/mixins/.gitkeep
192
+ create app/assets/javascripts/adapters
193
+ create app/assets/javascripts/adapters/.gitkeep
87
194
  create app/assets/javascripts/app.js
88
195
 
89
196
  If you want to avoid `.gitkeep` files, use the `skip git` option like
@@ -96,8 +203,7 @@ and including the assets in your layout:
96
203
 
97
204
  <%= javascript_include_tag "templates/admin_panel" %>
98
205
 
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'`.
206
+ If you want to avoid the `templates` prefix, set the `templates_root` option in your application configuration block:
101
207
 
102
208
  config.handlebars.templates_root = 'ember_templates'
103
209
 
@@ -122,20 +228,47 @@ Now a single line in the layout loads everything:
122
228
 
123
229
  <%= javascript_include_tag "templates/all" %>
124
230
 
125
- If you use Slim or Haml templates, you can use handlebars filter :
231
+ ### Note about ember components
232
+
233
+ 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.
234
+
235
+ *Example*
236
+
237
+ Given the following folder structure:
238
+
239
+ ```
240
+ ├── adapters
241
+ ├── components
242
+ ├── controllers
243
+ ├── helpers
244
+ ├── mixins
245
+ ├── models
246
+ ├── practicality.js.coffee
247
+ ├── router.js.coffee
248
+ ├── routes
249
+ ├── store.js.coffee
250
+ ├── templates
251
+ │ └── components
252
+ │ └── my-component.handlebars
253
+ └── views
254
+ ```
126
255
 
127
- handlebars:
128
- <button {{action anActionName}}>OK</button>
256
+ and a `my-component.handlebars` file with the following contents:
129
257
 
130
- It will be translated as :
258
+ <h1>My Component</h1>
131
259
 
132
- <script type="text/x-handlebars">
133
- <button {{action anActionName}}>OK</button>
260
+ It will produce the following handlebars output:
261
+
262
+ <script type="text/x-handlebars" id="components/my-component">
263
+ <h1>My Component</h1>
134
264
  </script>
135
265
 
266
+ You can reference your component inside your other handlebars template files by the handlebars file name:
267
+
268
+ {{ my-component }}
269
+
136
270
  ## Specifying Different Versions of Ember/Handlebars/Ember-Data
137
271
 
138
- ![Ember Data Warning](ember-data-in-progress.png)
139
272
  By default, ember-rails ships with the latest version of
140
273
  [Ember](https://rubygems.org/gems/ember-source/versions),
141
274
  [Handlebars](https://rubygems.org/gems/handlebars-source/versions),
@@ -145,7 +278,7 @@ To specify a different version that'll be used for both template
145
278
  precompilation and serving to the browser, you can specify the desired
146
279
  version of one of the above-linked gems in the Gemfile, e.g.:
147
280
 
148
- gem 'ember-source', '1.0.0.pre4.2'
281
+ gem 'ember-source', '1.7.0'
149
282
 
150
283
  You can also specify versions of 'handlebars-source' and
151
284
  'ember-data-source', but note that an appropriate 'handlebars-source'
@@ -163,11 +296,41 @@ you've specified in your app's configuration, e.g.:
163
296
 
164
297
  ## Updating Ember
165
298
 
166
- If at any point you need to update Ember.js from master, you can do that with
299
+ If at any point you need to update Ember.js from any of the release channels, you can do that with
300
+
301
+ rails generate ember:install --channel=<channel>
302
+
303
+ 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:
304
+ * canary - This references the 'master' branch and is not recommended for production use.
305
+ * beta - This references the 'beta' branch, and will ultimately become the next stable version. It is not recommended for production use.
306
+ * release - This references the 'stable' branch, and is recommended for production use.
307
+
308
+ When you don't specify a channel, the release channel is used.
167
309
 
168
- rails generate ember:install --head
310
+ It is also possible to download a specific tagged release. To do this, use the following syntax:
169
311
 
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.
312
+
313
+ rails generate ember:install --tag=v1.2.0-beta.2 --ember
314
+
315
+ or for ember-data
316
+
317
+ rails generate ember:install --tag=v1.0.0-beta.2 --ember-data
318
+
319
+ ## CSRF Token
320
+
321
+ 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.
322
+ 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).
323
+
324
+ When you use [jquery-ujs](https://github.com/rails/jquery-ujs),
325
+ the CSRF token will be sent to the rails application on every XHR automatically.
326
+ If not so, the following JavaScript is required in your code.
327
+
328
+ ``` javascript
329
+ $.ajaxPrefilter(function(options, originalOptions, xhr) {
330
+ var token = $('meta[name="csrf-token"]').attr('content');
331
+ xhr.setRequestHeader('X-CSRF-Token', token);
332
+ });
333
+ ```
171
334
 
172
335
  ## Note on Patches/Pull Requests
173
336
 
@@ -1,20 +1,24 @@
1
1
  require 'ember/handlebars/template'
2
2
  require 'active_model_serializers'
3
+ require 'sprockets/railtie'
3
4
 
4
5
  module Ember
5
6
  module Rails
6
7
  class Engine < ::Rails::Engine
7
- config.handlebars = ActiveSupport::OrderedOptions.new
8
+ Ember::Handlebars::Template.configure do |handlebars_config|
9
+ config.handlebars = handlebars_config
8
10
 
9
- config.handlebars.precompile = true
10
- config.handlebars.templates_root = "templates"
11
- config.handlebars.templates_path_separator = '/'
11
+ config.handlebars.precompile = true
12
+ config.handlebars.templates_root = 'templates'
13
+ config.handlebars.templates_path_separator = '/'
14
+ config.handlebars.output_type = :global
15
+ config.handlebars.ember_template = Ember::VERSION =~ /\A1.[0-9]\./ ? 'Handlebars' : 'HTMLBars'
16
+ end
12
17
 
13
18
  config.before_initialize do |app|
14
19
  Sprockets::Engines #force autoloading
15
- Sprockets.register_engine '.handlebars', Ember::Handlebars::Template
16
- Sprockets.register_engine '.hbs', Ember::Handlebars::Template
17
- Sprockets.register_engine '.hjs', Ember::Handlebars::Template
20
+
21
+ Ember::Handlebars::Template.setup Sprockets
18
22
  end
19
23
  end
20
24
  end
@@ -1,5 +1,5 @@
1
1
  module Ember
2
2
  module Rails
3
- VERSION = '0.13.0'
3
+ VERSION = '0.18.5'
4
4
  end
5
5
  end
data/lib/ember_rails.rb CHANGED
@@ -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 ['cannot load such file -- handlebars/source', 'no such file to load -- handlebars/source'].include?(e.message)
12
+ end
7
13
 
8
14
  module Ember
9
15
  module Rails
@@ -20,35 +26,63 @@ 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 || ::Rails.env.test?
25
- # test environments should default to development
26
- variant ||= :development
27
- # Copy over the desired ember, ember-data, and handlebars bundled in
28
- # ember-source, ember-data-source, and handlebars-source to a tmp folder.
29
- tmp_path = app.root.join("tmp/ember-rails")
30
- ext = variant == :production ? ".prod.js" : ".js"
31
- FileUtils.mkdir_p(tmp_path)
32
- FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ext}"), tmp_path.join("ember.js"))
33
- FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ext}"), tmp_path.join("ember-data.js"))
34
- app.assets.append_path(tmp_path)
35
-
36
- # Make the handlebars.js and handlebars.runtime.js bundled
37
- # in handlebars-source available.
38
- app.assets.append_path(File.expand_path('../', ::Handlebars::Source.bundled_path))
39
-
40
- # Allow a local variant override
41
- ember_path = app.root.join("vendor/assets/ember/#{variant}")
42
- app.assets.prepend_path(ember_path.to_s) if ember_path.exist?
29
+ def configure_assets(app)
30
+ if config.respond_to?(:assets) && config.assets.respond_to?(:configure)
31
+ # Rails 4.x
32
+ config.assets.configure do |env|
33
+ yield env
34
+ end
35
+ else
36
+ # Rails 3.2
37
+ yield app.assets
38
+ end
39
+ end
40
+
41
+ initializer "ember_rails.setup_vendor_on_locale", :after => "ember_rails.setup", :group => :all do |app|
42
+ variant = app.config.ember.variant || (::Rails.env.production? ? :production : :development)
43
+
44
+ # Allow a local variant override
45
+ ember_path = app.root.join("vendor/assets/ember/#{variant}")
46
+
47
+ configure_assets app do |env|
48
+ env.prepend_path(ember_path.to_s) if ember_path.exist?
49
+ end
50
+ end
51
+
52
+ initializer "ember_rails.copy_vendor_to_local", :after => "ember_rails.setup", :group => :all do |app|
53
+ variant = app.config.ember.variant || (::Rails.env.production? ? :production : :development)
43
54
 
55
+ # Copy over the desired ember and ember-data bundled in
56
+ # ember-source and ember-data-source to a tmp folder.
57
+ tmp_path = app.root.join("tmp/ember-rails")
58
+ FileUtils.mkdir_p(tmp_path)
59
+
60
+ if variant == :production
61
+ ember_ext = ".prod.js"
44
62
  else
45
- warn "No ember.js variant was specified in your config environment."
46
- warn "You can set a specific variant in your application config in "
47
- warn "order for sprockets to locate ember's assets:"
48
- warn ""
49
- warn " config.ember.variant = :development"
50
- warn ""
51
- warn "Valid values are :development and :production"
63
+ ember_ext = ".debug.js"
64
+ 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"
65
+ end
66
+ FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ember_ext}"), tmp_path.join("ember.js"))
67
+ ember_data_ext = variant == :production ? ".prod.js" : ".js"
68
+ FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ember_data_ext}"), tmp_path.join("ember-data.js"))
69
+
70
+ configure_assets app do |env|
71
+ env.append_path tmp_path
72
+ end
73
+ end
74
+
75
+ initializer "ember_rails.setup_vendor", :after => "ember_rails.copy_vendor_to_local", :group => :all do |app|
76
+ configure_assets app do |env|
77
+ env.append_path ::Ember::Source.bundled_path_for(nil)
78
+ env.append_path ::Ember::Data::Source.bundled_path_for(nil)
79
+ env.append_path File.expand_path('../', ::Handlebars::Source.bundled_path) if defined?(::Handlebars::Source)
80
+ end
81
+ end
82
+
83
+ initializer "ember_rails.setup_ember_template_compiler", :after => "ember_rails.setup_vendor", :group => :all do |app|
84
+ configure_assets app do |env|
85
+ Ember::Handlebars::Template.setup_ember_template_compiler(env.resolve('ember-template-compiler.js'))
52
86
  end
53
87
  end
54
88
 
@@ -0,0 +1,21 @@
1
+ require 'generators/ember/generator_helpers'
2
+
3
+ module Ember
4
+ module Generators
5
+ class AdapterGenerator < ::Rails::Generators::NamedBase
6
+ include Ember::Generators::GeneratorHelpers
7
+
8
+ source_root File.expand_path("../../templates", __FILE__)
9
+
10
+ desc "Creates a new Ember.js adapter"
11
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
12
+ class_option :javascript_engine, :desc => "Engine for JavaScripts"
13
+ class_option :app_name, :type => :string, :aliases => "-n", :default => false, :desc => "Custom ember app name"
14
+
15
+ def create_adapter_files
16
+ file_path = File.join(ember_path, 'adapters', class_path, "#{file_name}_adapter.#{engine_extension}")
17
+ template "adapter.#{engine_extension}", file_path
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,7 +11,7 @@ module Ember
11
11
 
12
12
  class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
13
13
  class_option :skip_git, :type => :boolean, :aliases => "-g", :default => false, :desc => "Skip Git keeps"
14
- class_option :javascript_engine, :desc => "Engine for JavaScripts"
14
+ class_option :javascript_engine, :desc => "Engine for JavaScripts (js for JavaScript, coffee for CoffeeScript, etc)"
15
15
  class_option :app_name, :type => :string, :aliases => "-n", :default => false, :desc => "Custom ember app name"
16
16
 
17
17
  def inject_ember
@@ -24,7 +24,7 @@ module Ember
24
24
 
25
25
 
26
26
  def create_dir_layout
27
- %W{models controllers views routes helpers templates}.each do |dir|
27
+ %W{models controllers views routes helpers components templates templates/components mixins adapters}.each do |dir|
28
28
  empty_directory "#{ember_path}/#{dir}"
29
29
  create_file "#{ember_path}/#{dir}/.gitkeep" unless options[:skip_git]
30
30
  end
@@ -38,19 +38,39 @@ module Ember
38
38
  template "router.#{engine_extension}", "#{ember_path}/router.#{engine_extension}"
39
39
  end
40
40
 
41
- def create_store_file
42
- template "store.#{engine_extension}", "#{ember_path}/store.#{engine_extension}"
41
+ def create_adapter_file
42
+ template "application_adapter.#{engine_extension}", "#{ember_path}/adapters/application_adapter.#{engine_extension}"
43
43
  end
44
44
 
45
45
  private
46
+
46
47
  def inject_into_application_file(safe_extension)
47
- application_file = "#{ember_path}/application.#{safe_extension}"
48
- inject_into_file( application_file, :before => /^.*require_tree.*$/) do
49
- context = instance_eval('binding')
50
- source = File.expand_path(find_in_source_paths("application.#{safe_extension}"))
51
- ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
48
+ application_file = "application.#{safe_extension}"
49
+ full_path = Pathname.new(destination_root).join(ember_path, application_file)
50
+
51
+ if full_path.exist?
52
+ injection_options = get_options_from_contents(full_path.read)
53
+
54
+ inject_into_file(full_path.to_s, injection_options) do
55
+ context = instance_eval('binding')
56
+ source = File.expand_path(find_in_source_paths(application_file))
57
+ ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
58
+ end
59
+ else
60
+ template application_file, full_path
52
61
  end
53
62
  end
63
+
64
+ def get_options_from_contents(contents)
65
+ if contents =~ regex = /^.*require_tree.*$/
66
+ {:before => regex}
67
+ elsif contents =~ regex = /^\s*$/
68
+ {:before => regex}
69
+ else
70
+ regex = /\z/
71
+ {:after => regex}
72
+ end
73
+ end
54
74
  end
55
75
  end
56
76
  end
@@ -0,0 +1,28 @@
1
+ require 'generators/ember/generator_helpers'
2
+
3
+ module Ember
4
+ module Generators
5
+ class ComponentGenerator < ::Rails::Generators::NamedBase
6
+ include Ember::Generators::GeneratorHelpers
7
+
8
+ source_root File.expand_path("../../templates", __FILE__)
9
+
10
+ desc "Creates a new Ember.js component and component template\nCustom Ember Components require at least two descriptive names separated by a dash. Use CamelCase or dash-case to name your component.\n\nExample,\n\trails generate ember:component PostChart [options]\n\trails generate ember:component post-chart [options]"
11
+
12
+ class_option :javascript_engine, :desc => "Engine for JavaScripts"
13
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
14
+ class_option :app_name, :type => :string, :aliases => "-n", :default => false, :desc => "Custom ember app name"
15
+
16
+ def create_component_files
17
+ dashed_file_name = file_name.gsub(/_/, '-')
18
+ comp_path = File.join(ember_path, 'components', class_path, "#{dashed_file_name}_component.#{engine_extension}")
19
+ template "component.#{engine_extension}", comp_path
20
+
21
+ templ_path = File.join(ember_path, 'templates/components', class_path, "#{dashed_file_name}.hbs")
22
+ template "component.template.hbs", templ_path
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -12,7 +12,7 @@ module Ember
12
12
  class_option :javascript_engine, :desc => "Engine for JavaScripts"
13
13
  class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
14
14
  class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
15
- class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.ObjectController to represent a single object"
15
+ class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.Controller to represent a single object"
16
16
  class_option :app_name, :type => :string, :aliases => "-n", :default => false, :desc => "Custom ember app name"
17
17
 
18
18