Comparing version 0.0.10 to 0.0.11
@@ -5,10 +5,8 @@ var Q = require('q'), | ||
PATH = require('./path'), | ||
INHERIT = require('inherit'), | ||
INHERIT = require('inherit'); | ||
Tech = exports.Tech = INHERIT({ | ||
exports.Tech = INHERIT({ | ||
__constructor: function() {}, | ||
createFile: function(path, type, parent) { | ||
return new this.File(this, path, type, parent) | ||
return new this.File(this, path, type, parent); | ||
}, | ||
@@ -32,11 +30,16 @@ | ||
parse: function(content) { | ||
return this.childType == 'include' ? | ||
this.parseInclude(content) : this.parseLink(content) | ||
return this.childType == 'include'? | ||
this.parseInclude(content) : this.parseLink(content); | ||
}, | ||
parseInclude: function(content) { return content }, | ||
parseInclude: function(content) { | ||
return content; | ||
}, | ||
parseLink: function(content) { return this.path }, | ||
parseLink: function(content) { | ||
return this.path; | ||
}, | ||
write: function(output) { | ||
var res = this.process(this.path); | ||
@@ -74,13 +77,16 @@ | ||
return defer.promise; | ||
}, | ||
process: function(path) { | ||
return this.childType == 'include' ? | ||
this.processInclude(path) : this.processLink(path) | ||
return this.childType == 'include'? | ||
this.processInclude(path) : this.processLink(path); | ||
}, | ||
processInclude: function(path) { return this.content }, | ||
processInclude: function(path) { | ||
return this.content; | ||
}, | ||
processLink: function(path) { | ||
return this.pathFrom(path) | ||
return this.pathFrom(path); | ||
}, | ||
@@ -94,7 +100,12 @@ | ||
pathTo: function(path) { return PATH.resolve(PATH.dirname(this.path), path) }, | ||
pathTo: function(path) { | ||
return PATH.resolve(PATH.dirname(this.path), path); | ||
}, | ||
pathFrom: function(path) { return PATH.relative(path, this.path) } | ||
pathFrom: function(path) { | ||
return PATH.relative(path, this.path); | ||
} | ||
}) | ||
}); |
var INHERIT = require('inherit'), | ||
base = require('../tech.js'), | ||
PATH = require('path'), | ||
FS = require('fs'), | ||
stringRe = "(?:(?:'[^'\\r\\n]*')|(?:\"[^\"\\r\\n]*\"))", | ||
@@ -14,10 +11,6 @@ urlRe = "(?:(?:url\\(\\s*" + stringRe + "\\s*\\))|(?:url\\(\\s*[^\\s\\r\\n'\"]*\\s*\\)))", | ||
Tech = exports.Tech = INHERIT(base.Tech, { | ||
exports.Tech = INHERIT(base.Tech, { | ||
File: INHERIT(base.File, { | ||
__constructor: function(tech, path, type, parent) { | ||
this.__base(tech, path, type, parent); | ||
this.root = PATH.dirname(path); | ||
}, | ||
parseInclude: function(content) { | ||
@@ -34,7 +27,7 @@ var m, found = []; | ||
var url = parseUrl(m[1]); | ||
if (isRelative(url)) found.push({ type: 'import', url: url, range: [ m.index, allRe.lastIndex ] }); | ||
if (isRelative(url)) found.push({ type: 'include', url: url, range: [ m.index, allRe.lastIndex ] }); | ||
} else if (urlStringRx.test(m[0])) { | ||
// url(...) | ||
var url = parseUrl(m[0]); | ||
if (isRelative(url)) found.push({ type: 'url', url: url, range: [ m.index, allRe.lastIndex-1 ] }); | ||
if (isRelative(url)) found.push({ type: 'link', url: url, range: [ m.index, allRe.lastIndex-1 ] }); | ||
} else { | ||
@@ -54,19 +47,13 @@ throw new Error('Failed to match: ' + m[0]); | ||
if (typeof item === 'string') { | ||
parsed[i] = item; | ||
if (typeof item === 'string') continue; | ||
if (item.type === 'include') { | ||
parsed[i] = '/* ' + item.url + ' begin */\n' + | ||
this.child('include', item.url).process(path) + | ||
'\n/* ' + item.url + ' end */\n'; | ||
continue; | ||
} | ||
var dir = PATH.dirname(path), | ||
url = item.url; | ||
url = PATH.resolve(dir, url); | ||
if (item.type === 'import') { | ||
var file = PATH.relative(this.root, url); | ||
parsed[i] = '/* ' + file + ' begin */\n' + | ||
this.processInclude(url, this.parseInclude(FS.readFileSync(url))) + | ||
'\n/* ' + file + ' end */\n'; | ||
} else if (item.type === 'url') { | ||
parsed[i] = 'url(' + PATH.relative(this.root, url) + ')'; | ||
} | ||
parsed[i] = this.child('link', item.url).process(path); | ||
} | ||
@@ -78,3 +65,3 @@ | ||
processLink: function(path) { | ||
return JSON.stringify(this.pathFrom(path)) | ||
return 'url(' + this.pathFrom(path) + ')'; | ||
} | ||
@@ -81,0 +68,0 @@ |
var INHERIT = require('inherit'), | ||
base = require('../tech.js'), | ||
path = require('path'), | ||
PATH = require('path'), | ||
util = require('util'), | ||
fs = require('fs'); | ||
Tech = exports.Tech = INHERIT(base.Tech, { | ||
exports.Tech = INHERIT(base.Tech, { | ||
File: INHERIT(base.File, { | ||
__constructor: function(tech, path, type, parent) { | ||
this.__base(tech, path, type, parent); | ||
}, | ||
parseInclude: function(content) { | ||
parseInclude: function(content) { | ||
var allIncRe = new RegExp( | ||
[ | ||
['/\\*!?', '\\*/'], | ||
['[\'"]', '[\'"]'] | ||
] | ||
var allIncRe = new RegExp([ | ||
['/\\*!?', '\\*/'], | ||
['[\'"]', '[\'"]'] | ||
] | ||
.map(function(i) { | ||
return ['(?:', i[0], '\\s*borschik:include:(.*?)\\s*', i[1], ')'].join('') | ||
}) | ||
.join('|'), | ||
'g'), | ||
return ['(?:', i[0], '\\s*borschik:include:(.*?)\\s*', i[1], ')'].join(''); | ||
}) | ||
.join('|'), 'g'), | ||
uniqStr = '\00borschik\00', | ||
@@ -30,14 +27,18 @@ _this = this; | ||
var incs = []; | ||
texts = content | ||
.replace(allIncRe, function(_, incCommFile, incStrFile) { | ||
var incFile = incCommFile || incStrFile, | ||
resultFile = path.join(path.dirname(_this.path), incFile); | ||
incs.push({ | ||
file: resultFile, | ||
type: incStrFile ? 'string' : 'comment' }); | ||
return uniqStr | ||
}) | ||
.split(uniqStr) | ||
var includes = [], | ||
texts = content | ||
.replace(allIncRe, function(_, incCommFile, incStrFile) { | ||
var incFile = incCommFile || incStrFile; | ||
includes.push({ | ||
file: _this.pathTo(incFile), | ||
type: incStrFile? 'string' : 'comment' | ||
}); | ||
return uniqStr; | ||
}) | ||
.split(uniqStr); | ||
// zip texts and includes | ||
@@ -47,6 +48,7 @@ var res = [], t, i; | ||
t && res.push(t); | ||
(i = incs.shift()) && res.push(i); | ||
(i = includes.shift()) && res.push(i); | ||
} | ||
return res | ||
return res; | ||
}, | ||
@@ -60,28 +62,16 @@ | ||
if(typeof item !== 'string') { | ||
if(path.existsSync(item.file)) { | ||
var processed = | ||
this.processInclude( | ||
item.file, | ||
this.parseInclude(fs.readFileSync(item.file))); | ||
if(typeof item === 'string') continue; | ||
parsed[i] = (item.type === 'comment' ? | ||
processed : | ||
JSON.stringify(processed)); | ||
} else { | ||
util.error('Base file: ' + baseFile); | ||
util.error('Include file: ' + item.file); | ||
throw 'File not exists' | ||
} | ||
if(!PATH.existsSync(item.file)) { | ||
throw new Error('File ' + item.file + ' does not exists, base file is ' + baseFile); | ||
} | ||
var processed = this.child('include', item.file).process(baseFile); | ||
parsed[i] = (item.type === 'comment'? processed : JSON.stringify(processed)); | ||
} | ||
return parsed.join(''); | ||
}, | ||
processLink: function(path) { | ||
return this.pathFrom(path); | ||
} | ||
}) | ||
}); | ||
}); |
{ | ||
"name": "borschik", | ||
"description": "Extendable builder for text-based file formats", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"homepage": "http://github.com/veged/borschik", | ||
@@ -24,3 +24,3 @@ "author": "Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)", | ||
"q-fs": "0.1", | ||
"cssp": "1.0.x" | ||
"cssp": "~1.0.5" | ||
}, | ||
@@ -39,2 +39,2 @@ "devDependencies": { | ||
"optionalDependencies": {} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
32445
20
659
Updatedcssp@~1.0.5