Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry committed Oct 5, 2011
2 parents 1996540 + c495bfc commit 84eece0
Show file tree
Hide file tree
Showing 62 changed files with 686 additions and 374 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -99,3 +99,6 @@ if ENV['ORACLE_ENHANCED_PATH'] || ENV['ORACLE_ENHANCED']
gem "activerecord-oracle_enhanced-adapter", :git => "git://github.com/rsim/oracle-enhanced.git"
end
end

# A gem necessary for ActiveRecord tests with IBM DB
gem "ibm_db" if ENV['IBM_DB']
22 changes: 11 additions & 11 deletions actionpack/actionpack.gemspec
Expand Up @@ -16,16 +16,16 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency('activesupport', version)
s.add_dependency('activemodel', version)
s.add_dependency('rack-cache', '~> 1.0.3')
s.add_dependency('builder', '~> 3.0.0')
s.add_dependency('i18n', '~> 0.6')
s.add_dependency('rack', '~> 1.3.2')
s.add_dependency('rack-test', '~> 0.6.1')
s.add_dependency('journey', '~> 1.0.0')
s.add_dependency('sprockets', '~> 2.0.0')
s.add_dependency('erubis', '~> 2.7.0')
s.add_dependency('activesupport', version)
s.add_dependency('activemodel', version)
s.add_dependency('rack-cache', '~> 1.1')
s.add_dependency('builder', '~> 3.0.0')
s.add_dependency('i18n', '~> 0.6')
s.add_dependency('rack', '~> 1.3.2')
s.add_dependency('rack-test', '~> 0.6.1')
s.add_dependency('journey', '~> 1.0.0')
s.add_dependency('sprockets', '~> 2.0.2')
s.add_dependency('erubis', '~> 2.7.0')

s.add_development_dependency('tzinfo', '~> 0.3.29')
s.add_development_dependency('tzinfo', '~> 0.3.29')
end
3 changes: 2 additions & 1 deletion actionpack/lib/abstract_controller/asset_paths.rb
Expand Up @@ -3,7 +3,8 @@ module AssetPaths
extend ActiveSupport::Concern

included do
config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir
config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir,
:stylesheets_dir, :default_asset_host_protocol
end
end
end
4 changes: 2 additions & 2 deletions actionpack/lib/abstract_controller/rendering.rb
Expand Up @@ -120,8 +120,6 @@ def _render_template(options) #:nodoc:
view_renderer.render(view_context, options)
end

private

DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
@_action_name @_response_body @_formats @_prefixes @_config
@_view_context_class @_view_renderer @_lookup_context
Expand All @@ -139,6 +137,8 @@ def view_assigns
hash
end

private

# Normalize args and options.
# :api: private
def _normalize_render(*args, &block)
Expand Down
20 changes: 15 additions & 5 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -333,9 +333,21 @@ module Behavior
module ClassMethods

# Sets the controller class name. Useful if the name can't be inferred from test class.
# Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>.
# Normalizes +controller_class+ before using. Examples:
#
# tests WidgetController
# tests :widget
# tests 'widget'
#
def tests(controller_class)
self.controller_class = controller_class
case controller_class
when String, Symbol
self.controller_class = "#{controller_class.to_s.underscore}_controller".camelize.constantize
when Class
self.controller_class = controller_class
else
raise ArgumentError, "controller class must be a String, Symbol, or Class"
end
end

def controller_class=(new_class)
Expand All @@ -352,9 +364,7 @@ def controller_class
end

def determine_default_controller_class(name)
name.sub(/Test$/, '').constantize
rescue NameError
nil
name.sub(/Test$/, '').safe_constantize
end

def prepare_controller_class(new_class)
Expand Down
10 changes: 6 additions & 4 deletions actionpack/lib/action_dispatch/http/url.rb
Expand Up @@ -64,14 +64,16 @@ def rewrite_authentication(options)
end

def host_or_subdomain_and_domain(options)
return options[:host] unless options[:subdomain] || options[:domain]
return options[:host] if options[:subdomain].nil? && options[:domain].nil?

tld_length = options[:tld_length] || @@tld_length

host = ""
host << (options[:subdomain] || extract_subdomain(options[:host], tld_length))
host << "."
host << (options[:domain] || extract_domain(options[:host], tld_length))
unless options[:subdomain] == false
host << (options[:subdomain] || extract_subdomain(options[:host], tld_length))
host << "."
end
host << (options[:domain] || extract_domain(options[:host], tld_length))
host
end
end
Expand Down
5 changes: 3 additions & 2 deletions actionpack/lib/action_dispatch/routing/url_for.rb
Expand Up @@ -116,9 +116,10 @@ def url_options
# If <tt>:only_path</tt> is false, this option must be
# provided either explicitly, or via +default_url_options+.
# * <tt>:subdomain</tt> - Specifies the subdomain of the link, using the +tld_length+
# to split the domain from the host.
# * <tt>:domain</tt> - Specifies the domain of the link, using the +tld_length+
# to split the subdomain from the host.
# If false, removes all subdomains from the host part of the link.
# * <tt>:domain</tt> - Specifies the domain of the link, using the +tld_length+
# to split the domain from the host.
# * <tt>:tld_length</tt> - Number of labels the TLD id composed of, only used if
# <tt>:subdomain</tt> or <tt>:domain</tt> are supplied. Defaults to
# <tt>ActionDispatch::Http::URL.tld_length</tt>, which in turn defaults to 1.
Expand Down
7 changes: 1 addition & 6 deletions actionpack/lib/action_dispatch/testing/test_process.rb
Expand Up @@ -5,12 +5,7 @@
module ActionDispatch
module TestProcess
def assigns(key = nil)
assigns = {}.with_indifferent_access
@controller.instance_variable_names.each do |ivar|
next if ActionController::Base.protected_instance_variables.include?(ivar)
assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar)
end

assigns = @controller.view_assigns.with_indifferent_access
key.nil? ? assigns : assigns[key]
end

Expand Down
21 changes: 4 additions & 17 deletions actionpack/lib/action_view/asset_paths.rb
Expand Up @@ -16,20 +16,17 @@ def initialize(config, controller = nil)
# roots. Rewrite the asset path for cache-busting asset ids. Include
# asset host, if configured, with the correct request protocol.
#
# When include_host is true and the asset host does not specify the protocol
# the protocol parameter specifies how the protocol will be added.
# When :relative (default), the protocol will be determined by the client using current protocol
# When :request, the protocol will be the request protocol
# Otherwise, the protocol is used (E.g. :http, :https, etc)
def compute_public_path(source, dir, options = {})
source = source.to_s
return source if is_uri?(source)

options[:include_host] ||= true
source = rewrite_extension(source, dir, options[:ext]) if options[:ext]
source = rewrite_asset_path(source, dir, options)
source = rewrite_relative_url_root(source, relative_url_root)
source = rewrite_host_and_protocol(source, options[:protocol]) if options[:include_host]
source = rewrite_host_and_protocol(source, options[:protocol])
source
end

Expand Down Expand Up @@ -89,9 +86,7 @@ def compute_protocol(protocol)
end

def default_protocol
protocol = @config.action_controller.default_asset_host_protocol if @config.action_controller.present?
protocol ||= @config.default_asset_host_protocol
protocol || (has_request? ? :request : :relative)
@config.default_asset_host_protocol || (has_request? ? :request : :relative)
end

def invalid_asset_host!(help_message)
Expand Down Expand Up @@ -120,19 +115,11 @@ def compute_asset_host(source)
end

def relative_url_root
if config.action_controller.present?
config.action_controller.relative_url_root
else
config.relative_url_root
end
config.relative_url_root
end

def asset_host_config
if config.action_controller.present?
config.action_controller.asset_host
else
config.asset_host
end
config.asset_host
end

# Returns the current request if one exists.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/test_case.rb
Expand Up @@ -63,7 +63,7 @@ def helper_method(*methods)
methods.flatten.each do |method|
_helpers.module_eval <<-end_eval
def #{method}(*args, &block) # def current_user(*args, &block)
_test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block)
_test_case.send(%(#{method}), *args, &block) # _test_case.send(%(current_user), *args, &block)
end # end
end_eval
end
Expand Down
107 changes: 71 additions & 36 deletions actionpack/lib/sprockets/assets.rake
@@ -1,60 +1,95 @@
require "fileutils"

namespace :assets do
def ruby_rake_task(task)
env = ENV['RAILS_ENV'] || 'production'
groups = ENV['RAILS_GROUPS'] || 'assets'
args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"]
args << "--trace" if Rake.application.options.trace
ruby *args
end

# We are currently running with no explicit bundler group
# and/or no explicit environment - we have to reinvoke rake to
# execute this task.
def invoke_or_reboot_rake_task(task)
if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty?
ruby_rake_task task
else
Rake::Task[task].invoke
end
end

desc "Compile all the assets named in config.assets.precompile"
task :precompile do
# We need to do this dance because RAILS_GROUPS is used
# too early in the boot process and changing here is already too late.
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
ENV["RAILS_GROUPS"] ||= "assets"
ENV["RAILS_ENV"] ||= "production"
ruby $0, *ARGV
else
require "fileutils"
Rake::Task["tmp:cache:clear"].invoke
Rake::Task["assets:environment"].invoke
invoke_or_reboot_rake_task "assets:precompile:all"
end

namespace :precompile do
def internal_precompile(digest=nil)
unless Rails.application.config.assets.enabled
raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
exit
end

# Ensure that action view is loaded and the appropriate sprockets hooks get executed
# Ensure that action view is loaded and the appropriate
# sprockets hooks get executed
_ = ActionView::Base

config = Rails.application.config
config.assets.compile = true
config.assets.digest = false if ENV["RAILS_ASSETS_NONDIGEST"]

env = Rails.application.assets

# Always compile files and avoid use of existing precompiled assets
config.assets.compile = true
config.assets.digest = digest unless digest.nil?
config.assets.digests = {}

target = File.join(Rails.public_path, config.assets.prefix)
static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest)
env = Rails.application.assets
target = File.join(Rails.public_path, config.assets.prefix)
compiler = Sprockets::StaticCompiler.new(env,
target,
config.assets.precompile,
:manifest_path => config.assets.manifest,
:digest => config.assets.digest,
:manifest => digest.nil?)
compiler.compile
end

manifest = static_compiler.precompile(config.assets.precompile)
manifest_path = config.assets.manifest || target
FileUtils.mkdir_p(manifest_path)
task :all do
Rake::Task["assets:precompile:primary"].invoke
# We need to reinvoke in order to run the secondary digestless
# asset compilation run - a fresh Sprockets environment is
# required in order to compile digestless assets as the
# environment has already cached the assets on the primary
# run.
ruby_rake_task "assets:precompile:nondigest" if Rails.application.config.assets.digest
end

unless ENV["RAILS_ASSETS_NONDIGEST"]
File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
YAML.dump(manifest, f)
end
ENV["RAILS_ASSETS_NONDIGEST"] = "true"
ruby $0, *ARGV
end
task :primary => ["assets:environment", "tmp:cache:clear"] do
internal_precompile
end

task :nondigest => ["assets:environment", "tmp:cache:clear"] do
internal_precompile(false)
end
end

desc "Remove compiled assets"
task :clean => ['assets:environment', 'tmp:cache:clear'] do
config = Rails.application.config
public_asset_path = File.join(Rails.public_path, config.assets.prefix)
rm_rf public_asset_path, :secure => true
task :clean do
invoke_or_reboot_rake_task "assets:clean:all"
end

namespace :clean do
task :all => ["assets:environment", "tmp:cache:clear"] do
config = Rails.application.config
public_asset_path = File.join(Rails.public_path, config.assets.prefix)
rm_rf public_asset_path, :secure => true
end
end

task :environment do
Rails.application.initialize!(:assets)
Sprockets::Bootstrap.new(Rails.application).run
if Rails.application.config.assets.initialize_on_precompile
Rake::Task["environment"].invoke
else
Rails.application.initialize!(:assets)
Sprockets::Bootstrap.new(Rails.application).run
end
end
end
3 changes: 2 additions & 1 deletion actionpack/lib/sprockets/helpers.rb
@@ -1,5 +1,6 @@
module Sprockets
module Helpers
autoload :RailsHelper, "sprockets/helpers/rails_helper"
autoload :RailsHelper, "sprockets/helpers/rails_helper"
autoload :IsolatedHelper, "sprockets/helpers/isolated_helper"
end
end
13 changes: 13 additions & 0 deletions actionpack/lib/sprockets/helpers/isolated_helper.rb
@@ -0,0 +1,13 @@
module Sprockets
module Helpers
module IsolatedHelper
def controller
nil
end

def config
Rails.application.config.action_controller
end
end
end
end
3 changes: 0 additions & 3 deletions actionpack/lib/sprockets/helpers/rails_helper.rb
Expand Up @@ -8,9 +8,6 @@ module RailsHelper

def asset_paths
@asset_paths ||= begin
config = self.config if respond_to?(:config)
config ||= Rails.application.config
controller = self.controller if respond_to?(:controller)
paths = RailsHelper::AssetPaths.new(config, controller)
paths.asset_environment = asset_environment
paths.asset_digests = asset_digests
Expand Down

0 comments on commit 84eece0

Please sign in to comment.