Permalink
Browse files

Add support for 'default.css'

This allows for general styles to be applied to every site. To get
this working, run the rake uninstall/rake install commands.

Closes #6.
  • Loading branch information...
1 parent 4f0b9c3 commit d28f1bd3fbf4ab95516be0120adca8533431bc75 @stewart committed Nov 7, 2012
Showing with 22 additions and 5 deletions.
  1. +22 −5 bin/dcssd
View
@@ -7,7 +7,7 @@ if (%w( -h --help -help help ) & ARGV).length > 0
end
if ARGV.include?('-v')
- puts 'dcssd 1.0'
+ puts 'dcssd 1.1'
exit
end
@@ -19,20 +19,37 @@ require "webrick"
dotcss = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
def do_GET(request, response)
- file = File.expand_path("#{request.path.gsub('/','')}")
- body = "/* dotcss is working */\n"
- body << File.read(file) if File.file?(file)
+ body = build_body(request.path)
response.status = body.empty? ? 204 : 200
if origin = detect_origin(request)
response['Access-Control-Allow-Origin'] = origin
end
- response['Content-Type'] = 'text/javascript'
+ response['Content-Type'] = 'text/css'
response.body = body
end
+ def build_body(path)
+ files = [File.expand_path('default.css')]
+ paths = path.gsub('/', '').split('.')
+
+ until paths.empty?
+ file = File.expand_path(paths.join('.'))
+ files << file if File.file?(file)
+ paths.shift
+ end
+
+ body = "/* dotcss is working */\n"
+
+ files.each do |file|
+ body << File.read(file) + "\n" if File.file?(file)
+ end
+
+ body
+ end
+
def detect_origin(req)
path = req.path
origin = req.header['origin']

0 comments on commit d28f1bd

Please sign in to comment.