Skip to content

Instantly share code, notes, and snippets.

@sinefunc
Created October 22, 2010 14:29
Show Gist options
  • Save sinefunc/640631 to your computer and use it in GitHub Desktop.
Save sinefunc/640631 to your computer and use it in GitHub Desktop.
# Sinatra helper for jQuery.
# Usage:
# Instead of doing <script src="/js/jquery.js">, use:
#
# <%= jquery %>
#
class Main
helpers do
def jquery(path='/js/jquery.js', version='1.4.3')
if settings.production?
# Grab Google CDN's jQuery; fallback to local if necessary
"<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js\"></script>"+
"<script>!window.jQuery && document.write('<script src=\"#{path}\"><\\/script>')</script>"
else
"<script src='#{path}'></script>"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment