squish.lua: Support for AutoFetch to use file:// URLs

Tue, 30 Nov 2010 13:18:47 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 30 Nov 2010 13:18:47 +0000
changeset 81
44f2945d09cf
parent 80
b70f75414c81
child 82
4d6a976c3bb7

squish.lua: Support for AutoFetch to use file:// URLs

squish.lua file | annotate | diff | comparison | revisions
--- a/squish.lua	Tue Nov 09 20:41:21 2010 +0000
+++ b/squish.lua	Tue Nov 30 13:18:47 2010 +0000
@@ -225,8 +225,19 @@
 	print_debug("Packing "..modulename.." ("..path..")...");
 	local data, err = fetch.filesystem(path);
 	if (not data) and module.url then
-		print_debug("Fetching: ".. module.url:gsub("%?", module.path))
-		data, err = fetch.http(module.url:gsub("%?", module.path));
+		local url = module.url:gsub("%?", module.path);
+		print_debug("Fetching: ".. url)
+		if url:match("^https?://") then
+			data, err = fetch.http(url);
+		elseif url:match("^file://") then
+			local dataf, dataerr = io.open((url:gsub("^file://", "")));
+			if dataf then
+				data, err = dataf:read("*a");
+				dataf:close();
+			else
+				data, err = nil, dataerr;
+			end
+		end
 	end
 	if data then
 		f:write("package.preload['", modulename, "'] = (function (...)\n");

mercurial