Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more robust environment auto-switching

This commit removes Ember from vendor/assets/javascripts completely. It
is important to do that because Rails will automatically add that
entire tree to the asset pipeline. That makes it possible to get the
production version of Ember when you were expecting the development
version of Ember and vice versa, depending on exactly how the asset
paths are ordered and whether you sacrificed the correct farmyard
animal to Sprockets within the last month.

In addition, this commit provides a map between Rails environments and the version of Ember that ember-rails will automatically provide. If you are, for example, using capybara-webkit to do acceptance testing, you absolutely want to run your acceptance tests against the production version of Ember. The previous behaviour was to provide the development version of Ember test environments, which is IMO pretty dangerous.
  • Loading branch information...
commit b70b226c499e4204cb1c508f6b27b3b1b11dbfaa 1 parent 51f1f2b
@indirect indirect authored
View
2  ember-rails.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rails", ["~> 3.1"]
- s.files = %w(README.md LICENSE) + Dir["lib/**/*", "vendor/assets/**/*"]
+ s.files = %w(README.md LICENSE) + Dir["lib/**/*", "vendor/**/*"]
s.require_paths = ["lib"]
end
View
2  lib/ember/handlebars/source.rb
@@ -12,7 +12,7 @@ def vendor_path
path = ::Rails.root.nil? ? '' : ::Rails.root.join('vendor/assets/javascripts/ember.js')
if !File.exists?(path)
- path = File.expand_path(File.join(__FILE__, '../../../../vendor/assets/javascripts/production/ember.js'))
+ path = File.expand_path(File.join(__FILE__, '../../../../vendor/ember/production/ember.js'))
end
end
View
2  lib/ember/handlebars/template.rb
@@ -1,3 +1,5 @@
+require 'sprockets'
+require 'sprockets/engines'
require 'ember/handlebars/source'
module Ember
View
13 lib/ember/rails/engine.rb
@@ -1,4 +1,5 @@
require 'ember/handlebars/template'
+require 'active_model_serializers'
module Ember
module Rails
@@ -8,8 +9,7 @@ class Engine < ::Rails::Engine
config.handlebars.templates_root = "templates"
config.handlebars.templates_path_separator = '/'
- initializer :setup_ember_rails, :group => :all do |app|
-
+ initializer "ember_rails.setup", :group => :all do |app|
require 'ember/filters/slim' if defined? Slim
require 'ember/filters/haml' if defined? Haml
@@ -17,13 +17,8 @@ class Engine < ::Rails::Engine
app.assets.register_engine '.hbs', Ember::Handlebars::Template
app.assets.register_engine '.hjs', Ember::Handlebars::Template
- assets_path = File.expand_path(File.join(__FILE__, '../../../../vendor/assets/javascripts'))
-
- if ::Rails.env.production?
- app.assets.append_path File.join(assets_path, 'production')
- else
- app.assets.append_path File.join(assets_path, 'development')
- end
+ # Add the gem's vendored ember to the end of the asset search path
+ app.config.assets.paths << Ember::Rails.ember_path
end
end
end
View
28 lib/ember_rails.rb
@@ -1,8 +1,24 @@
-require 'sprockets'
-require 'sprockets/engines'
-require 'active_model_serializers'
-
-require 'ember/rails/engine'
-
+require 'ember/rails/version'
require 'ember/version'
require 'ember/handlebars/version'
+require 'ember/rails/engine'
+
+module Ember
+ module Rails
+ # Create a map from Rails environments to versions of Ember.
+ mattr_accessor :map
+
+ # By default, production and test will both use minified Ember.
+ # Add mappings in your environment files like so:
+ # Ember::Rails.map["staging"] = "production"
+ self.map ||= {"test" => "production"}
+
+ def self.ember_path
+ @ember_path ||= begin
+ mapped_dir = Ember::Rails.map[::Rails.env]
+ vendored_ember = File.expand_path("../vendor/ember", __FILE__)
+ File.join(vendored_ember, mapped_dir || ::Rails.env)
+ end
+ end
+ end
+end
View
0  vendor/assets/javascripts/development/ember-data.js → vendor/ember/development/ember-data.js
File renamed without changes
View
0  ...r/assets/javascripts/development/ember-runtime.js → vendor/ember/development/ember-runtime.js
File renamed without changes
View
0  vendor/assets/javascripts/development/ember.js → vendor/ember/development/ember.js
File renamed without changes
View
0  vendor/assets/javascripts/production/ember-data.js → vendor/ember/production/ember-data.js
File renamed without changes
View
0  ...or/assets/javascripts/production/ember-runtime.js → vendor/ember/production/ember-runtime.js
File renamed without changes
View
0  vendor/assets/javascripts/production/ember.js → vendor/ember/production/ember.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.