lib/rack/jquery_ui.rb in rack-jquery_ui-0.0.3 vs lib/rack/jquery_ui.rb in rack-jquery_ui-0.0.4
- old
+ new
@@ -1,11 +1,13 @@
require "rack/jquery_ui/version"
+require "rack/jquery/helpers"
module Rack
# jQuery CDN script tags and fallback in one neat package.
class JQueryUI
+ include JQuery::Helpers
JQUERY_UI_FILE_NAME = "jquery-ui.min.js"
# Script tags for the Media Temple CDN
MEDIA_TEMPLE = "<script src='http://code.jquery.com/ui/1.10.1/jquery-ui.js'></script>"
@@ -22,14 +24,10 @@
!window.jQuery.ui && document.write(unescape("%3Cscript src='/js/jquery-ui/#{JQUERY_UI_VERSION}/#{JQUERY_UI_FILE_NAME}' type='text/javascript'%3E%3C/script%3E"))
</script>
STR
- # Ten years in seconds.
- TEN_YEARS = 60 * 60 * 24 * 365 * 10
-
-
# @param [Symbol] organisation Choose which CDN to use, either :google, :microsoft or :media_temple
# @return [String] The HTML script tags to get the CDN.
def self.cdn( organisation=:google )
script = case organisation
when :media_temple then MEDIA_TEMPLE
@@ -65,16 +63,10 @@
def call( env )
request = Rack::Request.new(env.dup)
if request.path_info == @http_path_to_jquery
response = Rack::Response.new
# for caching
- response.headers.merge!( {
- "Last-Modified" => JQUERY_UI_VERSION_DATE,
- "Expires" => Rack::Utils.rfc2109(Time.now + TEN_YEARS),
- "Cache-Control" => "max-age=#{TEN_YEARS},public",
- "Etag" => "#{JQUERY_UI_FILE_NAME}-#{JQUERY_UI_VERSION}",
- 'Content-Type' =>'application/javascript; charset=utf-8'
- })
+ response.headers.merge! caching_headers( "#{JQUERY_UI_FILE_NAME}-#{JQUERY_UI_VERSION}", JQUERY_UI_VERSION_DATE)
# There's no need to test if the IF_MODIFIED_SINCE against the release date because the header will only be passed if the file was previously accessed by the requester, and the file is never updated. If it is updated then it is accessed by a different path.
if request.env['HTTP_IF_MODIFIED_SINCE']
response.status = 304
else