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
@@ -1,6 +1,7 @@
var url = require('url'), var url = require('url'),
http = require('http'), http = require('http'),
fs = require('fs'), fs = require('fs'),
sys = require('sys'),
getopts = require('./getopts.js').getopts, getopts = require('./getopts.js').getopts,
opts = getopts(process.argv.slice(2, process.argv.length), opts = getopts(process.argv.slice(2, process.argv.length),
['--version', '-v', ['--version', '-v',
Expand Down Expand Up @@ -42,7 +43,13 @@ exports.main = function() {


function encodeImages(src, callback) { function encodeImages(src, callback) {
var reUrl = /url\(\s*["']?([^)]+?)["']?\s*\)/gi, 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)) { while (url = reUrl.exec(src)) {
(function(url) { (function(url) {
Expand All @@ -59,18 +66,18 @@ function encodeImages(src, callback) {
} }


function encodeImage(uri, callback) { function encodeImage(uri, callback) {
var normUri = '', var reHTTP = /^https?/i,
reHTTP = /^https?/; normUri = '';


if (uri.length && uri.substr(0, 5) != 'data:') { if (uri.length && uri.substr(0, 5) != 'data:') {
if (uri.substr(0, 2) == '//') { if (uri.substr(0, 2) == '//') {
normUri = 'http:' + uri; getViaHTTP('http:' + uri, callback)
} else if (reHTTP.test(uri)) { } else if (reHTTP.test(uri)) {
normUri = uri; getViaHTTP(uri, callback);
} else { } else {
normUri = baseUrl ? url.resolve(baseUrl, uri) : uri; 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 { } else {
callback && callback(); callback && callback();
} }
Expand Down Expand Up @@ -151,5 +158,5 @@ function getViaFS(uri, callback) {
} }


function printFile(filename) { 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.