From faa29901059932072c2be71afd5c4dfc5827da4e Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 10 Mar 2011 18:35:13 -0600 Subject: [PATCH 1/2] singular --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index c478e22..7f3e785 100644 --- a/README.markdown +++ b/README.markdown @@ -85,4 +85,4 @@ whichever is your favorite. ## Other Browers - [Firefox Add-on](https://github.com/rlr/dotjs-addon) -- [Safari Extensions](https://github.com/wfarr/dotjs.safariextension) +- [Safari Extension](https://github.com/wfarr/dotjs.safariextension) From 8853e8642b278bd058ee28f9aa1a14c7b5627a17 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 11 Mar 2011 00:13:01 -0500 Subject: [PATCH 2/2] Add CoffeeScript support ~/.js/website.com.coffee --- bin/djsd | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/bin/djsd b/bin/djsd index fe22a52..71cb89c 100755 --- a/bin/djsd +++ b/bin/djsd @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# -*- coding: utf-8 -*- if (%w( -h --help -help help ) & ARGV).length > 0 puts "usage: djsd [-hv]" @@ -15,18 +16,39 @@ require 'webrick' dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do def do_GET(request, response) - file = File.expand_path("~/.js/#{request.path.gsub('/','')}") - default = File.expand_path("~/.js/default.js") - body = '' - body << File.read(default) + "\n" if File.exists?(default) - body << File.read(file) if File.exists?(file) + body << js('default.js') + body << js(request.path.to_s.gsub('/','')) response.status = body.empty? ? 204 : 200 response['Access-Control-Allow-Origin'] = '*' response['Content-Type'] = 'text/javascript' response.body = body end + + def js(path) + if File.exists? path = File.expand_path("~/.js/#{path}") + File.read(path) + ";\n" + elsif File.exists? path = path.sub(/js$/, 'coffee') + coffee(path) + else + '' + end + end + + def coffee(path) + js = `coffee -bp #{path} 2>&1` + + case $?.exitstatus + when 0 + js + when 127 + "console.error('dotjs — `coffee\\' executable not found');" + else + error = js.split("\n").first + "console.error('dotjs — %s', #{error.inspect});" + end + end end server = WEBrick::HTTPServer.new(:Port => 3131)