24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/padrino-contrib/helpers/jquery.rb', line 24
def javascript_include_tag_jquery(options={})
libs = ["http://ajax.googleapis.com/ajax/libs/jquery/#{options[:version] || '1.7.1'}/jquery.min.js"]
if options.delete(:ui)
libs << "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"
end
if options.delete(:i18n)
libs << "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/i18n/jquery-ui-i18n.min.js"
end
if cache = options.delete(:cache)
cache = 'jquery' if cache.is_a?(TrueClass)
lib = cache.to_s
path = Padrino.root("public", uri_root_path('javascripts', lib))
path += ".js" unless path =~ /\.js$/
unless File.exist?(path)
began_at = Time.now
require 'open-uri' unless defined?(OpenURI)
sources = libs.map do |l|
source = open(l).read
if cs = source =~ /\/\*\!/
cr = source.slice(cs, source.length)
ce = cr =~ /\*\//
cr = source.slice(cs, ce+2)
source.sub!(cr,'')
end
source.each_line.reject { |l| l.strip == "" }.join
end
File.open(path, "w") { |f| f.write sources.join("\n") }
logger.debug "JQuery Cached (%0.2fms) %s" % [Time.now-began_at, path] if defined?(logger)
end
libs = lib
end
javascript_include_tag(libs)
end
|