public
Last active

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require 'sinatra/base'
 
module Sinatra
module JavaScripts
def js *scripts
@js ||= []
@js = scripts
end
 
def javascripts(*args)
js = []
js << settings.javascripts if settings.respond_to?('javascripts')
js << args
js << @js if @js
js.flatten.uniq.map do |script|
"<script src=\"#{path_to script}\"></script>"
end.join
end
 
def path_to script
case script
when :jquery then 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'
when :rightjs then 'http://cdn.rightjs.org/right-2.3.0.js'
when :backbone then 'http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.0/backbone-min.js'
when :underscore then 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js'
else script.to_s + '.js'
end
end
end
 
helpers JavaScripts
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.