ember-rails 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/ember/handlebars/assets/ember-precompiler.js +13 -12
- data/lib/ember/handlebars/source.rb +8 -2
- data/lib/ember/handlebars/version.rb +1 -1
- data/lib/ember/rails/engine.rb +10 -2
- data/lib/ember/rails/version.rb +1 -1
- data/lib/ember/version.rb +1 -1
- data/lib/ember_rails.rb +29 -25
- data/lib/generators/ember/bootstrap_generator.rb +28 -3
- data/lib/generators/ember/install_generator.rb +3 -37
- data/lib/generators/ember/model_generator.rb +8 -8
- data/lib/generators/ember/resource_override.rb +32 -0
- data/lib/generators/ember/view_generator.rb +8 -7
- data/lib/generators/templates/app.js +6 -8
- data/lib/generators/templates/application.handlebars +3 -0
- data/lib/generators/templates/array_controller.js +1 -1
- data/lib/generators/templates/controller.js +1 -1
- data/lib/generators/templates/router.js +15 -0
- data/lib/generators/templates/store.js +5 -0
- data/lib/generators/templates/view.handlebars +3 -1
- data/lib/generators/templates/view.js +2 -3
- data/vendor/ember/development/ember-data.js +6 -4
- data/vendor/ember/development/handlebars-runtime.js +229 -0
- data/vendor/ember/development/handlebars.js +1895 -0
- data/vendor/ember/production/ember-data.js +7 -3741
- data/vendor/ember/production/handlebars-runtime.js +2 -0
- data/vendor/ember/production/handlebars.js +2 -0
- metadata +12 -5
- data/lib/generators/templates/states.js +0 -18
data/README.md
CHANGED
@@ -52,7 +52,7 @@ file to setup application namespace and initial requires:
|
|
52
52
|
create app/assets/javascripts/helpers/.gitkeep
|
53
53
|
create app/assets/javascripts/templates
|
54
54
|
create app/assets/javascripts/templates/.gitkeep
|
55
|
-
create app/assets/javascripts/app.js
|
55
|
+
create app/assets/javascripts/app.js
|
56
56
|
|
57
57
|
If you want to avoid `.gitkeep` files, use the `skip git` option like
|
58
58
|
this: `rails g ember:bootstrap -g`.
|
@@ -1,22 +1,23 @@
|
|
1
1
|
// DOM
|
2
|
-
var Element = {}
|
3
|
-
Element.firstChild = function () { return Element };
|
4
|
-
Element.innerHTML = function () { return Element };
|
2
|
+
var Element = {};
|
3
|
+
Element.firstChild = function () { return Element; };
|
4
|
+
Element.innerHTML = function () { return Element; };
|
5
5
|
|
6
|
-
var document = { createRange: false, createElement: function() { return Element } };
|
6
|
+
var document = { createRange: false, createElement: function() { return Element; } };
|
7
7
|
var window = this;
|
8
8
|
this.document = document;
|
9
9
|
|
10
|
-
//
|
11
|
-
|
12
|
-
|
10
|
+
// null out console.log and console.warn to avoid unexpected output
|
11
|
+
if (window.console) {
|
12
|
+
window.console.warn = function() {};
|
13
|
+
window.console.log = function() {};
|
14
|
+
}
|
13
15
|
|
14
|
-
|
15
|
-
var jQuery = window.jQuery = function() { return jQuery };
|
16
|
-
jQuery.ready = function() { return jQuery };
|
17
|
-
jQuery.inArray = function() { return jQuery };
|
16
|
+
//// jQuery
|
17
|
+
var jQuery = window.jQuery = function() { return jQuery; };
|
18
|
+
jQuery.ready = function() { return jQuery; };
|
19
|
+
jQuery.inArray = function() { return jQuery; };
|
18
20
|
jQuery.jquery = "1.7.2";
|
19
|
-
var $ = jQuery;
|
20
21
|
|
21
22
|
// Precompiler
|
22
23
|
var EmberRails = {
|
@@ -21,7 +21,14 @@ module Ember
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def contents
|
24
|
-
@contents ||=
|
24
|
+
@contents ||= begin
|
25
|
+
config = ::Rails.application.config.ember
|
26
|
+
handlebars = File.read(config.handlebars_location)
|
27
|
+
ember = File.read(config.ember_location)
|
28
|
+
precompiler = File.read(precompiler_path)
|
29
|
+
|
30
|
+
[precompiler, handlebars, ember].join("\n")
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
34
|
def handlebars_version
|
@@ -40,7 +47,6 @@ module Ember
|
|
40
47
|
|
41
48
|
class << self
|
42
49
|
def compile(template)
|
43
|
-
template = template.read if template.respond_to?(:read)
|
44
50
|
Source.context.call('EmberRails.precompile', template)
|
45
51
|
end
|
46
52
|
end
|
data/lib/ember/rails/engine.rb
CHANGED
@@ -5,7 +5,8 @@ module Ember
|
|
5
5
|
module Rails
|
6
6
|
class Engine < ::Rails::Engine
|
7
7
|
config.handlebars = ActiveSupport::OrderedOptions.new
|
8
|
-
|
8
|
+
|
9
|
+
config.handlebars.precompile = true
|
9
10
|
config.handlebars.templates_root = "templates"
|
10
11
|
config.handlebars.templates_path_separator = '/'
|
11
12
|
|
@@ -18,7 +19,14 @@ module Ember
|
|
18
19
|
app.assets.register_engine '.hjs', Ember::Handlebars::Template
|
19
20
|
|
20
21
|
# Add the gem's vendored ember to the end of the asset search path
|
21
|
-
app.config.
|
22
|
+
variant = app.config.ember.variant
|
23
|
+
|
24
|
+
if variant.nil?
|
25
|
+
warn "[EMBER-RAILS] `ember.variant` was not found in your current environment"
|
26
|
+
end
|
27
|
+
|
28
|
+
ember_path = File.expand_path("../../../../vendor/ember/#{variant}", __FILE__)
|
29
|
+
app.config.assets.paths.unshift ember_path
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
data/lib/ember/rails/version.rb
CHANGED
data/lib/ember/version.rb
CHANGED
data/lib/ember_rails.rb
CHANGED
@@ -5,33 +5,37 @@ require 'ember/rails/engine'
|
|
5
5
|
|
6
6
|
module Ember
|
7
7
|
module Rails
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
8
|
+
class Railtie < ::Rails::Railtie
|
9
|
+
config.ember = ActiveSupport::OrderedOptions.new
|
10
|
+
|
11
|
+
generators do |app|
|
12
|
+
app ||= ::Rails.application # Rails 3.0.x does not yield `app`
|
13
|
+
|
14
|
+
app.config.generators.assets = false
|
15
|
+
|
16
|
+
::Rails::Generators.configure!(app.config.generators)
|
17
|
+
::Rails::Generators.hidden_namespaces.uniq!
|
18
|
+
require "generators/ember/resource_override"
|
19
|
+
end
|
20
|
+
|
21
|
+
initializer "ember_rails.setup_vendor", :after => "ember_rails.setup", :group => :all do |app|
|
22
|
+
# Add the gem's vendored ember to the end of the asset search path
|
23
|
+
variant = app.config.ember.variant
|
24
|
+
ember_path = app.root.join("vendor/assets/ember/#{variant}")
|
25
|
+
app.config.assets.paths.unshift(ember_path.to_s) if ember_path.exist?
|
26
|
+
end
|
27
|
+
|
28
|
+
initializer "ember_rails.find_ember", :after => "ember_rails.setup_vendor", :group => :all do |app|
|
29
|
+
config.ember.ember_location = location_for(app, "ember.js")
|
30
|
+
config.ember.handlebars_location = location_for(app, "handlebars.js")
|
31
|
+
end
|
32
|
+
|
33
|
+
def location_for(app, file)
|
34
|
+
path = app.config.assets.paths.find do |dir|
|
35
|
+
Pathname.new(dir).join(file).exist?
|
32
36
|
end
|
33
37
|
|
34
|
-
|
38
|
+
File.join(path, file) if path
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -16,6 +16,9 @@ module Ember
|
|
16
16
|
|
17
17
|
inject_into_file(application_file, :before => "//= require_tree") do
|
18
18
|
dependencies = [
|
19
|
+
# this should eventually become handlebars-runtime when we remove
|
20
|
+
# the runtime dependency on compilation
|
21
|
+
"//= require handlebars",
|
19
22
|
"//= require ember",
|
20
23
|
"//= require ember-data",
|
21
24
|
"//= require_self",
|
@@ -27,7 +30,7 @@ module Ember
|
|
27
30
|
end
|
28
31
|
|
29
32
|
def create_dir_layout
|
30
|
-
%W{models controllers views
|
33
|
+
%W{models controllers views routes helpers templates}.each do |dir|
|
31
34
|
empty_directory "#{ember_path}/#{dir}"
|
32
35
|
create_file "#{ember_path}/#{dir}/.gitkeep" unless options[:skip_git]
|
33
36
|
end
|
@@ -37,8 +40,30 @@ module Ember
|
|
37
40
|
template "app.js", "#{ember_path}/#{application_name.underscore}.js"
|
38
41
|
end
|
39
42
|
|
40
|
-
def
|
41
|
-
template "
|
43
|
+
def create_router_file
|
44
|
+
template "router.js", "#{ember_path}/routes/app_router.js"
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_store_file
|
48
|
+
template "store.js", "#{ember_path}/store.js"
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_app_stubs
|
52
|
+
generate "ember:view", "application"
|
53
|
+
end
|
54
|
+
|
55
|
+
def inject_proper_ember_version
|
56
|
+
environment <<-RUBY.strip_heredoc, :env => :development
|
57
|
+
config.ember.variant = :development
|
58
|
+
RUBY
|
59
|
+
|
60
|
+
environment <<-RUBY.strip_heredoc, :env => :test
|
61
|
+
config.ember.variant = :development
|
62
|
+
RUBY
|
63
|
+
|
64
|
+
environment <<-RUBY.strip_heredoc, :env => :production
|
65
|
+
config.ember.variant = :production
|
66
|
+
RUBY
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
@@ -3,21 +3,8 @@ require 'ember/version'
|
|
3
3
|
module Ember
|
4
4
|
module Generators
|
5
5
|
class InstallGenerator < ::Rails::Generators::Base
|
6
|
-
|
7
|
-
EMBER_FILES = [ "ember.js", "ember-dev.js" ]
|
8
|
-
RUNTIME_FILES = [ "ember-runtime.js", "ember-runtime-dev.js" ]
|
9
|
-
ALL_FILES = [ *EMBER_FILES, *RUNTIME_FILES ]
|
10
|
-
|
11
6
|
desc "Install Ember.js into your vendor folder"
|
12
7
|
class_option :head, :type => :boolean, :default => false, :desc => "Download latest Ember.js from GitHub and copy it into your project"
|
13
|
-
class_option :runtime, :type => :boolean, :default => false, :desc => "Include the Ember.js runtime only"
|
14
|
-
|
15
|
-
def remove_ember
|
16
|
-
ALL_FILES.each do |name|
|
17
|
-
file = "vendor/assets/javascripts/#{name}"
|
18
|
-
remove_file file if File.exist?(file)
|
19
|
-
end
|
20
|
-
end
|
21
8
|
|
22
9
|
def copy_ember
|
23
10
|
if options.head?
|
@@ -33,7 +20,7 @@ module Ember
|
|
33
20
|
cmd command
|
34
21
|
else
|
35
22
|
Dir.chdir git_root do
|
36
|
-
command = "git fetch --force --quiet --tags && git reset
|
23
|
+
command = "git fetch --force --quiet --tags && git reset origin/master --hard"
|
37
24
|
say_status("updating", command, :green)
|
38
25
|
|
39
26
|
cmd command
|
@@ -50,34 +37,13 @@ module Ember
|
|
50
37
|
|
51
38
|
self.class.source_root File.join(git_root, "dist")
|
52
39
|
|
53
|
-
|
54
|
-
|
55
|
-
name.gsub /-dev/, '.debug'
|
56
|
-
else
|
57
|
-
name.gsub /.js/, '.prod.js'
|
58
|
-
end
|
59
|
-
|
60
|
-
copy_file source_file, "vendor/assets/javascripts/#{name}"
|
61
|
-
end
|
62
|
-
|
63
|
-
else
|
64
|
-
|
65
|
-
self.class.source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
|
66
|
-
say_status("copying", "Ember.js (#{Ember::VERSION})", :green)
|
67
|
-
|
68
|
-
ember_files.each do |name|
|
69
|
-
copy_file name, "vendor/assets/javascripts/#{name}"
|
70
|
-
end
|
71
|
-
|
40
|
+
copy_file "ember.js", "vendor/assets/ember/development/ember.js"
|
41
|
+
copy_file "ember.min.js", "vendor/assets/ember/production/ember.js"
|
72
42
|
end
|
73
43
|
end
|
74
44
|
|
75
45
|
private
|
76
46
|
|
77
|
-
def ember_files
|
78
|
-
options.runtime? ? RUNTIME_FILES : EMBER_FILES
|
79
|
-
end
|
80
|
-
|
81
47
|
def cmd(command)
|
82
48
|
out = `#{command}`
|
83
49
|
|
@@ -5,22 +5,22 @@ module Ember
|
|
5
5
|
class ModelGenerator < ::Rails::Generators::NamedBase
|
6
6
|
source_root File.expand_path("../../templates", __FILE__)
|
7
7
|
argument :attributes, :type => :array, :default => [], :banner => "field[:type] field[:type] ..."
|
8
|
-
|
8
|
+
|
9
9
|
desc "Creates a new Ember.js model"
|
10
|
-
|
10
|
+
|
11
11
|
def create_model_files
|
12
12
|
template 'model.js', File.join('app/assets/javascripts/models', class_path, "#{file_name}.js")
|
13
13
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
17
|
def parse_attributes!
|
18
18
|
self.attributes = (attributes || []).map do |attr|
|
19
|
-
|
20
|
-
|
19
|
+
name, type = attr.split(':')
|
20
|
+
type = 'string' if type == 'text'
|
21
|
+
{ name: name, type: type }
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "rails/generators/rails/resource/resource_generator"
|
3
|
+
require "generators/ember/controller_generator"
|
4
|
+
require "generators/ember/view_generator"
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module Generators
|
8
|
+
ResourceGenerator.class_eval do
|
9
|
+
def add_ember
|
10
|
+
say_status :invoke, "ember:model", :white
|
11
|
+
with_padding do
|
12
|
+
invoke "ember:model"
|
13
|
+
end
|
14
|
+
|
15
|
+
say_status :invoke, "ember controller and view (singular)", :white
|
16
|
+
with_padding do
|
17
|
+
invoke "ember:view"
|
18
|
+
end
|
19
|
+
|
20
|
+
@_invocations[Ember::Generators::ControllerGenerator].delete "create_controller_files"
|
21
|
+
@_invocations[Ember::Generators::ViewGenerator].delete "create_view_files"
|
22
|
+
|
23
|
+
say_status :invoke, "ember controller and view (plural)", :white
|
24
|
+
with_padding do
|
25
|
+
invoke "ember:view", [plural_name], :array => true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
@@ -4,15 +4,16 @@ module Ember
|
|
4
4
|
module Generators
|
5
5
|
class ViewGenerator < ::Rails::Generators::NamedBase
|
6
6
|
source_root File.expand_path("../../templates", __FILE__)
|
7
|
-
|
8
|
-
|
7
|
+
|
9
8
|
desc "Creates a new Ember.js view and associated Handlebars template"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
template 'view.
|
9
|
+
class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
|
10
|
+
|
11
|
+
def create_view_files
|
12
|
+
template 'view.js', File.join('app/assets/javascripts/views', class_path, "#{file_name}_view.js")
|
13
|
+
template 'view.handlebars', File.join('app/assets/javascripts/templates', class_path, "#{file_name}.handlebars")
|
14
|
+
invoke('ember:controller', [ file_name ], options)
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -1,17 +1,15 @@
|
|
1
|
+
//= require ./store
|
1
2
|
//= require_tree ./models
|
2
3
|
//= require_tree ./controllers
|
3
4
|
//= require_tree ./views
|
4
5
|
//= require_tree ./helpers
|
5
6
|
//= require_tree ./templates
|
6
|
-
//= require_tree ./
|
7
|
+
//= require_tree ./routes
|
7
8
|
//= require_self
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
var stateManager = <%= application_name.camelize %>.stateManager = <%= application_name.camelize %>.StateManager.create();
|
12
|
-
<%= application_name.camelize %>.initialize(stateManager);
|
13
|
-
|
14
|
-
jQuery(function() {
|
15
|
-
stateManager.send('ready');
|
10
|
+
var router = <%= application_name.camelize %>.router = <%= application_name.camelize %>.Router.create({
|
11
|
+
location: 'hash'
|
16
12
|
});
|
17
13
|
|
14
|
+
<%= application_name.camelize %>.initialize(router);
|
15
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= application_name.camelize %>.Router = Ember.Router.extend({
|
2
|
+
root: Ember.State.extend({
|
3
|
+
index: Ember.State.extend({
|
4
|
+
route: '/'
|
5
|
+
|
6
|
+
// You'll likely want to connect a view here.
|
7
|
+
// connectOutlets: function(router) {
|
8
|
+
// router.get('applicationController').connectOutlet(App.MainView);
|
9
|
+
// }
|
10
|
+
|
11
|
+
// Layout your routes here...
|
12
|
+
})
|
13
|
+
})
|
14
|
+
});
|
15
|
+
|