discourse-ember-rails 0.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +341 -0
- data/lib/ember-rails.rb +1 -0
- data/lib/ember/rails/engine.rb +25 -0
- data/lib/ember/rails/version.rb +5 -0
- data/lib/ember_rails.rb +96 -0
- data/lib/generators/ember/adapter_generator.rb +21 -0
- data/lib/generators/ember/bootstrap_generator.rb +76 -0
- data/lib/generators/ember/component_generator.rb +28 -0
- data/lib/generators/ember/controller_generator.rb +34 -0
- data/lib/generators/ember/generator_helpers.rb +58 -0
- data/lib/generators/ember/initializer_generator.rb +23 -0
- data/lib/generators/ember/install_generator.rb +194 -0
- data/lib/generators/ember/instance_initializer_generator.rb +23 -0
- data/lib/generators/ember/model_generator.rb +48 -0
- data/lib/generators/ember/resource_generator.rb +29 -0
- data/lib/generators/ember/resource_override.rb +38 -0
- data/lib/generators/ember/route_generator.rb +21 -0
- data/lib/generators/ember/service_generator.rb +23 -0
- data/lib/generators/ember/template_generator.rb +23 -0
- data/lib/generators/ember/view_generator.rb +24 -0
- data/lib/generators/templates/adapter.js +5 -0
- data/lib/generators/templates/adapter.js.coffee +5 -0
- data/lib/generators/templates/adapter.js.em +3 -0
- data/lib/generators/templates/app.js +11 -0
- data/lib/generators/templates/app.js.coffee +11 -0
- data/lib/generators/templates/app.js.em +11 -0
- data/lib/generators/templates/application.hbs +3 -0
- data/lib/generators/templates/application.js +11 -0
- data/lib/generators/templates/application.js.coffee +11 -0
- data/lib/generators/templates/application.js.em +10 -0
- data/lib/generators/templates/application_adapter.js +5 -0
- data/lib/generators/templates/application_adapter.js.coffee +5 -0
- data/lib/generators/templates/application_adapter.js.em +3 -0
- data/lib/generators/templates/array_controller.js +5 -0
- data/lib/generators/templates/array_controller.js.coffee +5 -0
- data/lib/generators/templates/array_controller.js.em +3 -0
- data/lib/generators/templates/component.js +4 -0
- data/lib/generators/templates/component.js.coffee +6 -0
- data/lib/generators/templates/component.js.em +6 -0
- data/lib/generators/templates/component.template.hbs +2 -0
- data/lib/generators/templates/controller.js +5 -0
- data/lib/generators/templates/controller.js.coffee +6 -0
- data/lib/generators/templates/controller.js.em +3 -0
- data/lib/generators/templates/model.js +13 -0
- data/lib/generators/templates/model.js.coffee +12 -0
- data/lib/generators/templates/model.js.em +12 -0
- data/lib/generators/templates/object_controller.js +5 -0
- data/lib/generators/templates/object_controller.js.coffee +5 -0
- data/lib/generators/templates/object_controller.js.em +3 -0
- data/lib/generators/templates/route.js +5 -0
- data/lib/generators/templates/route.js.coffee +5 -0
- data/lib/generators/templates/route.js.em +3 -0
- data/lib/generators/templates/router.js +5 -0
- data/lib/generators/templates/router.js.coffee +5 -0
- data/lib/generators/templates/router.js.em +5 -0
- data/lib/generators/templates/template.hbs +5 -0
- data/lib/generators/templates/view.js +5 -0
- data/lib/generators/templates/view.js.coffee +4 -0
- data/lib/generators/templates/view.js.em +4 -0
- metadata +329 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 00db50d88e7113d359e49c7c5675233df626a02a204b9691db1bb9ff9113b076
|
4
|
+
data.tar.gz: 7b9eca1cb3c5018f341b2bd6fdf32243326fbcb62e115915e3d1ad5ab8ab16dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 542df7c08633fba64400c1d7b0453590d01718fb2486e9212f23d719fe67c125e42bf56776bd4ec997de8ce4ac09a1a3a8268dd3f80a7dd31d9c201814122d7e
|
7
|
+
data.tar.gz: 8a808aaf33b2a11c743adee3915a80e91b07aad6579c4c2ded90b7f1497e8f3444bd99838f425408b707712abb7fc0f265e27c92ae96b6aeae17862630a01f87
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Keith Pitt, Rob Monie, Joao Carlos, Paul Chavard and ember-rails contributors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,341 @@
|
|
1
|
+
# ember-rails [](http://travis-ci.org/emberjs/ember-rails) [](https://gemnasium.com/emberjs/ember-rails) [](https://codeclimate.com/github/emberjs/ember-rails)
|
2
|
+
|
3
|
+
ember-rails makes developing an [Ember.JS](http://emberjs.com/) application much easier in Rails 3.1+.
|
4
|
+
|
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.
|
9
|
+
|
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.
|
11
|
+
|
12
|
+
## Getting started
|
13
|
+
* Add the gem to your application Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'ember-rails'
|
17
|
+
gem 'ember-source', '~> 1.9.0' # or the version you need
|
18
|
+
```
|
19
|
+
|
20
|
+
* Run `bundle install`
|
21
|
+
* Next, generate the application structure:
|
22
|
+
|
23
|
+
```shell
|
24
|
+
rails generate ember:bootstrap
|
25
|
+
```
|
26
|
+
|
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
|
+
```
|
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).
|
40
|
+
|
41
|
+
Notes:
|
42
|
+
|
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
|
+
|
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
|
+
|
67
|
+
## For CoffeeScript support
|
68
|
+
|
69
|
+
Add coffee-rails to the Gemfile
|
70
|
+
```ruby
|
71
|
+
gem 'coffee-rails'
|
72
|
+
```
|
73
|
+
|
74
|
+
Run the bootstrap generator in step 4 with an extra flag instead:
|
75
|
+
```sh
|
76
|
+
rails g ember:bootstrap -g --javascript-engine coffee
|
77
|
+
```
|
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
|
+
|
138
|
+
## Architecture
|
139
|
+
|
140
|
+
Ember does not require an organized file structure. However, ember-rails allows you
|
141
|
+
to use `rails g ember:bootstrap` to create the following directory structure under `app/assets/javascripts`:
|
142
|
+
|
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
|
+
```
|
158
|
+
|
159
|
+
Additionally, it will add the following lines to `app/assets/javascripts/application.js`.
|
160
|
+
By default, it uses the Rails Application's name and creates an `rails_app_name.js`
|
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
|
+
```
|
171
|
+
|
172
|
+
*Example:*
|
173
|
+
|
174
|
+
rails g ember:bootstrap
|
175
|
+
insert app/assets/javascripts/application.js
|
176
|
+
create app/assets/javascripts/models
|
177
|
+
create app/assets/javascripts/models/.gitkeep
|
178
|
+
create app/assets/javascripts/controllers
|
179
|
+
create app/assets/javascripts/controllers/.gitkeep
|
180
|
+
create app/assets/javascripts/views
|
181
|
+
create app/assets/javascripts/views/.gitkeep
|
182
|
+
create app/assets/javascripts/helpers
|
183
|
+
create app/assets/javascripts/helpers/.gitkeep
|
184
|
+
create app/assets/javascripts/components
|
185
|
+
create app/assets/javascripts/components/.gitkeep
|
186
|
+
create app/assets/javascripts/templates
|
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
|
194
|
+
create app/assets/javascripts/app.js
|
195
|
+
|
196
|
+
If you want to avoid `.gitkeep` files, use the `skip git` option like
|
197
|
+
this: `rails g ember:bootstrap -g`.
|
198
|
+
|
199
|
+
Ask Rails to serve HandlebarsJS and pre-compile templates to Ember
|
200
|
+
by putting each template in a dedicated ".js.hjs", ".hbs" or ".handlebars" file
|
201
|
+
(e.g. `app/assets/javascripts/templates/admin_panel.handlebars`)
|
202
|
+
and including the assets in your layout:
|
203
|
+
|
204
|
+
<%= javascript_include_tag "templates/admin_panel" %>
|
205
|
+
|
206
|
+
If you want to avoid the `templates` prefix, set the `templates_root` option in your application configuration block:
|
207
|
+
|
208
|
+
config.handlebars.templates_root = 'ember_templates'
|
209
|
+
|
210
|
+
If you store templates in a file like `app/assets/javascripts/ember_templates/admin_panel.handlebars` after setting the above config,
|
211
|
+
it will be made available to Ember as the `admin_panel` template.
|
212
|
+
|
213
|
+
_(Note: you must clear the local sprockets cache after modifying `templates_root`, stored by default in `tmp/cache/assets`)_
|
214
|
+
|
215
|
+
Default behavior for ember-rails is to precompile handlebars templates.
|
216
|
+
If you don't want this behavior you can turn it off in your application configuration (or per environment in: `config/environments/development.rb`) block:
|
217
|
+
|
218
|
+
config.handlebars.precompile = false
|
219
|
+
|
220
|
+
_(Note: you must clear the local sprockets cache if you disable precompilation, stored by default in `tmp/cache/assets`)_
|
221
|
+
|
222
|
+
Bundle all templates together thanks to Sprockets,
|
223
|
+
e.g create `app/assets/javascripts/templates/all.js` with:
|
224
|
+
|
225
|
+
//= require_tree .
|
226
|
+
|
227
|
+
Now a single line in the layout loads everything:
|
228
|
+
|
229
|
+
<%= javascript_include_tag "templates/all" %>
|
230
|
+
|
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
|
+
```
|
255
|
+
|
256
|
+
and a `my-component.handlebars` file with the following contents:
|
257
|
+
|
258
|
+
<h1>My Component</h1>
|
259
|
+
|
260
|
+
It will produce the following handlebars output:
|
261
|
+
|
262
|
+
<script type="text/x-handlebars" id="components/my-component">
|
263
|
+
<h1>My Component</h1>
|
264
|
+
</script>
|
265
|
+
|
266
|
+
You can reference your component inside your other handlebars template files by the handlebars file name:
|
267
|
+
|
268
|
+
{{ my-component }}
|
269
|
+
|
270
|
+
## Specifying Different Versions of Ember/Handlebars/Ember-Data
|
271
|
+
|
272
|
+
By default, ember-rails ships with the latest version of
|
273
|
+
[Ember](https://rubygems.org/gems/ember-source/versions),
|
274
|
+
[Handlebars](https://rubygems.org/gems/handlebars-source/versions),
|
275
|
+
and [Ember-Data](https://rubygems.org/gems/ember-data-source/versions).
|
276
|
+
|
277
|
+
To specify a different version that'll be used for both template
|
278
|
+
precompilation and serving to the browser, you can specify the desired
|
279
|
+
version of one of the above-linked gems in the Gemfile, e.g.:
|
280
|
+
|
281
|
+
gem 'ember-source', '1.7.0'
|
282
|
+
|
283
|
+
You can also specify versions of 'handlebars-source' and
|
284
|
+
'ember-data-source', but note that an appropriate 'handlebars-source'
|
285
|
+
will be automatically chosen depending on the version of 'ember-source'
|
286
|
+
that's specified.
|
287
|
+
|
288
|
+
You can also override the specific ember.js, handlebars.js, and
|
289
|
+
ember-data.js files that'll be `require`d by the Asset pipeline by
|
290
|
+
placing these files in `vendor/assets/ember/development` and
|
291
|
+
`vendor/assets/ember/production`, depending on the `config.ember.variant`
|
292
|
+
you've specified in your app's configuration, e.g.:
|
293
|
+
|
294
|
+
config.ember.variant = :production
|
295
|
+
#config.ember.variant = :development
|
296
|
+
|
297
|
+
## Updating Ember
|
298
|
+
|
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.
|
309
|
+
|
310
|
+
It is also possible to download a specific tagged release. To do this, use the following syntax:
|
311
|
+
|
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
|
+
```
|
334
|
+
|
335
|
+
## Note on Patches/Pull Requests
|
336
|
+
|
337
|
+
1. Fork the project.
|
338
|
+
2. Make your feature addition or bug fix.
|
339
|
+
3. Add tests for it. This is important so I don't break it in a future version unintentionally.
|
340
|
+
4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
341
|
+
5. Send me a pull request. Bonus points for topic branches.
|
data/lib/ember-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ember_rails'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ember/handlebars/template'
|
2
|
+
require 'active_model_serializers'
|
3
|
+
require 'sprockets/railtie'
|
4
|
+
|
5
|
+
module Ember
|
6
|
+
module Rails
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
Ember::Handlebars::Template.configure do |handlebars_config|
|
9
|
+
config.handlebars = handlebars_config
|
10
|
+
|
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
|
17
|
+
|
18
|
+
config.before_initialize do |app|
|
19
|
+
Sprockets::Engines #force autoloading
|
20
|
+
|
21
|
+
Ember::Handlebars::Template.setup Sprockets
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/ember_rails.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'ember/source'
|
3
|
+
require 'ember/data/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
|
13
|
+
|
14
|
+
module Ember
|
15
|
+
module Rails
|
16
|
+
class Railtie < ::Rails::Railtie
|
17
|
+
config.ember = ActiveSupport::OrderedOptions.new
|
18
|
+
|
19
|
+
generators do |app|
|
20
|
+
app ||= ::Rails.application # Rails 3.0.x does not yield `app`
|
21
|
+
|
22
|
+
app.config.generators.assets = false
|
23
|
+
|
24
|
+
::Rails::Generators.configure!(app.config.generators)
|
25
|
+
::Rails::Generators.hidden_namespaces.uniq!
|
26
|
+
require "generators/ember/resource_override"
|
27
|
+
end
|
28
|
+
|
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)
|
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"
|
62
|
+
else
|
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'))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
initializer "ember_rails.es5_default", :group => :all do |app|
|
90
|
+
if defined?(Closure::Compiler) && app.config.assets.js_compressor == :closure
|
91
|
+
Closure::Compiler::DEFAULT_OPTIONS[:language_in] = 'ECMASCRIPT5'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|