Permalink
Browse files

0.1.1 bugfixes

  • Loading branch information...
1 parent 3ec3462 commit 277114f564e766059c724b753f90489fc79295fd @Panya committed Aug 31, 2011
Showing with 14 additions and 7 deletions.
  1. +14 −7 lib/durilka.js
View
@@ -1,6 +1,7 @@
var url = require('url'),
http = require('http'),
fs = require('fs'),
+ sys = require('sys'),
getopts = require('./getopts.js').getopts,
opts = getopts(process.argv.slice(2, process.argv.length),
['--version', '-v',
@@ -42,7 +43,13 @@ exports.main = function() {
function encodeImages(src, callback) {
var reUrl = /url\(\s*["']?([^)]+?)["']?\s*\)/gi,
- len = src.match(reUrl).length, url;
+ urls = src.match(reUrl),
+ len = urls && urls.length, url;
+
+ if (!len) {
+ callback && callback(src);
+ return;
+ }
while (url = reUrl.exec(src)) {
(function(url) {
@@ -59,18 +66,18 @@ function encodeImages(src, callback) {
}
function encodeImage(uri, callback) {
- var normUri = '',
- reHTTP = /^https?/;
+ var reHTTP = /^https?/i,
+ normUri = '';
if (uri.length && uri.substr(0, 5) != 'data:') {
if (uri.substr(0, 2) == '//') {
- normUri = 'http:' + uri;
+ getViaHTTP('http:' + uri, callback)
} else if (reHTTP.test(uri)) {
- normUri = uri;
+ getViaHTTP(uri, callback);
} else {
normUri = baseUrl ? url.resolve(baseUrl, uri) : uri;
+ reHTTP.test(normUri) ? getViaHTTP(normUri, callback) : getViaFS(normUri, callback);
}
- reHTTP.test(normUri) ? getViaHTTP(normUri, callback) : getViaFS(normUri, callback);
} else {
callback && callback();
}
@@ -151,5 +158,5 @@ function getViaFS(uri, callback) {
}
function printFile(filename) {
- console.log(fs.readFileSync(__dirname.slice(0, __dirname.lastIndexOf('/')) + '/' + filename).toString());
+ sys.print(fs.readFileSync(__dirname.slice(0, __dirname.lastIndexOf('/')) + '/' + filename).toString());
}

0 comments on commit 277114f

Please sign in to comment.