ember-rails 0.14.0 → 0.18.0
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 +4 -4
- data/README.md +141 -102
- data/lib/ember/rails/engine.rb +8 -5
- data/lib/ember/rails/version.rb +1 -1
- data/lib/ember_rails.rb +36 -16
- data/lib/generators/ember/adapter_generator.rb +21 -0
- data/lib/generators/ember/bootstrap_generator.rb +6 -3
- data/lib/generators/ember/component_generator.rb +2 -2
- data/lib/generators/ember/generator_helpers.rb +7 -5
- data/lib/generators/ember/install_generator.rb +64 -32
- data/lib/generators/ember/resource_override.rb +8 -2
- data/lib/generators/ember/template_generator.rb +2 -2
- 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 +2 -2
- data/lib/generators/templates/app.js.coffee +2 -1
- data/lib/generators/templates/app.js.em +3 -1
- data/lib/generators/templates/{application.handlebars → application.hbs} +0 -0
- data/lib/generators/templates/application.js +3 -2
- data/lib/generators/templates/application.js.coffee +3 -1
- data/lib/generators/templates/application.js.em +3 -1
- 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 +1 -1
- data/lib/generators/templates/{component.template.handlebars → component.template.hbs} +0 -0
- data/lib/generators/templates/model.js +1 -1
- data/lib/generators/templates/model.js.coffee +1 -1
- data/lib/generators/templates/model.js.em +1 -1
- data/lib/generators/templates/{template.handlebars → template.hbs} +0 -0
- metadata +77 -103
- data/lib/ember/handlebars/template.rb +0 -113
- data/lib/generators/templates/store.js +0 -7
- data/lib/generators/templates/store.js.coffee +0 -6
- data/lib/generators/templates/store.js.em +0 -7
@@ -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
|
@@ -24,7 +24,7 @@ module Ember
|
|
24
24
|
|
25
25
|
|
26
26
|
def create_dir_layout
|
27
|
-
%W{models controllers views routes helpers components templates templates/components mixins}.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,8 +38,8 @@ module Ember
|
|
38
38
|
template "router.#{engine_extension}", "#{ember_path}/router.#{engine_extension}"
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
template "
|
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
|
@@ -54,6 +54,9 @@ module Ember
|
|
54
54
|
{:before => regex}
|
55
55
|
elsif contents =~ regex = /^\s*$/
|
56
56
|
{:before => regex}
|
57
|
+
else
|
58
|
+
regex = /\z/
|
59
|
+
{:after => regex}
|
57
60
|
end
|
58
61
|
|
59
62
|
inject_into_file(full_path.to_s, injection_options) do
|
@@ -18,8 +18,8 @@ module Ember
|
|
18
18
|
comp_path = File.join(ember_path, 'components', class_path, "#{dashed_file_name}_component.#{engine_extension}")
|
19
19
|
template "component.#{engine_extension}", comp_path
|
20
20
|
|
21
|
-
templ_path = File.join(ember_path, 'templates/components', class_path, "#{dashed_file_name}.
|
22
|
-
template "component.template.
|
21
|
+
templ_path = File.join(ember_path, 'templates/components', class_path, "#{dashed_file_name}.hbs")
|
22
|
+
template "component.template.hbs", templ_path
|
23
23
|
|
24
24
|
end
|
25
25
|
|
@@ -5,10 +5,10 @@ module Ember
|
|
5
5
|
def ember_path
|
6
6
|
if options[:ember_path]
|
7
7
|
options[:ember_path]
|
8
|
-
elsif configuration.ember_path
|
9
|
-
configuration.ember_path
|
10
8
|
elsif rails_engine?
|
11
9
|
"app/assets/javascripts/#{engine_name}"
|
10
|
+
elsif configuration.ember_path
|
11
|
+
configuration.ember_path
|
12
12
|
else
|
13
13
|
"app/assets/javascripts"
|
14
14
|
end
|
@@ -25,10 +25,10 @@ module Ember
|
|
25
25
|
def application_name
|
26
26
|
if options[:app_name]
|
27
27
|
options[:app_name]
|
28
|
-
elsif configuration.app_name
|
29
|
-
configuration.app_name
|
30
28
|
elsif rails_engine?
|
31
29
|
engine_name
|
30
|
+
elsif configuration.app_name
|
31
|
+
configuration.app_name
|
32
32
|
elsif defined?(::Rails) && ::Rails.application
|
33
33
|
::Rails.application.class.name.split('::').first
|
34
34
|
else
|
@@ -49,7 +49,9 @@ module Ember
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def configuration
|
52
|
-
::Rails.configuration
|
52
|
+
if defined?(::Rails) && ::Rails.configuration
|
53
|
+
::Rails.configuration.ember
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -10,37 +10,35 @@ module Ember
|
|
10
10
|
|
11
11
|
class InvalidChannel < ::Thor::Error; end
|
12
12
|
class ConflictingOptions < ::Thor::Error; end
|
13
|
-
class Deprecated < ::Thor::Error; end
|
14
13
|
class InsufficientOptions < ::Thor::Error; end
|
15
14
|
|
16
15
|
::InvalidChannel = InvalidChannel
|
17
16
|
::ConflictingOptions = ConflictingOptions
|
18
|
-
::Deprecated = Deprecated
|
19
17
|
::InsufficientOptions = InsufficientOptions
|
20
18
|
|
21
19
|
desc "Install Ember.js into your vendor folder"
|
22
20
|
class_option :head,
|
23
|
-
:type => :boolean,
|
24
|
-
:default => false,
|
21
|
+
:type => :boolean,
|
22
|
+
:default => false,
|
25
23
|
:desc => "Download Ember.js & Ember data from canary channel. This is deprecated. Use channel instead."
|
26
24
|
class_option :channel,
|
27
25
|
:type => :string,
|
28
26
|
:required => false,
|
29
27
|
:desc => "Ember release channel Choose between 'release', 'beta' or 'canary'"
|
30
|
-
class_option :ember_only,
|
31
|
-
:type => :boolean,
|
32
|
-
:required => false,
|
28
|
+
class_option :ember_only,
|
29
|
+
:type => :boolean,
|
30
|
+
:required => false,
|
33
31
|
:desc => "Only download Ember.",
|
34
32
|
:aliases => '--ember'
|
35
33
|
class_option :ember_data_only,
|
36
|
-
:type => :boolean,
|
37
|
-
:required => false,
|
38
|
-
:desc => "Only download ember-data",
|
34
|
+
:type => :boolean,
|
35
|
+
:required => false,
|
36
|
+
:desc => "Only download ember-data",
|
39
37
|
:aliases => '--ember-data'
|
40
38
|
class_option :tag,
|
41
39
|
:type => :string,
|
42
|
-
:required => false,
|
43
|
-
:desc => "Download
|
40
|
+
:required => false,
|
41
|
+
:desc => "Download tagged release use syntax v1.0.0-beta.3/ember-data & v1.0.0-rc.8/ember"
|
44
42
|
|
45
43
|
def initialize(args = [], options = {}, config = {})
|
46
44
|
super(args, options, config)
|
@@ -73,32 +71,53 @@ module Ember
|
|
73
71
|
|
74
72
|
private
|
75
73
|
|
76
|
-
|
77
74
|
def get_ember_data_for(environment)
|
75
|
+
# temporarily using a variable here until a stable release of
|
76
|
+
# ember-data is released so that installing with ember-data
|
77
|
+
# *just works*.
|
78
|
+
chan = if channel.to_s == 'release'
|
79
|
+
say_status("warning:", 'Ember Data is not available on the :release channel. Falling back to beta channel.' , :yellow)
|
80
|
+
:beta
|
81
|
+
else
|
82
|
+
channel
|
83
|
+
end
|
84
|
+
|
78
85
|
create_file "vendor/assets/ember/#{environment}/ember-data.js" do
|
79
|
-
fetch
|
86
|
+
fetch url_for(chan, 'ember-data', environment), "vendor/assets/ember/#{environment}/ember-data.js"
|
87
|
+
end
|
88
|
+
|
89
|
+
sourcemap_url = "#{base_url}/#{chan}/ember-data.js.map"
|
90
|
+
if resource_exist?(sourcemap_url)
|
91
|
+
create_file "vendor/assets/ember/#{environment}/ember-data.js.map" do
|
92
|
+
fetch sourcemap_url, "vendor/assets/ember/#{environment}/ember-data.js.map", false
|
93
|
+
end
|
80
94
|
end
|
81
95
|
end
|
82
96
|
|
83
97
|
def get_ember_js_for(environment)
|
84
|
-
|
85
98
|
create_file "vendor/assets/ember/#{environment}/ember.js" do
|
86
|
-
fetch
|
99
|
+
fetch url_for(channel, 'ember', environment), "vendor/assets/ember/#{environment}/ember.js"
|
87
100
|
end
|
88
101
|
end
|
89
102
|
|
90
|
-
def
|
103
|
+
def url_for(channel, component, environment)
|
104
|
+
base = "#{base_url}/#{channel}/#{component}"
|
105
|
+
|
91
106
|
case environment
|
92
107
|
when :production
|
93
|
-
"#{
|
108
|
+
"#{base}.min.js"
|
94
109
|
when :development
|
95
|
-
"#{
|
110
|
+
if resource_exist?("#{base}.debug.js")
|
111
|
+
"#{base}.debug.js" # Ember.js 1.10.0.beta.1 or later
|
112
|
+
else
|
113
|
+
"#{base}.js"
|
114
|
+
end
|
96
115
|
end
|
97
116
|
end
|
98
117
|
|
99
118
|
def check_options
|
100
|
-
if options.head?
|
101
|
-
say('WARNING: --head option is deprecated in favor of --channel=
|
119
|
+
if options.head?
|
120
|
+
say('WARNING: --head option is deprecated in favor of --channel=canary' , :yellow)
|
102
121
|
end
|
103
122
|
if options.head? && options.channel?
|
104
123
|
say 'ERROR: conflicting options. --head and --channel. Use either --head or --channel=<channel>', :red
|
@@ -123,7 +142,7 @@ module Ember
|
|
123
142
|
end
|
124
143
|
|
125
144
|
def process_options
|
126
|
-
if options.head?
|
145
|
+
if options.head?
|
127
146
|
@channel = :canary
|
128
147
|
end
|
129
148
|
if options.tag?
|
@@ -143,23 +162,36 @@ module Ember
|
|
143
162
|
end
|
144
163
|
end
|
145
164
|
|
146
|
-
|
147
|
-
def fetch(from, to)
|
165
|
+
def fetch(from, to, prepend_verbose = true)
|
148
166
|
message = "#{from} -> #{to}"
|
149
167
|
say_status("downloading:", message , :green)
|
150
168
|
|
151
169
|
uri = URI(from)
|
152
170
|
output = StringIO.new
|
153
|
-
|
154
|
-
|
155
|
-
|
171
|
+
if prepend_verbose
|
172
|
+
output.puts "// Fetched from channel: #{channel}, with url " + uri.to_s
|
173
|
+
output.puts "// Fetched on: " + Time.now.utc.iso8601.to_s
|
174
|
+
end
|
175
|
+
|
176
|
+
response = Net::HTTP.get_response(uri)
|
177
|
+
case response.code
|
178
|
+
when '404'
|
179
|
+
say "ERROR: Error reading the content from the channel with url #{from}. File not found" , :red
|
180
|
+
raise Thor::Error
|
181
|
+
when '200'
|
182
|
+
output.puts response.body.force_encoding("UTF-8")
|
183
|
+
else
|
184
|
+
say "ERROR: Unexpected error with status #{response.code} reading the content from the channel with url #{from}." , :red
|
185
|
+
raise Thor::Error
|
186
|
+
end
|
156
187
|
output.rewind
|
157
188
|
content = output.read
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
189
|
+
end
|
190
|
+
|
191
|
+
def resource_exist?(target)
|
192
|
+
uri = URI(target)
|
193
|
+
response = Net::HTTP.new(uri.host, uri.port).head(uri.path)
|
194
|
+
response.code == '200'
|
163
195
|
end
|
164
196
|
end
|
165
197
|
end
|
@@ -6,6 +6,12 @@ require "generators/ember/view_generator"
|
|
6
6
|
module Rails
|
7
7
|
module Generators
|
8
8
|
ResourceGenerator.class_eval do
|
9
|
+
|
10
|
+
class_option :javascript_engine, :desc => "Engine for JavaScripts"
|
11
|
+
class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
|
12
|
+
class_option :with_template, :type => :boolean, :default => false, :desc => "Create template for this view"
|
13
|
+
class_option :app_name, :type => :string, :aliases => "-n", :default => false, :desc => "Custom ember app name"
|
14
|
+
|
9
15
|
def add_ember
|
10
16
|
say_status :invoke, "ember:model", :white
|
11
17
|
with_padding do
|
@@ -14,7 +20,7 @@ module Rails
|
|
14
20
|
|
15
21
|
say_status :invoke, "ember controller and view (singular)", :white
|
16
22
|
with_padding do
|
17
|
-
invoke "ember:view", [singular_name], :object => true
|
23
|
+
invoke "ember:view", [singular_name], options.merge(:object => true)
|
18
24
|
end
|
19
25
|
|
20
26
|
@_invocations[Ember::Generators::ControllerGenerator].delete "create_controller_files"
|
@@ -22,7 +28,7 @@ module Rails
|
|
22
28
|
|
23
29
|
say_status :invoke, "ember controller and view (plural)", :white
|
24
30
|
with_padding do
|
25
|
-
invoke "ember:view", [plural_name], :array => true
|
31
|
+
invoke "ember:view", [plural_name], options.merge(:array => true)
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -14,8 +14,8 @@ module Ember
|
|
14
14
|
|
15
15
|
|
16
16
|
def create_template_files
|
17
|
-
file_path = File.join(ember_path, 'templates', class_path, "#{file_name}.
|
18
|
-
template 'template.
|
17
|
+
file_path = File.join(ember_path, 'templates', class_path, "#{file_name}.hbs")
|
18
|
+
template 'template.hbs', file_path
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
//=
|
1
|
+
//= require_tree ./adapters
|
2
2
|
//= require_tree ./mixins
|
3
3
|
//= require_tree ./models
|
4
4
|
//= require_tree ./controllers
|
@@ -6,6 +6,6 @@
|
|
6
6
|
//= require_tree ./helpers
|
7
7
|
//= require_tree ./components
|
8
8
|
//= require_tree ./templates
|
9
|
-
//= require ./router
|
10
9
|
//= require_tree ./routes
|
10
|
+
//= require ./router
|
11
11
|
//= require_self
|
@@ -1,8 +1,10 @@
|
|
1
|
-
#=
|
1
|
+
#= require_tree ./adapters
|
2
|
+
#= require_tree ./mixins
|
2
3
|
#= require_tree ./models
|
3
4
|
#= require_tree ./controllers
|
4
5
|
#= require_tree ./views
|
5
6
|
#= require_tree ./helpers
|
7
|
+
#= require_tree ./components
|
6
8
|
#= require_tree ./templates
|
7
9
|
#= require_tree ./routes
|
8
10
|
#= require ./router
|
File without changes
|
@@ -1,9 +1,10 @@
|
|
1
1
|
//= require jquery
|
2
|
-
//= require
|
2
|
+
//= require jquery_ujs
|
3
|
+
<%= "//= require handlebars\n" if ::Rails.configuration.handlebars.ember_template == 'Handlebars' -%>
|
3
4
|
//= require ember
|
4
5
|
//= require ember-data
|
5
6
|
//= require_self
|
6
|
-
//= require
|
7
|
+
//= require ./<%= application_name.underscore %>
|
7
8
|
|
8
9
|
// for more details see: http://emberjs.com/guides/application/
|
9
10
|
<%= application_name.camelize %> = Ember.Application.create();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// for more details see: http://emberjs.com/guides/controllers/
|
1
|
+
// for more details see: http://emberjs.com/guides/controllers/representing-multiple-models-with-arraycontroller/
|
2
2
|
|
3
3
|
<%= application_name.camelize %>.<%= class_name %>Controller = Ember.ArrayController.extend({
|
4
4
|
|
File without changes
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<% attributes.each_with_index do |attribute, idx| -%>
|
5
5
|
<%= attribute[:name].camelize(:lower) %>: <%=
|
6
6
|
if %w(references belongs_to).member?(attribute[:type])
|
7
|
-
"DS.belongsTo('%s
|
7
|
+
"DS.belongsTo('%s')" % attribute[:name].camelize(:lower)
|
8
8
|
else
|
9
9
|
"DS.attr('%s')" % attribute[:type]
|
10
10
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<% attributes.each do |attribute| -%>
|
5
5
|
<%= attribute[:name].camelize(:lower) %>: <%=
|
6
6
|
if %w(references belongs_to).member?(attribute[:type])
|
7
|
-
"DS.belongsTo '%s
|
7
|
+
"DS.belongsTo '%s'" % attribute[:name].camelize(:lower)
|
8
8
|
else
|
9
9
|
"DS.attr '%s'" % attribute[:type]
|
10
10
|
end
|
@@ -4,7 +4,7 @@ class <%= application_name.camelize %>.<%= class_name %> extends DS.Model
|
|
4
4
|
<% attributes.each do |attribute| -%>
|
5
5
|
<%= attribute[:name].camelize(:lower) %>: <%=
|
6
6
|
if %w(references belongs_to).member?(attribute[:type])
|
7
|
-
"DS.belongsTo '%s
|
7
|
+
"DS.belongsTo '%s'" % attribute[:name].camelize(:lower)
|
8
8
|
else
|
9
9
|
"DS.attr '%s'" % attribute[:type]
|
10
10
|
end
|