ember-rails-lite 0.9.2 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,9 +12,7 @@ Add the gem to your application Gemfile:
12
12
 
13
13
  gem "ember-rails"
14
14
 
15
- Run `bundle install` and add the following line to `app/assets/javascripts/application.js`:
16
-
17
- //= require ember
15
+ Run `bundle install` and use the ember-rails generator to add the necessary dependencies.
18
16
 
19
17
  Ember-rails will use the production build of Ember.js when Rails is running in
20
18
  production mode, and the development build otherwise.
@@ -35,8 +33,12 @@ Additionally, it will add the following lines to `app/assets/javascripts/applica
35
33
  By default, it uses the Rails Application's name and creates an `rails_app_name.js`
36
34
  file to setup application namespace and initial requires:
37
35
 
36
+ //= require handlebars
38
37
  //= require ember
39
- //= require ember/app
38
+ //= require ember-data
39
+ //= require_self
40
+ //= require rails_app_name
41
+ RailsAppName = Ember.Application.create();
40
42
 
41
43
  *Example:*
42
44
 
@@ -64,26 +66,22 @@ and including the assets in your layout:
64
66
 
65
67
  <%= javascript_include_tag "templates/admin_panel" %>
66
68
 
67
- If you want to strip template root from template names, add `templates_root` option to your application configuration block :
68
-
69
- config.handlebars.templates_root = 'templates'
70
-
71
- The result will be like this :
69
+ If you want to strip template root from template names, add `templates_root` option to your application configuration block.
70
+ By default, `templates_root` is `'templates'`.
72
71
 
73
- Ember.TEMPLATES['admin_panel'] = "...";
72
+ config.handlebars.templates_root = 'ember_templates'
74
73
 
75
- If you want a different path separator in template names add `templates_path_separator` option to your application configuration block :
74
+ If you store templates in a file like `app/assets/javascripts/ember_templates/admin_panel.handlebars` after setting the above config,
75
+ it will be made available to Ember as the `admin_panel` template.
76
76
 
77
- config.handlebars.templates_path_separator = '-'
77
+ _(Note: you must clear the local sprockets cache after modifying `templates_root`, stored by default in `tmp/cache/assets`)_
78
78
 
79
- The result will be like this :
80
-
81
- Ember.TEMPLATES['templates-admin_panel'] = "...";
82
-
83
- Default behavior for ember-rails is to precompile handlebars templates only in production environment.
84
- If you don't want this behavior you can turn it off in your application configuration block :
79
+ Default behavior for ember-rails is to precompile handlebars templates.
80
+ 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:
85
81
 
86
82
  config.handlebars.precompile = false
83
+
84
+ _(Note: you must clear the local sprockets cache if you disable precompilation, stored by default in `tmp/cache/assets`)_
87
85
 
88
86
  Bundle all templates together thanks to Sprockets,
89
87
  e.g create `app/assets/javascripts/templates/all.js` with:
@@ -105,6 +103,33 @@ It will be translated as :
105
103
  {{#view Ember.Button}}OK{{/view}}
106
104
  </script>
107
105
 
106
+ ## Specifying Different Versions of Ember/Handlebars/Ember-Data
107
+
108
+ By default, ember-rails ships with the latest version of
109
+ [Ember](https://rubygems.org/gems/ember-source/versions) (rc1),
110
+ [Handlebars](https://rubygems.org/gems/handlebars-source/versions) (rc3),
111
+ and [Ember-Data](https://rubygems.org/gems/ember-data-source/versions).
112
+
113
+ To specify a different version that'll be used for both template
114
+ precompilation and serving to the browser, you can specify the desired
115
+ version of one of the above-linked gems in the Gemfile, e.g.:
116
+
117
+ gem 'ember-source', '1.0.0.pre4.2'
118
+
119
+ You can also specify versions of 'handlebars-source' and
120
+ 'ember-data-source', but note that an appropriate 'handlebars-source'
121
+ will be automatically chosen depending on the version of 'ember-source'
122
+ that's specified.
123
+
124
+ You can also override the specific ember.js, handlebars.js, and
125
+ ember-data.js files that'll be `require`d by the Asset pipeline by
126
+ placing these files in `vendor/assets/ember/development` and
127
+ `vendor/assets/ember/production`, depending on the `config.ember.variant`
128
+ you've specified in your app's configuration, e.g.:
129
+
130
+ config.ember.variant = :production
131
+ #config.ember.variant = :development
132
+
108
133
  ## Note on Patches/Pull Requests
109
134
 
110
135
  1. Fork the project.
@@ -0,0 +1 @@
1
+ require 'ember_rails'
@@ -77,11 +77,11 @@ module Ember
77
77
 
78
78
  if root.kind_of? Array
79
79
  root.each do |root|
80
- path.gsub!(/^#{Regexp.quote(root)}\//, '')
80
+ path.sub!(/#{Regexp.quote(root)}\//, '')
81
81
  end
82
82
  else
83
83
  unless root.empty?
84
- path.gsub!(/^#{Regexp.quote(root)}\/?/, '')
84
+ path.sub!(/#{Regexp.quote(root)}\/?/, '')
85
85
  end
86
86
  end
87
87
 
@@ -1,5 +1,5 @@
1
1
  module Ember
2
2
  module Handlebars
3
- VERSION = "1.0.rc.2"
3
+ VERSION = "1.0.rc.3"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Ember
2
2
  module Rails
3
- VERSION = '0.9.2'
3
+ VERSION = '0.11.1'
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Ember
2
- VERSION = "1.0.0-pre.4"
2
+ VERSION = "1.0.0-rc.1"
3
3
  end
@@ -1,8 +1,10 @@
1
1
  require 'rails'
2
2
  require 'ember/rails/version'
3
3
  require 'ember/version'
4
- require 'ember/handlebars/version'
5
4
  require 'ember/rails/engine'
5
+ require 'ember/source'
6
+ require 'ember/data/source'
7
+ require 'handlebars/source'
6
8
 
7
9
  module Ember
8
10
  module Rails
@@ -21,13 +23,23 @@ module Ember
21
23
 
22
24
  initializer "ember_rails.setup_vendor", :after => "ember_rails.setup", :group => :all do |app|
23
25
  if variant = app.config.ember.variant
24
- # Add the gem's vendored ember to the end of the asset search path
25
- ember_path = File.expand_path("../../vendor/ember/#{variant}", __FILE__)
26
- app.config.assets.paths.push(ember_path.to_s)
26
+ # Copy over the desired ember, ember-data, and handlebars bundled in
27
+ # ember-source, ember-data-source, and handlebars-source to a tmp folder.
28
+ tmp_path = app.root.join("tmp/ember-rails")
29
+ ext = variant == :production ? ".prod.js" : ".js"
30
+ FileUtils.mkdir_p(tmp_path)
31
+ FileUtils.cp(::Ember::Source.bundled_path_for("ember#{ext}"), tmp_path.join("ember.js"))
32
+ FileUtils.cp(::Ember::Data::Source.bundled_path_for("ember-data#{ext}"), tmp_path.join("ember-data.js"))
33
+ app.assets.append_path(tmp_path)
34
+
35
+ # Make the handlebars.js and handlebars.runtime.js bundled
36
+ # in handlebars-source available.
37
+ app.assets.append_path(File.expand_path('../', ::Handlebars::Source.bundled_path))
27
38
 
28
39
  # Allow a local variant override
29
40
  ember_path = app.root.join("vendor/assets/ember/#{variant}")
30
- app.config.assets.paths.unshift(ember_path.to_s) if ember_path.exist?
41
+ app.assets.prepend_path(ember_path.to_s) if ember_path.exist?
42
+
31
43
  else
32
44
  warn "No ember.js variant was specified in your config environment."
33
45
  warn "You can set a specific variant in your application config in "
@@ -39,24 +51,11 @@ module Ember
39
51
  end
40
52
  end
41
53
 
42
- initializer "ember_rails.find_ember", :after => "ember_rails.setup_vendor", :group => :all do |app|
43
- config.ember.ember_location ||= location_for(app, "ember.js")
44
- config.ember.handlebars_location ||= location_for(app, "handlebars.js")
45
- end
46
-
47
54
  initializer "ember_rails.es5_default", :group => :all do |app|
48
55
  if defined?(Closure::Compiler) && app.config.assets.js_compressor == :closure
49
56
  Closure::Compiler::DEFAULT_OPTIONS[:language_in] = 'ECMASCRIPT5'
50
57
  end
51
58
  end
52
-
53
- def location_for(app, file)
54
- path = app.config.assets.paths.find do |dir|
55
- Pathname.new(dir).join(file).exist?
56
- end
57
-
58
- File.join(path, file) if path
59
- end
60
59
  end
61
60
  end
62
61
  end
@@ -1,3 +1,4 @@
1
+ require 'ember/version'
1
2
  require 'generators/ember/generator_helpers'
2
3
 
3
4
  module Ember
@@ -7,9 +8,11 @@ module Ember
7
8
 
8
9
  source_root File.expand_path("../../templates", __FILE__)
9
10
 
10
- desc "Creates a default Ember.js folder layout in app/assets/javascripts/ember"
11
+ desc "Creates a default Ember.js folder layout in app/assets/javascripts"
11
12
 
13
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
12
14
  class_option :skip_git, :type => :boolean, :aliases => "-g", :default => false, :desc => "Skip Git keeps"
15
+ class_option :skip_ams, :type => :boolean, :aliases => "-a", :default => false, :desc => "Skip ActiveModelSerializers"
13
16
 
14
17
  def inject_ember
15
18
  application_file = "app/assets/javascripts/application.js"
@@ -29,6 +32,16 @@ module Ember
29
32
  end
30
33
  end
31
34
 
35
+ def inject_ams
36
+ return if options[:skip_ams]
37
+ gem_file = ENV['BUNDLE_GEMFILE'] || 'Gemfile'
38
+ append_to_file(gem_file, "\n" + [
39
+ '# Learn how to build an Ember-compatible Rails API at',
40
+ '# https://github.com/rails-api/active_model_serializers',
41
+ 'gem "active_model_serializers"'
42
+ ].join("\n"))
43
+ end
44
+
32
45
  def create_dir_layout
33
46
  %W{models controllers views routes helpers templates}.each do |dir|
34
47
  empty_directory "#{ember_path}/#{dir}"
@@ -49,7 +62,7 @@ module Ember
49
62
  end
50
63
 
51
64
  def create_app_stubs
52
- generate "ember:view", "application"
65
+ invoke "ember:view", ["application", "-d #{ember_path}"]
53
66
  end
54
67
  end
55
68
  end
@@ -1,16 +1,20 @@
1
1
  require 'ember/version'
2
+ require 'generators/ember/generator_helpers'
2
3
 
3
4
  module Ember
4
5
  module Generators
5
6
  class ControllerGenerator < ::Rails::Generators::NamedBase
7
+ include Ember::Generators::GeneratorHelpers
8
+
6
9
  source_root File.expand_path("../../templates", __FILE__)
7
10
 
8
11
  desc "Creates a new Ember.js controller"
9
12
  class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
13
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
10
14
  class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.ObjectController to represent a single object"
11
15
 
12
16
  def create_controller_files
13
- file_path = File.join('app/assets/javascripts/controllers', class_path, "#{file_name}_controller.js")
17
+ file_path = File.join(ember_path, 'controllers', class_path, "#{file_name}_controller.js")
14
18
  if options.array?
15
19
  template 'array_controller.js', file_path
16
20
  elsif options.object?
@@ -3,7 +3,7 @@ module Ember
3
3
  module GeneratorHelpers
4
4
 
5
5
  def ember_path
6
- "app/assets/javascripts"
6
+ options[:ember_path] || "app/assets/javascripts"
7
7
  end
8
8
 
9
9
  def application_name
@@ -1,4 +1,5 @@
1
1
  require 'ember/version'
2
+ require 'generators/ember/generator_helpers'
2
3
 
3
4
  module Ember
4
5
  module Generators
@@ -28,10 +29,10 @@ module Ember
28
29
  end
29
30
 
30
31
  Dir.chdir git_root do
31
- say_status("building", "bundle && bundle exec rake dist", :green)
32
+ say_status("building", "bundle && bundle exec rake clean dist", :green)
32
33
  Bundler.with_clean_env do
33
34
  cmd "bundle --gemfile #{gem_file}"
34
- cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake dist}
35
+ cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake clean dist}
35
36
  end
36
37
  end
37
38
 
@@ -64,10 +65,10 @@ module Ember
64
65
  end
65
66
 
66
67
  Dir.chdir git_root do
67
- say_status("building", "bundle && bundle exec rake", :green)
68
+ say_status("building", "bundle && bundle exec rake clean dist", :green)
68
69
  Bundler.with_clean_env do
69
70
  cmd "bundle --gemfile #{gem_file}"
70
- cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake}
71
+ cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake clean dist}
71
72
  end
72
73
  end
73
74
 
@@ -1,33 +1,37 @@
1
1
  require 'ember/version'
2
+ require 'generators/ember/generator_helpers'
2
3
 
3
4
  module Ember
4
5
  module Generators
5
6
  class ModelGenerator < ::Rails::Generators::NamedBase
7
+ include Ember::Generators::GeneratorHelpers
8
+
6
9
  source_root File.expand_path("../../templates", __FILE__)
7
10
  argument :attributes, :type => :array, :default => [], :banner => "field[:type] field[:type] ..."
8
11
 
9
12
  desc "Creates a new Ember.js model"
13
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
10
14
 
11
15
  def create_model_files
12
- template 'model.js', File.join('app/assets/javascripts/models', class_path, "#{file_name}.js")
16
+ template 'model.js', File.join(ember_path, 'models', class_path, "#{file_name}.js")
13
17
  end
14
18
 
15
19
  private
16
20
  EMBER_TYPE_LOOKUP = {
17
21
  nil => 'string',
18
22
 
19
- binary: 'string',
20
- string: 'string',
21
- text: 'string',
22
- boolean: 'boolean',
23
- date: 'date',
24
- datetime: 'date',
25
- time: 'date',
26
- timestamp: 'date',
27
- decimal: 'number',
28
- float: 'number',
29
- integer: 'number',
30
- primary_key: 'number'
23
+ :binary => 'string',
24
+ :string => 'string',
25
+ :text => 'string',
26
+ :boolean => 'boolean',
27
+ :date => 'date',
28
+ :datetime => 'date',
29
+ :time => 'date',
30
+ :timestamp => 'date',
31
+ :decimal => 'number',
32
+ :float => 'number',
33
+ :integer => 'number',
34
+ :primary_key => 'number'
31
35
  }
32
36
 
33
37
  def parse_attributes!
@@ -36,7 +40,7 @@ module Ember
36
40
  key = type.try(:to_sym)
37
41
  ember_type = EMBER_TYPE_LOOKUP[key] || type
38
42
 
39
- { name: name, type: ember_type }
43
+ { :name => name, :type => ember_type }
40
44
  end
41
45
  end
42
46
  end
@@ -1,14 +1,18 @@
1
1
  require 'ember/version'
2
+ require 'generators/ember/generator_helpers'
2
3
 
3
4
  module Ember
4
5
  module Generators
5
6
  class RouteGenerator < ::Rails::Generators::NamedBase
7
+ include Ember::Generators::GeneratorHelpers
8
+
6
9
  source_root File.expand_path("../../templates", __FILE__)
7
10
 
8
11
  desc "Creates a new Ember.js route"
12
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
9
13
 
10
14
  def create_route_files
11
- file_path = File.join('app/assets/javascripts/routes', class_path, "#{file_name}_route.js")
15
+ file_path = File.join(ember_path, 'routes', class_path, "#{file_name}_route.js")
12
16
  template 'route.js', file_path
13
17
  end
14
18
  end
@@ -1,17 +1,21 @@
1
1
  require 'ember/version'
2
+ require 'generators/ember/generator_helpers'
2
3
 
3
4
  module Ember
4
5
  module Generators
5
6
  class ViewGenerator < ::Rails::Generators::NamedBase
7
+ include Ember::Generators::GeneratorHelpers
8
+
6
9
  source_root File.expand_path("../../templates", __FILE__)
7
10
 
8
11
  desc "Creates a new Ember.js view and associated Handlebars template"
9
12
  class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
13
+ class_option :ember_path, :type => :string, :aliases => "-d", :default => false, :desc => "Custom ember app path"
10
14
  class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.ObjectController to represent a single object"
11
15
 
12
16
  def create_view_files
13
- template 'view.js', File.join('app/assets/javascripts/views', class_path, "#{file_name}_view.js")
14
- template 'view.handlebars', File.join('app/assets/javascripts/templates', class_path, "#{file_name}.handlebars")
17
+ template 'view.js', File.join(ember_path, 'views', class_path, "#{file_name}_view.js")
18
+ template 'view.handlebars', File.join(ember_path, 'templates', class_path, "#{file_name}.handlebars")
15
19
  invoke('ember:controller', [ file_name ], options)
16
20
  invoke('ember:route', [ file_name ], options)
17
21
  end
@@ -1,5 +1,11 @@
1
1
  <%= application_name.camelize %>.<%= class_name %> = DS.Model.extend({
2
- <% attributes.each_index do |idx| -%>
3
- <%= attributes[idx][:name].camelize(:lower) %>: DS.attr('<%= attributes[idx][:type] %>')<% if (idx < attributes.length-1) %>,<% end %>
2
+ <% attributes.each_with_index do |attribute, idx| -%>
3
+ <%= attribute[:name].camelize(:lower) %>: <%=
4
+ if %w(references belongs_to).member?(attribute[:type])
5
+ "DS.belongsTo('%s.%s')" % [application_name.camelize, attribute[:name].camelize]
6
+ else
7
+ "DS.attr('%s')" % attribute[:type]
8
+ end
9
+ %><% if (idx < attributes.length-1) %>,<% end %>
4
10
  <% end -%>
5
11
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-rails-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.11.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-02-09 00:00:00.000000000 Z
15
+ date: 2013-03-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: execjs
@@ -48,6 +48,38 @@ dependencies:
48
48
  version: '3.1'
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: barber
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.1
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 0.4.1
65
+ - !ruby/object:Gem::Dependency
66
+ name: ember-source
67
+ requirement: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: ember-data-source
51
83
  requirement: !ruby/object:Gem::Requirement
52
84
  none: false
53
85
  requirements:
@@ -126,6 +158,7 @@ files:
126
158
  - lib/ember/rails/version.rb
127
159
  - lib/ember/version.rb
128
160
  - lib/ember-rails-lite.rb
161
+ - lib/ember-rails.rb
129
162
  - lib/ember_rails.rb
130
163
  - lib/generators/ember/bootstrap_generator.rb
131
164
  - lib/generators/ember/controller_generator.rb
@@ -146,17 +179,16 @@ files:
146
179
  - lib/generators/templates/store.js
147
180
  - lib/generators/templates/view.handlebars
148
181
  - lib/generators/templates/view.js
149
- - vendor/ember/development/ember-data.js
150
- - vendor/ember/development/ember.js
151
- - vendor/ember/development/handlebars-runtime.js
152
- - vendor/ember/development/handlebars.js
153
- - vendor/ember/production/ember-data.js
154
- - vendor/ember/production/ember.js
155
- - vendor/ember/production/handlebars-runtime.js
156
- - vendor/ember/production/handlebars.js
157
182
  homepage: https://github.com/emberjs/ember-rails
158
183
  licenses: []
159
- post_install_message:
184
+ post_install_message: ! "# Ember-Rails Release Notes #\n\nIf you're upgrading from
185
+ ember-rails 0.11.1 or earlier, please be aware of the\nActiveModelSerializers changes
186
+ that are part of this update:\n\nActiveModelSerializers will no longer be a hard
187
+ dependency of ember-rails and\nwill not be require'd automatically. Please add
188
+ the following line to your\nGemfile to continue using ActiveModelSerializers with
189
+ ember-rails:\n\n gem \"active_model_serializers\"\n\nIn new applications, running
190
+ the bootstrap generator will append this\ndependency statement to your Gemfile for
191
+ you:\n\n rails g ember:bootstrap\n\nRead more about using ember-rails at https://github.com/emberjs/ember-rails\n"
160
192
  rdoc_options: []
161
193
  require_paths:
162
194
  - lib
@@ -177,5 +209,5 @@ rubyforge_project:
177
209
  rubygems_version: 1.8.23
178
210
  signing_key:
179
211
  specification_version: 3
180
- summary: Ember for Rails 3.1+ without ActiveModelSerializers
212
+ summary: Ember for Rails 3.1+
181
213
  test_files: []