Module: Padrino::Contrib::Helpers::JQuery::Helpers

Defined in:
lib/padrino-contrib/helpers/jquery.rb

Instance Method Summary collapse

Instance Method Details

#javascript_include_tag_jquery(options = {}) ⇒ Object



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/1.6.2/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
        # Removes extra comments
        if cs = source =~ /\/\*\!/
          cr = source.slice(cs, source.length)
          ce = cr =~ /\*\//
          cr = source.slice(cs, ce+2)
          source.sub!(cr,'')
        end
        # Removes empty lines
        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


17
18
19
20
21
22
# File 'lib/padrino-contrib/helpers/jquery.rb', line 17

def stylesheet_link_tag_jquery(options={})
  theme = options.delete(:theme) || :smoothness
  version = options.delete(:version) || '1.8.16'

  stylesheet_link_tag('http://ajax.googleapis.com/ajax/libs/jqueryui/%s/themes/%s/jquery-ui.css' % [version, theme], options)
end