Changeset 8578
- Timestamp:
- 01/06/08 20:53:23 (4 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/cgi_process.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/template_handlers/erb.rb (modified) (1 diff)
- trunk/actionpack/test/template/asset_tag_helper_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8577 r8578 1 1 *SVN* 2 3 * The asset_host block takes the controller request as an optional second argument. Example: use a single asset host for SSL requests. #10549 [Cheah Chu Yeow, Peter B, Tom Taylor] 2 4 3 5 * Support render :text => nil. #6684 [tjennings, PotatoSalad, Cheah Chu Yeow] trunk/actionpack/lib/action_controller/cgi_process.rb
r8176 r8578 4 4 module ActionController #:nodoc: 5 5 class Base 6 # Process a request extracted from a nCGI object and return a response. Pass false as <tt>session_options</tt> to disable6 # Process a request extracted from a CGI object and return a response. Pass false as <tt>session_options</tt> to disable 7 7 # sessions (large performance increase if sessions are not needed). The <tt>session_options</tt> are the same as for CGI::Session: 8 8 # … … 18 18 # * <tt>:session_expires</tt> - the time the current session expires, as a +Time+ object. If not set, the session will continue 19 19 # indefinitely. 20 # * <tt>:session_domain</tt> - the hostname domain for which this session is valid. If not set, defaults to the hostname of the20 # * <tt>:session_domain</tt> - the hostname domain for which this session is valid. If not set, defaults to the hostname of the 21 21 # server. 22 22 # * <tt>:session_secure</tt> - if +true+, this session will only work over HTTPS. … … 35 35 class CgiRequest < AbstractRequest #:nodoc: 36 36 attr_accessor :cgi, :session_options 37 class SessionFixationAttempt < StandardError; end #:nodoc: 37 class SessionFixationAttempt < StandardError #:nodoc: 38 end 38 39 39 40 DEFAULT_SESSION_OPTIONS = { trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb
r8421 r8578 51 51 # => <link href="http://assets1.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" /> 52 52 # 53 # The proc takes a single <tt>source</tt> parameter which is the path of the source asset. This can be used to 54 # generate a particular asset host depending on the asset path. 53 # The proc takes a <tt>source</tt> parameter (which is the path of the source asset) and an optional 54 # <tt>request</tt> parameter (which is an entire instance of an <tt>ActionController::AbstractRequest</tt> 55 # subclass). This can be used to generate a particular asset host depending on the asset path and the particular 56 # request. 55 57 # 56 58 # ActionController::Base.asset_host = Proc.new { |source| … … 65 67 # stylesheet_include_tag("application") 66 68 # => <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" /> 69 # 70 # The optional <tt>request</tt> parameter to the proc is useful in particular for serving assets from an 71 # SSL-protected page. The example proc below disables asset hosting for HTTPS connections, while still sending 72 # assets for plain HTTP requests from asset hosts. This is useful for avoiding mixed media warnings when serving 73 # non-HTTP assets from HTTPS web pages when you don't have an SSL certificate for each of the asset hosts. 74 # 75 # ActionController::Base.asset_host = Proc.new { |source, request| 76 # if request.ssl? 77 # "#{request.protocol}#{request.host_with_port}" 78 # else 79 # "#{request.protocol}assets.example.com" 80 # end 81 # } 67 82 # 68 83 # === Using asset timestamps … … 462 477 if host = ActionController::Base.asset_host 463 478 if host.is_a?(Proc) 464 host.call(source) 479 case host.arity 480 when 2: 481 host.call(source, @controller.request) 482 else 483 host.call(source) 484 end 465 485 else 466 486 host % (source.hash % 4) trunk/actionpack/lib/action_view/template_handlers/erb.rb
r8422 r8578 5 5 HTML_ESCAPE = { '&' => '&', '"' => '"', '>' => '>', '<' => '<' } 6 6 7 # A utility method for escaping HTML tag characters. 8 # This method is also aliased as <tt>h</tt>. 9 # 10 # In your ERb templates, use this method to escape any unsafe content. For example: 11 # <%=h @person.name %> 12 # 13 # ==== Example: 14 # puts html_escape("is a > 0 & a < 10?") 15 # # => is a > 0 & a < 10? 7 16 def html_escape(s) 8 17 s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] } trunk/actionpack/test/template/asset_tag_helper_test.rb
r8564 r8578 35 35 def relative_url_root() "" end 36 36 def protocol() 'http://' end 37 def ssl?() false end 38 def host_with_port() 'localhost' end 37 39 end.new 38 40 … … 249 251 250 252 def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host 251 ENV[ "RAILS_ASSET_ID"] = ""253 ENV['RAILS_ASSET_ID'] = '' 252 254 ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } 253 255 ActionController::Base.perform_caching = true … … 263 265 ensure 264 266 FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) 267 end 268 269 def test_caching_javascript_include_tag_when_caching_on_with_2_argument_proc_asset_host 270 ENV['RAILS_ASSET_ID'] = '' 271 ActionController::Base.asset_host = Proc.new { |source, request| 272 if request.ssl? 273 "#{request.protocol}#{request.host_with_port}" 274 else 275 "#{request.protocol}assets#{source.length}.example.com" 276 end 277 } 278 ActionController::Base.perform_caching = true 279 280 assert_equal '/javascripts/vanilla.js'.length, 23 281 assert_dom_equal( 282 %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>), 283 javascript_include_tag(:all, :cache => 'vanilla') 284 ) 285 286 assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js')) 287 288 class << @controller.request 289 def protocol() 'https://' end 290 def ssl?() true end 291 end 292 293 assert_equal '/javascripts/secure.js'.length, 22 294 assert_dom_equal( 295 %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>), 296 javascript_include_tag(:all, :cache => 'secure') 297 ) 298 299 assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js')) 300 301 ensure 302 FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js')) 303 FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js')) 265 304 end 266 305