-
Notifications
You must be signed in to change notification settings - Fork 3
/
assets.rb
34 lines (29 loc) · 867 Bytes
/
assets.rb
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
require 'sprockets'
require 'yui/compressor'
class Assets < Sinatra::Base
configure do
set :assets, (Sprockets::Environment.new { |env|
env.append_path(settings.root + "/app/public/img")
env.append_path(settings.root + "/app/public/js")
env.append_path(settings.root + "/app/public/css")
if ENV["RACK_ENV"] == "production"
env.js_compressor = YUI::JavaScriptCompressor.new
env.css_compressor = YUI::CssCompressor.new
end
})
end
get "/assets/app.js" do
content_type("application/javascript")
settings.assets["app.js"]
end
get "/assets/app.css" do
content_type("text/css")
settings.assets["app.css"]
end
%w{jpg png}.each do |format|
get "/assets/:image.#{format}" do |image|
content_type("image/#{format}")
settings.assets["#{image}.#{format}"]
end
end
end