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
|
# File 'lib/highcarb/assets_controller.rb', line 6
def assets(asset)
if asset.include?("/../")
plain_response! 403, "URL can not contain /../"
end
asset_path = assets_root.join("./" + asset)
if not asset_path.exist?
not_found! asset
end
if not asset_path.file?
plain_response! 403, "#{asset} is not a file"
end
output = nil
mime_type = nil
if asset_path.extname == ".scss"
output = Sass::Engine.for_file(asset_path.to_s, {}).render
mime_type = "text/css"
end
if asset_path.extname == ".coffee"
output = CoffeeScript.compile(asset_path.read)
mime_type = "application/javascript"
end
if output == nil
mime_type = MIME::Types.type_for(asset_path.to_s).first || "application/octet-stream"
output = asset_path.read
end
[
200,
{ "Content-Type" => mime_type.to_s },
output
]
end
|