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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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
 
module StyleSheets
def css *files
@css ||= []
@css = files
end
 
def styles(*args)
css = []
css << settings.css if settings.respond_to?('css')
css << args
css << @css if @css
css.flatten.uniq.map do |stylesheet|
"<link href=\"/#{stylesheet}.css\" media=\"screen, projection\" rel=\"stylesheet\" />"
end.join
end
end
 
helpers JavaScripts, StyleSheets
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.