ember-rails 0.13.0 → 0.18.5
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/README.md +209 -46
- data/lib/ember/rails/engine.rb +11 -7
- data/lib/ember/rails/version.rb +1 -1
- data/lib/ember_rails.rb +64 -30
- data/lib/generators/ember/adapter_generator.rb +21 -0
- data/lib/generators/ember/bootstrap_generator.rb +29 -9
- data/lib/generators/ember/component_generator.rb +28 -0
- data/lib/generators/ember/controller_generator.rb +1 -1
- data/lib/generators/ember/generator_helpers.rb +28 -3
- data/lib/generators/ember/install_generator.rb +165 -13
- data/lib/generators/ember/resource_generator.rb +1 -1
- data/lib/generators/ember/resource_override.rb +8 -2
- data/lib/generators/ember/template_generator.rb +4 -1
- 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 +4 -2
- data/lib/generators/templates/app.js.coffee +3 -1
- data/lib/generators/templates/app.js.em +11 -0
- data/lib/generators/templates/{application.handlebars → application.hbs} +0 -0
- data/lib/generators/templates/application.js +4 -2
- data/lib/generators/templates/application.js.coffee +3 -1
- 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 +1 -1
- 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.em +3 -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 +12 -0
- data/lib/generators/templates/object_controller.js +1 -1
- data/lib/generators/templates/object_controller.js.coffee +1 -1
- data/lib/generators/templates/object_controller.js.em +3 -0
- data/lib/generators/templates/route.js.em +3 -0
- data/lib/generators/templates/router.js.em +5 -0
- data/lib/generators/templates/{template.handlebars → template.hbs} +0 -0
- data/lib/generators/templates/view.js.em +4 -0
- metadata +141 -94
- data/lib/ember/handlebars/template.rb +0 -102
- data/lib/generators/templates/store.js +0 -6
- data/lib/generators/templates/store.js.coffee +0 -6
@@ -3,12 +3,32 @@ module Ember
|
|
3
3
|
module GeneratorHelpers
|
4
4
|
|
5
5
|
def ember_path
|
6
|
-
options[:ember_path]
|
6
|
+
if options[:ember_path]
|
7
|
+
options[:ember_path]
|
8
|
+
elsif rails_engine?
|
9
|
+
"app/assets/javascripts/#{engine_name}"
|
10
|
+
elsif configuration.ember_path
|
11
|
+
configuration.ember_path
|
12
|
+
else
|
13
|
+
"app/assets/javascripts"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def rails_engine?
|
18
|
+
defined?(ENGINE_PATH)
|
19
|
+
end
|
20
|
+
|
21
|
+
def engine_name
|
22
|
+
ENGINE_PATH.split('/')[-2]
|
7
23
|
end
|
8
24
|
|
9
25
|
def application_name
|
10
26
|
if options[:app_name]
|
11
27
|
options[:app_name]
|
28
|
+
elsif rails_engine?
|
29
|
+
engine_name
|
30
|
+
elsif configuration.app_name
|
31
|
+
configuration.app_name
|
12
32
|
elsif defined?(::Rails) && ::Rails.application
|
13
33
|
::Rails.application.class.name.split('::').first
|
14
34
|
else
|
@@ -16,18 +36,23 @@ module Ember
|
|
16
36
|
end
|
17
37
|
end
|
18
38
|
|
19
|
-
|
20
39
|
def class_name
|
21
40
|
(class_path + [file_name]).map!{ |m| m.camelize }.join()
|
22
41
|
end
|
23
42
|
|
24
43
|
def handlebars_template_path
|
25
|
-
File.join(class_path, file_name).gsub(/^\//, '')
|
44
|
+
File.join(class_path, file_name).gsub(/^\//, '')
|
26
45
|
end
|
27
46
|
|
28
47
|
def engine_extension
|
29
48
|
@engine_extension ||= "js.#{options[:javascript_engine]}".sub('js.js','js')
|
30
49
|
end
|
50
|
+
|
51
|
+
def configuration
|
52
|
+
if defined?(::Rails) && ::Rails.configuration
|
53
|
+
::Rails.configuration.ember
|
54
|
+
end
|
55
|
+
end
|
31
56
|
end
|
32
57
|
end
|
33
58
|
end
|
@@ -6,36 +6,188 @@ require 'fileutils'
|
|
6
6
|
module Ember
|
7
7
|
module Generators
|
8
8
|
class InstallGenerator < ::Rails::Generators::Base
|
9
|
+
|
10
|
+
class InvalidChannel < ::Thor::Error; end
|
11
|
+
class ConflictingOptions < ::Thor::Error; end
|
12
|
+
class InsufficientOptions < ::Thor::Error; end
|
13
|
+
|
14
|
+
::InvalidChannel = InvalidChannel
|
15
|
+
::ConflictingOptions = ConflictingOptions
|
16
|
+
::InsufficientOptions = InsufficientOptions
|
17
|
+
|
9
18
|
desc "Install Ember.js into your vendor folder"
|
10
|
-
class_option :head,
|
19
|
+
class_option :head,
|
20
|
+
:type => :boolean,
|
21
|
+
:default => false,
|
22
|
+
:desc => "Download Ember.js & Ember data from canary channel. This is deprecated. Use channel instead."
|
23
|
+
class_option :channel,
|
24
|
+
:type => :string,
|
25
|
+
:required => false,
|
26
|
+
:desc => "Ember release channel Choose between 'release', 'beta' or 'canary'"
|
27
|
+
class_option :ember_only,
|
28
|
+
:type => :boolean,
|
29
|
+
:required => false,
|
30
|
+
:desc => "Only download Ember.",
|
31
|
+
:aliases => '--ember'
|
32
|
+
class_option :ember_data_only,
|
33
|
+
:type => :boolean,
|
34
|
+
:required => false,
|
35
|
+
:desc => "Only download ember-data",
|
36
|
+
:aliases => '--ember-data'
|
37
|
+
class_option :tag,
|
38
|
+
:type => :string,
|
39
|
+
:required => false,
|
40
|
+
:desc => "Download tagged release use syntax v1.0.0-beta.3/ember-data & v1.0.0-rc.8/ember"
|
41
|
+
|
42
|
+
def initialize(args = [], options = {}, config = {})
|
43
|
+
super(args, options, config)
|
44
|
+
check_options
|
45
|
+
process_options
|
46
|
+
end
|
47
|
+
|
48
|
+
def ember
|
49
|
+
begin
|
50
|
+
unless options.ember_data_only?
|
51
|
+
get_ember_js_for(:development)
|
52
|
+
get_ember_js_for(:production)
|
53
|
+
end
|
54
|
+
rescue Thor::Error
|
55
|
+
say('WARNING: no ember files on this channel or tag' , :yellow)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def ember_data
|
60
|
+
begin
|
61
|
+
unless options.ember_only?
|
62
|
+
get_ember_data_for(:development)
|
63
|
+
get_ember_data_for(:production)
|
64
|
+
end
|
65
|
+
rescue Thor::Error
|
66
|
+
say('WARNING: no ember-data files on this channel or tag' , :yellow)
|
67
|
+
end
|
68
|
+
end
|
11
69
|
|
12
|
-
|
70
|
+
private
|
71
|
+
|
72
|
+
def get_ember_data_for(environment)
|
73
|
+
|
74
|
+
create_file "vendor/assets/ember/#{environment}/ember-data.js" do
|
75
|
+
fetch url_for(channel, 'ember-data', environment), "vendor/assets/ember/#{environment}/ember-data.js"
|
76
|
+
end
|
77
|
+
|
78
|
+
sourcemap_url = "#{base_url}/#{channel}/ember-data.js.map"
|
79
|
+
if resource_exist?(sourcemap_url)
|
80
|
+
create_file "vendor/assets/ember/#{environment}/ember-data.js.map" do
|
81
|
+
fetch sourcemap_url, "vendor/assets/ember/#{environment}/ember-data.js.map", false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_ember_js_for(environment)
|
87
|
+
create_file "vendor/assets/ember/#{environment}/ember.js" do
|
88
|
+
fetch url_for(channel, 'ember', environment), "vendor/assets/ember/#{environment}/ember.js"
|
89
|
+
end
|
90
|
+
|
91
|
+
compiler_url = "#{base_url}/#{channel}/ember-template-compiler.js"
|
92
|
+
if resource_exist?(compiler_url)
|
93
|
+
create_file "vendor/assets/ember/#{environment}/ember-template-compiler.js" do
|
94
|
+
fetch "#{base_url}/#{channel}/ember-template-compiler.js", "vendor/assets/ember/#{environment}/ember-template-compiler.js"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def url_for(channel, component, environment)
|
100
|
+
base = "#{base_url}/#{channel}/#{component}"
|
101
|
+
|
102
|
+
case environment
|
103
|
+
when :production
|
104
|
+
"#{base}.min.js"
|
105
|
+
when :development
|
106
|
+
if resource_exist?("#{base}.debug.js")
|
107
|
+
"#{base}.debug.js" # Ember.js 1.10.0.beta.1 or later
|
108
|
+
else
|
109
|
+
"#{base}.js"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def check_options
|
13
115
|
if options.head?
|
14
|
-
|
15
|
-
|
116
|
+
say('WARNING: --head option is deprecated in favor of --channel=canary' , :yellow)
|
117
|
+
end
|
118
|
+
if options.head? && options.channel?
|
119
|
+
say 'ERROR: conflicting options. --head and --channel. Use either --head or --channel=<channel>', :red
|
120
|
+
raise ConflictingOptions
|
121
|
+
end
|
122
|
+
if options.channel? && !%w(release beta canary).include?(options[:channel])
|
123
|
+
say 'ERROR: channel can either be release, beta or canary', :red
|
124
|
+
raise InvalidChannel
|
125
|
+
end
|
126
|
+
if options.channel? && options.tag?
|
127
|
+
say 'ERROR: conflicting options. --tag and --channel. --tag is incompatible with other options', :red
|
128
|
+
raise ConflictingOptions
|
129
|
+
end
|
130
|
+
if options.head? && options.tag?
|
131
|
+
say 'ERROR: conflicting options. --tag and --head. --tag is incompatible with other options', :red
|
132
|
+
raise ConflictingOptions
|
133
|
+
end
|
134
|
+
if options.tag? && !(options.ember_only? || options.ember_data_only?)
|
135
|
+
say 'ERROR: insufficient options. --tag needs to be combined with eithe --ember or --ember-data', :red
|
136
|
+
raise InsufficientOptions
|
16
137
|
end
|
17
138
|
end
|
18
139
|
|
19
|
-
def
|
140
|
+
def process_options
|
20
141
|
if options.head?
|
21
|
-
|
22
|
-
|
142
|
+
@channel = :canary
|
143
|
+
end
|
144
|
+
if options.tag?
|
145
|
+
@channel = "tags/#{options.tag}"
|
23
146
|
end
|
24
147
|
end
|
25
148
|
|
26
|
-
|
149
|
+
def base_url
|
150
|
+
'http://builds.emberjs.com'
|
151
|
+
end
|
152
|
+
|
153
|
+
def channel
|
154
|
+
if options.channel
|
155
|
+
@channel ||= options[:channel]
|
156
|
+
else
|
157
|
+
@channel ||= :release
|
158
|
+
end
|
159
|
+
end
|
27
160
|
|
28
|
-
def fetch(from, to)
|
161
|
+
def fetch(from, to, prepend_verbose = true)
|
29
162
|
message = "#{from} -> #{to}"
|
30
163
|
say_status("downloading:", message , :green)
|
31
164
|
|
32
165
|
uri = URI(from)
|
166
|
+
output = StringIO.new
|
167
|
+
if prepend_verbose
|
168
|
+
output.puts "// Fetched from channel: #{channel}, with url " + uri.to_s
|
169
|
+
output.puts "// Fetched on: " + Time.now.utc.iso8601.to_s
|
170
|
+
end
|
33
171
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
172
|
+
response = Net::HTTP.get_response(uri)
|
173
|
+
case response.code
|
174
|
+
when '404'
|
175
|
+
say "ERROR: Error reading the content from the channel with url #{from}. File not found" , :red
|
176
|
+
raise Thor::Error
|
177
|
+
when '200'
|
178
|
+
output.puts response.body.force_encoding("UTF-8")
|
179
|
+
else
|
180
|
+
say "ERROR: Unexpected error with status #{response.code} reading the content from the channel with url #{from}." , :red
|
181
|
+
raise Thor::Error
|
38
182
|
end
|
183
|
+
output.rewind
|
184
|
+
content = output.read
|
185
|
+
end
|
186
|
+
|
187
|
+
def resource_exist?(target)
|
188
|
+
uri = URI(target)
|
189
|
+
response = Net::HTTP.new(uri.host, uri.port).head(uri.path)
|
190
|
+
response.code == '200'
|
39
191
|
end
|
40
192
|
end
|
41
193
|
end
|
@@ -12,7 +12,7 @@ module Ember
|
|
12
12
|
class_option :javascript_engine, :desc => "Engine for JavaScripts"
|
13
13
|
class_option :skip_route, :type => :boolean, :default => false, :desc => "Don't create route"
|
14
14
|
class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
|
15
|
-
class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.
|
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
|
|
@@ -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
|
@@ -9,10 +9,13 @@ module Ember
|
|
9
9
|
|
10
10
|
desc "Creates a new Ember.js template"
|
11
11
|
class_option :javascript_engine, :desc => "Engine for JavaScripts"
|
12
|
+
class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
|
13
|
+
|
12
14
|
|
13
15
|
|
14
16
|
def create_template_files
|
15
|
-
|
17
|
+
file_path = File.join(ember_path, 'templates', class_path, "#{file_name}.hbs")
|
18
|
+
template 'template.hbs', file_path
|
16
19
|
end
|
17
20
|
|
18
21
|
end
|
@@ -1,9 +1,11 @@
|
|
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
|
-
//= require ./router
|
8
9
|
//= require_tree ./routes
|
10
|
+
//= require ./router
|
9
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
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#= require_tree ./adapters
|
2
|
+
#= require_tree ./mixins
|
3
|
+
#= require_tree ./models
|
4
|
+
#= require_tree ./controllers
|
5
|
+
#= require_tree ./views
|
6
|
+
#= require_tree ./helpers
|
7
|
+
#= require_tree ./components
|
8
|
+
#= require_tree ./templates
|
9
|
+
#= require_tree ./routes
|
10
|
+
#= require ./router
|
11
|
+
#= require_self
|
File without changes
|
@@ -1,8 +1,10 @@
|
|
1
|
-
//= require
|
1
|
+
//= require jquery
|
2
|
+
//= require jquery_ujs
|
3
|
+
<%= "//= require handlebars\n" if ::Rails.configuration.handlebars.ember_template == 'Handlebars' -%>
|
2
4
|
//= require ember
|
3
5
|
//= require ember-data
|
4
6
|
//= require_self
|
5
|
-
//= require
|
7
|
+
//= require ./<%= application_name.underscore %>
|
6
8
|
|
7
9
|
// for more details see: http://emberjs.com/guides/application/
|
8
10
|
<%= application_name.camelize %> = Ember.Application.create();
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#= require jquery
|
2
|
+
#= require jquery_ujs
|
3
|
+
<%= "#= require handlebars\n" if ::Rails.configuration.handlebars.ember_template == 'Handlebars' -%>
|
4
|
+
#= require ember
|
5
|
+
#= require ember-data
|
6
|
+
#= require_self
|
7
|
+
#= require <%= application_name.underscore %>
|
8
|
+
|
9
|
+
# for more details see: http://emberjs.com/guides/application/
|
10
|
+
window.<%= 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
|
|
@@ -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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# for more details see: http://emberjs.com/guides/models/defining-models/
|
2
|
+
|
3
|
+
class <%= application_name.camelize %>.<%= class_name %> extends DS.Model
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
<%= attribute[:name].camelize(:lower) %>: <%=
|
6
|
+
if %w(references belongs_to).member?(attribute[:type])
|
7
|
+
"DS.belongsTo '%s'" % attribute[:name].camelize(:lower)
|
8
|
+
else
|
9
|
+
"DS.attr '%s'" % attribute[:type]
|
10
|
+
end
|
11
|
+
%>
|
12
|
+
<% end -%>
|
File without changes
|