actionpack 3.1.1.rc1 → 3.1.1.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,5 +1,45 @@
1
1
  *Rails 3.1.1 (unreleased)*
2
2
 
3
+ * javascript_path and stylesheet_path now refer to /assets if asset pipelining
4
+ is on. [Santiago Pastorino]
5
+
6
+ * button_to support form option. Now you're able to pass for example
7
+ 'data-type' => 'json'. [ihower]
8
+
9
+ * image_path and image_tag should use /assets if asset pipelining is turned
10
+ on. Closes #3126 [Santiago Pastorino and christos]
11
+
12
+ * Avoid use of existing precompiled assets during rake assets:precompile run.
13
+ Closes #3119 [Guillermo Iguaran]
14
+
15
+ * Copy assets to nondigested filenames too [Santiago Pastorino]
16
+
17
+ * Give precedence to `config.digest = false` over the existence of
18
+ manifest.yml asset digests [christos]
19
+
20
+ * escape options for the stylesheet_link_tag method [Alexey Vakhov]
21
+
22
+ * Re-launch assets:precompile task using (Rake.)ruby instead of Kernel.exec so
23
+ it works on Windows [cablegram]
24
+
25
+ * env var passed to process shouldn't be modified in process method. [Santiago
26
+ Pastorino]
27
+
28
+ * `rake assets:precompile` loads the application but does not initialize
29
+ it.
30
+
31
+ To the app developer, this means configuration add in
32
+ config/initializers/* will not be executed.
33
+
34
+ Plugins developers need to special case their initializers that are
35
+ meant to be run in the assets group by adding :group => :assets. [José Valim]
36
+
37
+ * Sprockets uses config.assets.prefix for asset_path [asee]
38
+
39
+ * FileStore key_file_path properly limit filenames to 255 characters. [phuibonhoa]
40
+
41
+ * Fix Hash#to_query edge case with html_safe strings. [brainopia]
42
+
3
43
  * Allow asset tag helper methods to accept :digest => false option in order to completely avoid the digest generation.
4
44
  Useful for linking assets from static html files or from emails when the user
5
45
  could probably look at an older html email with an older asset. [Santiago Pastorino]
@@ -1,4 +1,5 @@
1
1
  require 'set'
2
+ require 'cgi'
2
3
  require 'active_support/core_ext/class/attribute'
3
4
 
4
5
  module HTML
@@ -164,13 +164,14 @@ module ActionDispatch
164
164
  remove_possible_method :#{selector}
165
165
  def #{selector}(*args)
166
166
  options = args.extract_options!
167
+ result = #{options.inspect}
167
168
 
168
169
  if args.any?
169
- options[:_positional_args] = args
170
- options[:_positional_keys] = #{route.segment_keys.inspect}
170
+ result[:_positional_args] = args
171
+ result[:_positional_keys] = #{route.segment_keys.inspect}
171
172
  end
172
173
 
173
- options ? #{options.inspect}.merge(options) : #{options.inspect}
174
+ result.merge(options)
174
175
  end
175
176
  protected :#{selector}
176
177
  END_EVAL
@@ -244,8 +244,8 @@ module ActionDispatch
244
244
  end
245
245
 
246
246
  # Performs the actual request.
247
- def process(method, path, parameters = nil, env = nil)
248
- env ||= {}
247
+ def process(method, path, parameters = nil, rack_env = nil)
248
+ rack_env ||= {}
249
249
  if path =~ %r{://}
250
250
  location = URI.parse(path)
251
251
  https! URI::HTTPS === location if location.scheme
@@ -261,7 +261,7 @@ module ActionDispatch
261
261
 
262
262
  hostname, port = host.split(':')
263
263
 
264
- default_env = {
264
+ env = {
265
265
  :method => method,
266
266
  :params => parameters,
267
267
 
@@ -279,7 +279,7 @@ module ActionDispatch
279
279
 
280
280
  session = Rack::Test::Session.new(_mock_session)
281
281
 
282
- env.reverse_merge!(default_env)
282
+ env.merge!(rack_env)
283
283
 
284
284
  # NOTE: rack-test v0.5 doesn't build a default uri correctly
285
285
  # Make sure requested path is always a full uri
@@ -3,7 +3,7 @@ module ActionPack
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 1
6
- PRE = "rc1"
6
+ PRE = "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
@@ -17,7 +17,7 @@ module ActionView
17
17
 
18
18
  def asset_tag(source, options)
19
19
  # We force the :request protocol here to avoid a double-download bug in IE7 and IE8
20
- tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => ERB::Util.html_escape(path_to_asset(source, :protocol => :request)) }.merge(options), false, false)
20
+ tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => path_to_asset(source, :protocol => :request) }.merge(options))
21
21
  end
22
22
 
23
23
  def custom_dir
@@ -279,6 +279,7 @@ module ActionView
279
279
  # processed normally, otherwise no action is taken.
280
280
  # * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
281
281
  # submit behavior. By default this behavior is an ajax submit.
282
+ # * <tt>:form</tt> - This hash will be form attributes
282
283
  # * <tt>:form_class</tt> - This controls the class of the form within which the submit button will
283
284
  # be placed
284
285
  #
@@ -295,6 +296,12 @@ module ActionView
295
296
  # # </form>"
296
297
  #
297
298
  #
299
+ # <%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %>
300
+ # # => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
301
+ # # <div><input value="Create" type="submit" /></div>
302
+ # # </form>"
303
+ #
304
+ #
298
305
  # <%= button_to "Delete Image", { :action => "delete", :id => @image.id },
299
306
  # :confirm => "Are you sure?", :method => :delete %>
300
307
  # # => "<form method="post" action="/images/delete/1" class="button_to">
@@ -324,10 +331,11 @@ module ActionView
324
331
  end
325
332
 
326
333
  form_method = method.to_s == 'get' ? 'get' : 'post'
327
- form_class = html_options.delete('form_class') || 'button_to'
328
-
334
+ form_options = html_options.delete('form') || {}
335
+ form_options[:class] ||= html_options.delete('form_class') || 'button_to'
336
+
329
337
  remote = html_options.delete('remote')
330
-
338
+
331
339
  request_token_tag = ''
332
340
  if form_method == 'post' && protect_against_forgery?
333
341
  request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
@@ -340,8 +348,10 @@ module ActionView
340
348
 
341
349
  html_options.merge!("type" => "submit", "value" => name)
342
350
 
343
- ("<form method=\"#{form_method}\" action=\"#{ERB::Util.html_escape(url)}\" #{"data-remote=\"true\"" if remote} class=\"#{ERB::Util.html_escape(form_class)}\"><div>" +
344
- method_tag + tag("input", html_options) + request_token_tag + "</div></form>").html_safe
351
+ form_options.merge!(:method => form_method, :action => url)
352
+ form_options.merge!("data-remote" => "true") if remote
353
+
354
+ "#{tag(:form, form_options, true)}<div>#{method_tag}#{tag("input", html_options)}#{request_token_tag}</div></form>".html_safe
345
355
  end
346
356
 
347
357
 
@@ -6,58 +6,55 @@ namespace :assets do
6
6
  if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
7
7
  ENV["RAILS_GROUPS"] ||= "assets"
8
8
  ENV["RAILS_ENV"] ||= "production"
9
- Kernel.exec $0, *ARGV
9
+ ruby $0, *ARGV
10
10
  else
11
- Rake::Task["environment"].invoke
11
+ require "fileutils"
12
12
  Rake::Task["tmp:cache:clear"].invoke
13
+ Rake::Task["assets:environment"].invoke
14
+
15
+ unless Rails.application.config.assets.enabled
16
+ raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
17
+ end
13
18
 
14
19
  # Ensure that action view is loaded and the appropriate sprockets hooks get executed
15
20
  ActionView::Base
16
21
 
17
- # Always compile files
18
- Rails.application.config.assets.compile = true
19
-
20
- # Always ignore asset host
21
- Rails.application.config.action_controller.asset_host = nil
22
-
23
22
  config = Rails.application.config
23
+ config.assets.compile = true
24
+ config.assets.digest = false if ENV["RAILS_ASSETS_NONDIGEST"]
25
+
24
26
  env = Rails.application.assets
25
- target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
26
- manifest = {}
27
+
28
+ # Always compile files and avoid use of existing precompiled assets
29
+ config.assets.compile = true
30
+ config.assets.digests = {}
31
+
32
+ target = File.join(Rails.public_path, config.assets.prefix)
33
+ static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest)
34
+
35
+ manifest = static_compiler.precompile(config.assets.precompile)
27
36
  manifest_path = config.assets.manifest || target
37
+ FileUtils.mkdir_p(manifest_path)
28
38
 
29
- config.assets.precompile.each do |path|
30
- env.each_logical_path do |logical_path|
31
- if path.is_a?(Regexp)
32
- next unless path.match(logical_path)
33
- elsif path.is_a?(Proc)
34
- next unless path.call(logical_path)
35
- else
36
- next unless File.fnmatch(path.to_s, logical_path)
37
- end
38
-
39
- if asset = env.find_asset(logical_path)
40
- asset_path = config.assets.digest ? asset.digest_path : logical_path
41
- manifest[logical_path] = asset_path
42
- filename = target.join(asset_path)
43
-
44
- mkdir_p filename.dirname
45
- asset.write_to(filename)
46
- asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
47
- end
39
+ unless ENV["RAILS_ASSETS_NONDIGEST"]
40
+ File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
41
+ YAML.dump(manifest, f)
48
42
  end
49
- end
50
-
51
- File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
52
- YAML.dump(manifest, f)
43
+ ENV["RAILS_ASSETS_NONDIGEST"] = "true"
44
+ ruby $0, *ARGV
53
45
  end
54
46
  end
55
47
  end
56
48
 
57
49
  desc "Remove compiled assets"
58
- task :clean => [:environment, 'tmp:cache:clear'] do
50
+ task :clean => ['assets:environment', 'tmp:cache:clear'] do
59
51
  config = Rails.application.config
60
52
  public_asset_path = File.join(Rails.public_path, config.assets.prefix)
61
53
  rm_rf public_asset_path, :secure => true
62
54
  end
55
+
56
+ task :environment do
57
+ Rails.application.initialize!(:assets)
58
+ Sprockets::Bootstrap.new(Rails.application).run
59
+ end
63
60
  end
@@ -0,0 +1,65 @@
1
+ module Sprockets
2
+ class Bootstrap
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ # TODO: Get rid of config.assets.enabled
8
+ def run
9
+ app, config = @app, @app.config
10
+ return unless app.assets
11
+
12
+ config.assets.paths.each { |path| app.assets.append_path(path) }
13
+
14
+ if config.assets.compress
15
+ # temporarily hardcode default JS compressor to uglify. Soon, it will work
16
+ # the same as SCSS, where a default plugin sets the default.
17
+ unless config.assets.js_compressor == false
18
+ app.assets.js_compressor = LazyCompressor.new { expand_js_compressor(config.assets.js_compressor || :uglifier) }
19
+ end
20
+
21
+ unless config.assets.css_compressor == false
22
+ app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) }
23
+ end
24
+ end
25
+
26
+ if config.assets.compile
27
+ app.routes.prepend do
28
+ mount app.assets => config.assets.prefix
29
+ end
30
+ end
31
+
32
+ if config.assets.digest
33
+ app.assets = app.assets.index
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def expand_js_compressor(sym)
40
+ case sym
41
+ when :closure
42
+ require 'closure-compiler'
43
+ Closure::Compiler.new
44
+ when :uglifier
45
+ require 'uglifier'
46
+ Uglifier.new
47
+ when :yui
48
+ require 'yui/compressor'
49
+ YUI::JavaScriptCompressor.new
50
+ else
51
+ sym
52
+ end
53
+ end
54
+
55
+ def expand_css_compressor(sym)
56
+ case sym
57
+ when :yui
58
+ require 'yui/compressor'
59
+ YUI::CssCompressor.new
60
+ else
61
+ sym
62
+ end
63
+ end
64
+ end
65
+ end
@@ -13,7 +13,6 @@ module Sprockets
13
13
  controller = self.controller if respond_to?(:controller)
14
14
  paths = RailsHelper::AssetPaths.new(config, controller)
15
15
  paths.asset_environment = asset_environment
16
- paths.asset_prefix = asset_prefix
17
16
  paths.asset_digests = asset_digests
18
17
  paths.compile_assets = compile_assets?
19
18
  paths.digest_assets = digest_assets?
@@ -57,10 +56,25 @@ module Sprockets
57
56
 
58
57
  def asset_path(source, options = {})
59
58
  source = source.logical_path if source.respond_to?(:logical_path)
60
- path = asset_paths.compute_public_path(source, 'assets', options.merge(:body => true))
59
+ path = asset_paths.compute_public_path(source, asset_prefix, options.merge(:body => true))
61
60
  options[:body] ? "#{path}?body=1" : path
62
61
  end
63
62
 
63
+ def image_path(source)
64
+ asset_path(source)
65
+ end
66
+ alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
67
+
68
+ def javascript_path(source)
69
+ asset_path(source)
70
+ end
71
+ alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with an javascript_path named route
72
+
73
+ def stylesheet_path(source)
74
+ asset_path(source)
75
+ end
76
+ alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with an stylesheet_path named route
77
+
64
78
  private
65
79
  def debug_assets?
66
80
  begin
@@ -107,10 +121,6 @@ module Sprockets
107
121
 
108
122
  class AssetNotPrecompiledError < StandardError; end
109
123
 
110
- def compute_public_path(source, dir, options = {})
111
- super(source, asset_prefix, options)
112
- end
113
-
114
124
  # Return the filesystem path for the source
115
125
  def compute_source_path(source, ext)
116
126
  asset_for(source, ext)
@@ -124,7 +134,7 @@ module Sprockets
124
134
  end
125
135
 
126
136
  def digest_for(logical_path)
127
- if asset_digests && (digest = asset_digests[logical_path])
137
+ if digest_assets && asset_digests && (digest = asset_digests[logical_path])
128
138
  return digest
129
139
  end
130
140
 
@@ -1,7 +1,9 @@
1
1
  module Sprockets
2
- autoload :Helpers, "sprockets/helpers"
2
+ autoload :Bootstrap, "sprockets/bootstrap"
3
+ autoload :Helpers, "sprockets/helpers"
3
4
  autoload :LazyCompressor, "sprockets/compressors"
4
5
  autoload :NullCompressor, "sprockets/compressors"
6
+ autoload :StaticCompiler, "sprockets/static_compiler"
5
7
 
6
8
  # TODO: Get rid of config.assets.enabled
7
9
  class Railtie < ::Rails::Railtie
@@ -11,7 +13,7 @@ module Sprockets
11
13
  load "sprockets/assets.rake"
12
14
  end
13
15
 
14
- initializer "sprockets.environment" do |app|
16
+ initializer "sprockets.environment", :group => :assets do |app|
15
17
  config = app.config
16
18
  next unless config.assets.enabled
17
19
 
@@ -50,59 +52,7 @@ module Sprockets
50
52
  # are compiled, and so that other Railties have an opportunity to
51
53
  # register compressors.
52
54
  config.after_initialize do |app|
53
- next unless app.assets
54
- config = app.config
55
-
56
- config.assets.paths.each { |path| app.assets.append_path(path) }
57
-
58
- if config.assets.compress
59
- # temporarily hardcode default JS compressor to uglify. Soon, it will work
60
- # the same as SCSS, where a default plugin sets the default.
61
- unless config.assets.js_compressor == false
62
- app.assets.js_compressor = LazyCompressor.new { expand_js_compressor(config.assets.js_compressor || :uglifier) }
63
- end
64
-
65
- unless config.assets.css_compressor == false
66
- app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) }
67
- end
68
- end
69
-
70
- if config.assets.compile
71
- app.routes.prepend do
72
- mount app.assets => config.assets.prefix
73
- end
74
- end
75
-
76
- if config.assets.digest
77
- app.assets = app.assets.index
78
- end
55
+ Sprockets::Bootstrap.new(app).run
79
56
  end
80
-
81
- protected
82
- def expand_js_compressor(sym)
83
- case sym
84
- when :closure
85
- require 'closure-compiler'
86
- Closure::Compiler.new
87
- when :uglifier
88
- require 'uglifier'
89
- Uglifier.new
90
- when :yui
91
- require 'yui/compressor'
92
- YUI::JavaScriptCompressor.new
93
- else
94
- sym
95
- end
96
- end
97
-
98
- def expand_css_compressor(sym)
99
- case sym
100
- when :yui
101
- require 'yui/compressor'
102
- YUI::CssCompressor.new
103
- else
104
- sym
105
- end
106
- end
107
57
  end
108
58
  end
@@ -0,0 +1,52 @@
1
+ require 'fileutils'
2
+
3
+ module Sprockets
4
+ class StaticCompiler
5
+ attr_accessor :env, :target, :digest
6
+
7
+ def initialize(env, target, options = {})
8
+ @env = env
9
+ @target = target
10
+ @digest = options.key?(:digest) ? options.delete(:digest) : true
11
+ end
12
+
13
+ def precompile(paths)
14
+ Rails.application.config.assets.digest = digest
15
+ manifest = {}
16
+
17
+ env.each_logical_path do |logical_path|
18
+ next unless precompile_path?(logical_path, paths)
19
+ if asset = env.find_asset(logical_path)
20
+ manifest[logical_path] = compile(asset)
21
+ end
22
+ end
23
+ manifest
24
+ end
25
+
26
+ def compile(asset)
27
+ asset_path = digest_asset(asset)
28
+ filename = File.join(target, asset_path)
29
+ FileUtils.mkdir_p File.dirname(filename)
30
+ asset.write_to(filename)
31
+ asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
32
+ asset_path
33
+ end
34
+
35
+ def precompile_path?(logical_path, paths)
36
+ paths.each do |path|
37
+ if path.is_a?(Regexp)
38
+ return true if path.match(logical_path)
39
+ elsif path.is_a?(Proc)
40
+ return true if path.call(logical_path)
41
+ else
42
+ return true if File.fnmatch(path.to_s, logical_path)
43
+ end
44
+ end
45
+ false
46
+ end
47
+
48
+ def digest_asset(asset)
49
+ digest ? asset.digest_path : asset.logical_path
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 977940594
4
+ hash: 977940595
5
5
  prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 1
10
- - rc1
11
- version: 3.1.1.rc1
10
+ - rc2
11
+ version: 3.1.1.rc2
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Heinemeier Hansson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-09-14 00:00:00 -07:00
19
+ date: 2011-09-29 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -27,13 +27,13 @@ dependencies:
27
27
  requirements:
28
28
  - - "="
29
29
  - !ruby/object:Gem::Version
30
- hash: 977940594
30
+ hash: 977940595
31
31
  segments:
32
32
  - 3
33
33
  - 1
34
34
  - 1
35
- - rc1
36
- version: 3.1.1.rc1
35
+ - rc2
36
+ version: 3.1.1.rc2
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency
@@ -44,13 +44,13 @@ dependencies:
44
44
  requirements:
45
45
  - - "="
46
46
  - !ruby/object:Gem::Version
47
- hash: 977940594
47
+ hash: 977940595
48
48
  segments:
49
49
  - 3
50
50
  - 1
51
51
  - 1
52
- - rc1
53
- version: 3.1.1.rc1
52
+ - rc2
53
+ version: 3.1.1.rc2
54
54
  type: :runtime
55
55
  version_requirements: *id002
56
56
  - !ruby/object:Gem::Dependency
@@ -386,10 +386,12 @@ files:
386
386
  - lib/action_view/testing/resolvers.rb
387
387
  - lib/action_view.rb
388
388
  - lib/sprockets/assets.rake
389
+ - lib/sprockets/bootstrap.rb
389
390
  - lib/sprockets/compressors.rb
390
391
  - lib/sprockets/helpers/rails_helper.rb
391
392
  - lib/sprockets/helpers.rb
392
393
  - lib/sprockets/railtie.rb
394
+ - lib/sprockets/static_compiler.rb
393
395
  has_rdoc: true
394
396
  homepage: http://www.rubyonrails.org
395
397
  licenses: []