Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 54 additions and 12 deletions.
  1. +44 −6 build.js
  2. +10 −6 build/amd-css.js
50 build.js
View
@@ -40,7 +40,20 @@ if(typeof define == 'undefined'){
fs = fsModule;
pathModule = {
resolve: function(base, target){
- return base.replace(/[^\/]+$/, '') + target;
+ return (base.replace(/[^\/]+$/, '') + target)
+ .replace(/\/[^\/]*\/\.\./g, '')
+ .replace(/\/\./g,'');
+ },
+ dirname: function(path){
+ return path.replace(/[\/\\][^\/\\]*$/, '');
+ },
+ relative: function(basePath, path){
+ return path.slice(this.dirname(basePath).length + 1);
+ },
+ join: function(base, target){
+ return ((base[base.length - 1] == '/' ? base : (base + '/'))+ target)
+ .replace(/\/[^\/]*\/\.\./g, '')
+ .replace(/\/\./g,'');
}
}
return function(xstyleText){
@@ -72,13 +85,37 @@ function minify(cssText){
replace(/\/\*([^\*]|\*[^\/])*\*\//g, ' ').
replace(/\s*("(\\\\|[^\"])*"|'(\\\\|[^\'])*'|[;}{:])\s*/g,"$1");
}
-function processCss(cssText,basePath){
+var mimeTypes = {
+ eot: "application/vnd.ms-fontobject",
+ woff: "application/font-woff",
+ gif: "image/gif",
+ jpg: "image/jpeg",
+ jpeg: "image/jpeg",
+ png: "image/png"
+}
+function processCss(cssText, basePath, inlineAllResources){
+ console.log("processing",basePath);
function insertRule(cssText){
//browserCss.push(cssText);
}
function correctUrls(cssText, path){
- var relativePath = pathModule.relative(basePath, pathModule.dirname(path));
- return cssText.replace(/url\s*\(['"]?([^'"\)]*)['"]?\)/g, function(t, url){
+ // correct all the URLs in the stylesheets
+ // determine the directory path
+ path = pathModule.dirname(path) + '/';
+ //console.log("starting path", basePath , path);
+ // compute the relative path from where we are to the base path where the stylesheet will go
+ var relativePath = pathModule.relative(basePath, path);
+ return cssText.replace(/url\s*\(\s*['"]?([^'"\)]*)['"]?\s*\)/g, function(t, url){
+ //console.log("relativePath", relativePath, pathModule.resolve(path, url), pathModule.join(relativePath, url));
+ if(inlineAllResources || /#inline$/.test(url)){
+ // we can inline the resource
+ suffix = url.match(/\.(\w+)(#|\?|$)/);
+ suffix = suffix && suffix[1];
+ url = url.replace(/[\?#].*/,'');
+ return 'url(data:' + (mimeTypes[suffix] || 'application/octet-stream') +
+ ';base64,' + fs.readFileSync(pathModule.resolve(path, url)).toString("base64") + ')';
+ }
+ // or we adjust the URL
return 'url("' + pathModule.join(relativePath, url).replace(/\\/g, '/') + '")';
});
}
@@ -98,7 +135,7 @@ function processCss(cssText,basePath){
cssRules: []
}
};
- var browserCss = [];
+ var browserCss = [cssText];
var xstyleCss = [];
var rootRule = xstyle.parse(cssText, {href:basePath || '.', cssRules:[], insertRule: insertRule});
var intrinsicVariables = {
@@ -109,7 +146,7 @@ function processCss(cssText,basePath){
prefixed: 1
}
function visit(parent){
- browserCss.push(parent.selector + '{' + parent.cssText + '}');
+ //browserCss.push(parent.selector + '{' + parent.cssText + '}');
for(var i in parent.variables){
if(!intrinsicVariables.hasOwnProperty(i)){
xstyleCss.push(i,'=',parent.variables[i]);
@@ -117,6 +154,7 @@ function processCss(cssText,basePath){
}
}
visit(rootRule);
+ //console.log('browserCss', browserCss);
return {
standardCss: minify(browserCss.join('')),
xstyleCss: xstyleCss.join(';'),
16 build/amd-css.js
View
@@ -41,7 +41,7 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
var createStyleSheetModule = bc.getSrcModuleInfo('xstyle/util/createStyleSheet', referenceModule);
}
// read the stylesheet so we can process
- var text= fs.readFileSync(stylesheetInfo.src, "utf8");
+ //var text= fs.readFileSync(stylesheetInfo.src, "utf8");
if (!cssPlugin){
throw new Error("text! plugin missing");
@@ -57,7 +57,7 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
}
if(targetStylesheetUrl){
// accumulate all the stylesheets in our target stylesheet
- var processed = processCss(cssResource);
+ var processed = processCss(cssResource);//, targetStylesheetUrl);
targetStylesheetContents += processed.standardCss;
referenceModule.layer.targetStylesheetContents = targetStylesheetContents;
}
@@ -69,7 +69,7 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
mid:stylesheetInfo.mid,
deps:[],
getText:function(){
- var processed = processCss(this.module);
+ var processed = this.processed = processCss(this.module, true);//stylesheetInfo.url, // inline resources too
return processed.xstyleCss ?
json.stringify({
cssText: processed.standardCss,
@@ -78,17 +78,21 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
json.stringify(processed.standardCss +"");
},
internStrings:function(){
- return ["url:" + this.mid, this.getText()];
+ if(!this.processed){
+ return ["url:" + this.mid, this.getText()];
+ }else{
+ return '';
+ }
}
});
}
- function processCss(module){
+ function processCss(module, inlineAllResource){
var text = module.getText ? module.getText() : module.text;
if(text===undefined){
// the module likely did not go through the read transform; therefore, just read it manually
text= fs.readFileSync(this.module.src, "utf8");
}
- var processed = xstyleProcess(text, stylesheetInfo.url);
+ var processed = xstyleProcess(text, stylesheetInfo.url, inlineAllResource);
//for(var i = 0; i < processed.requiredModules.length; i++){
// TODO: at some point, we may add an option to include the modules that
// are required by the stylesheet, but at least by default these should

No commit comments for this range

Something went wrong with that request. Please try again.