Skip to content

Commit

Permalink
0.1.1 bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Panya committed Aug 31, 2011
1 parent 3ec3462 commit 277114f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/durilka.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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.