Skip to content

Instantly share code, notes, and snippets.

@negipo
Created November 29, 2011 01:30
Show Gist options
  • Save negipo/1402933 to your computer and use it in GitHub Desktop.
Save negipo/1402933 to your computer and use it in GitHub Desktop.
allows dotjs to describe globs as '_'
index 5d256ab..5924648 100755
--- a/bin/djsd
+++ b/bin/djsd
@@ -15,12 +15,19 @@ require 'webrick'
dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
def do_GET(request, response)
- file = File.expand_path("#{request.path.gsub('/','')}")
+ path = request.path.gsub('/','')
+ files = Dir.glob('*.js').select do |file_name|
+ path.match(Regexp.new(file_name.gsub(/_/, '.*') + '$'))
+ end.map do |file_name|
+ File.expand_path("#{file_name}")
+ end
default = File.expand_path("default.js")
body = "// dotjs is working! //\n"
body << File.read(default) + "\n" if File.file?(default)
- body << File.read(file) if File.file?(file)
+ files.each do |file|
+ body << File.read(file)
+ end
response.status = body.empty? ? 204 : 200
if origin = detect_origin(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment