Module: Haml::More::Javascript::ClassMethods

Defined in:
lib/haml/more/javascript.rb

Constant Summary collapse

DEFAULTS =

here is an idea: map to hash, store in haml file

[
  # http://code.google.com/apis/ajaxlibs/documentation/
  # lib,            pattern,  v,  min
  [ :jquery,        :google,  1,  true  ],
  [ :jqueryui,      :google,  1,  true  ],
  [ :prototype,     :google,  1         ],
  [ :scriptaculous, :google,  1         ],
  [ :mootools,      :google,  1,  true  ],
  [ :dojo,          :google,  1,  true  ],
  [ :swfobject,     :google,  2,  true  ],
  [ :yui,           :google,  2,  true  ], # for 3.x, see below
  [ "ext-core",     :google,  3         ],
  [ :webfont,       :google,  1         ],

  # others
  [ "chrome-frame",   "http://ajax.googleapis.com/ajax/libs/chrome-frame/%V/CFInstall.min.js"             ],
  [ :modernizr,       "http://github.com/Modernizr/Modernizr/raw/v%V/modernizr.js",               '1.1'   ],
  [ :hyphenator,      "http://hyphenator.googlecode.com/svn/tags/Version%%20%V/Hyphenator.js",    '3.0.0' ],
  [ :yui3,            "http://yui.yahooapis.com/combo?%V/build/yui/yui-min.js",                   '3.1.1' ],
  [ :sizzle,          "http://github.com/jeresig/sizzle/raw/master/sizzle.js"                             ],
  [ :underscore,      "http://github.com/documentcloud/underscore/raw/%V/underscore-min.js",      '1.0.2' ],
  [ :raphael,         "http://github.com/DmitryBaranovskiy/raphael/raw/v%V/raphael-min.js",       '1.4.3' ],
  [ :cufon,           "http://cufon.shoqolate.com/js/cufon-yui.js"                                        ],
  [ "coffee-script",  "http://github.com/jashkenas/coffee-script/raw/%V/extras/coffee-script.js", '0.6.2' ],
  [ :sammy,           "http://github.com/quirkey/sammy/raw/v%V/lib/min/sammy-%V.min.js",          '0.5.4' ]
]

Instance Method Summary collapse

Instance Method Details

#included(klass) ⇒ Object



56
57
58
59
# File 'lib/haml/more/javascript.rb', line 56

def included(klass)
  klass.send :include, Haml::More::JavaScript::InstanceMethods
  super
end

#javascript_default_patternObject



61
62
63
# File 'lib/haml/more/javascript.rb', line 61

def javascript_default_pattern
  @javascript_default_pattern ||= Haml::More::JavaScript::Pattern.google
end

#javascript_guessing?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/haml/more/javascript.rb', line 65

def javascript_guessing?
  true
end

#javascript_url_for(name, version = nil, *args) ⇒ Object



69
70
71
72
# File 'lib/haml/more/javascript.rb', line 69

def javascript_url_for(name, version = nil, *args)
  return javascript_url_map[name] % [name, version, *args] if javascript_url_map.includes? name
  javascript_default_pattern % [name, version, *args] if javascript_guessing?
end

#javascript_url_mapObject



78
79
80
81
82
# File 'lib/haml/more/javascript.rb', line 78

def javascript_url_map
  return @javascript_url_map if @javascript_url_map
  @javascript_url_map = Hash.new { |h,k| h[k.to_s] unless k.respond_to? :to_str }
  DEFAULTS.each { |args| set_javascript(*args) }
end

#set_javascript(name, *args) ⇒ Object



74
75
76
# File 'lib/haml/more/javascript.rb', line 74

def set_javascript(name, *args)
  javascript_url_map[name.to_s] = Haml::More::JavaScript::Pattern.new(*args)
end