Skip to content
This repository
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor

Showing 2 changed files with 54 additions and 12 deletions. Show diff stats Hide diff stats

  1. +44 6 build.js
  2. +10 6 build/amd-css.js
50 build.js
@@ -40,7 +40,20 @@ if(typeof define == 'undefined'){
40 40 fs = fsModule;
41 41 pathModule = {
42 42 resolve: function(base, target){
43   - return base.replace(/[^\/]+$/, '') + target;
  43 + return (base.replace(/[^\/]+$/, '') + target)
  44 + .replace(/\/[^\/]*\/\.\./g, '')
  45 + .replace(/\/\./g,'');
  46 + },
  47 + dirname: function(path){
  48 + return path.replace(/[\/\\][^\/\\]*$/, '');
  49 + },
  50 + relative: function(basePath, path){
  51 + return path.slice(this.dirname(basePath).length + 1);
  52 + },
  53 + join: function(base, target){
  54 + return ((base[base.length - 1] == '/' ? base : (base + '/'))+ target)
  55 + .replace(/\/[^\/]*\/\.\./g, '')
  56 + .replace(/\/\./g,'');
44 57 }
45 58 }
46 59 return function(xstyleText){
@@ -72,13 +85,37 @@ function minify(cssText){
72 85 replace(/\/\*([^\*]|\*[^\/])*\*\//g, ' ').
73 86 replace(/\s*("(\\\\|[^\"])*"|'(\\\\|[^\'])*'|[;}{:])\s*/g,"$1");
74 87 }
75   -function processCss(cssText,basePath){
  88 +var mimeTypes = {
  89 + eot: "application/vnd.ms-fontobject",
  90 + woff: "application/font-woff",
  91 + gif: "image/gif",
  92 + jpg: "image/jpeg",
  93 + jpeg: "image/jpeg",
  94 + png: "image/png"
  95 +}
  96 +function processCss(cssText, basePath, inlineAllResources){
  97 + console.log("processing",basePath);
76 98 function insertRule(cssText){
77 99 //browserCss.push(cssText);
78 100 }
79 101 function correctUrls(cssText, path){
80   - var relativePath = pathModule.relative(basePath, pathModule.dirname(path));
81   - return cssText.replace(/url\s*\(['"]?([^'"\)]*)['"]?\)/g, function(t, url){
  102 + // correct all the URLs in the stylesheets
  103 + // determine the directory path
  104 + path = pathModule.dirname(path) + '/';
  105 + //console.log("starting path", basePath , path);
  106 + // compute the relative path from where we are to the base path where the stylesheet will go
  107 + var relativePath = pathModule.relative(basePath, path);
  108 + return cssText.replace(/url\s*\(\s*['"]?([^'"\)]*)['"]?\s*\)/g, function(t, url){
  109 + //console.log("relativePath", relativePath, pathModule.resolve(path, url), pathModule.join(relativePath, url));
  110 + if(inlineAllResources || /#inline$/.test(url)){
  111 + // we can inline the resource
  112 + suffix = url.match(/\.(\w+)(#|\?|$)/);
  113 + suffix = suffix && suffix[1];
  114 + url = url.replace(/[\?#].*/,'');
  115 + return 'url(data:' + (mimeTypes[suffix] || 'application/octet-stream') +
  116 + ';base64,' + fs.readFileSync(pathModule.resolve(path, url)).toString("base64") + ')';
  117 + }
  118 + // or we adjust the URL
82 119 return 'url("' + pathModule.join(relativePath, url).replace(/\\/g, '/') + '")';
83 120 });
84 121 }
@@ -98,7 +135,7 @@ function processCss(cssText,basePath){
98 135 cssRules: []
99 136 }
100 137 };
101   - var browserCss = [];
  138 + var browserCss = [cssText];
102 139 var xstyleCss = [];
103 140 var rootRule = xstyle.parse(cssText, {href:basePath || '.', cssRules:[], insertRule: insertRule});
104 141 var intrinsicVariables = {
@@ -109,7 +146,7 @@ function processCss(cssText,basePath){
109 146 prefixed: 1
110 147 }
111 148 function visit(parent){
112   - browserCss.push(parent.selector + '{' + parent.cssText + '}');
  149 + //browserCss.push(parent.selector + '{' + parent.cssText + '}');
113 150 for(var i in parent.variables){
114 151 if(!intrinsicVariables.hasOwnProperty(i)){
115 152 xstyleCss.push(i,'=',parent.variables[i]);
@@ -117,6 +154,7 @@ function processCss(cssText,basePath){
117 154 }
118 155 }
119 156 visit(rootRule);
  157 + //console.log('browserCss', browserCss);
120 158 return {
121 159 standardCss: minify(browserCss.join('')),
122 160 xstyleCss: xstyleCss.join(';'),
16 build/amd-css.js
@@ -41,7 +41,7 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
41 41 var createStyleSheetModule = bc.getSrcModuleInfo('xstyle/util/createStyleSheet', referenceModule);
42 42 }
43 43 // read the stylesheet so we can process
44   - var text= fs.readFileSync(stylesheetInfo.src, "utf8");
  44 + //var text= fs.readFileSync(stylesheetInfo.src, "utf8");
45 45
46 46 if (!cssPlugin){
47 47 throw new Error("text! plugin missing");
@@ -57,7 +57,7 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
57 57 }
58 58 if(targetStylesheetUrl){
59 59 // accumulate all the stylesheets in our target stylesheet
60   - var processed = processCss(cssResource);
  60 + var processed = processCss(cssResource);//, targetStylesheetUrl);
61 61 targetStylesheetContents += processed.standardCss;
62 62 referenceModule.layer.targetStylesheetContents = targetStylesheetContents;
63 63 }
@@ -69,7 +69,7 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
69 69 mid:stylesheetInfo.mid,
70 70 deps:[],
71 71 getText:function(){
72   - var processed = processCss(this.module);
  72 + var processed = this.processed = processCss(this.module, true);//stylesheetInfo.url, // inline resources too
73 73 return processed.xstyleCss ?
74 74 json.stringify({
75 75 cssText: processed.standardCss,
@@ -78,17 +78,21 @@ define(["dojo/json", "build/fs", "../build"], function(json, fs, buildModule){
78 78 json.stringify(processed.standardCss +"");
79 79 },
80 80 internStrings:function(){
81   - return ["url:" + this.mid, this.getText()];
  81 + if(!this.processed){
  82 + return ["url:" + this.mid, this.getText()];
  83 + }else{
  84 + return '';
  85 + }
82 86 }
83 87 });
84 88 }
85   - function processCss(module){
  89 + function processCss(module, inlineAllResource){
86 90 var text = module.getText ? module.getText() : module.text;
87 91 if(text===undefined){
88 92 // the module likely did not go through the read transform; therefore, just read it manually
89 93 text= fs.readFileSync(this.module.src, "utf8");
90 94 }
91   - var processed = xstyleProcess(text, stylesheetInfo.url);
  95 + var processed = xstyleProcess(text, stylesheetInfo.url, inlineAllResource);
92 96 //for(var i = 0; i < processed.requiredModules.length; i++){
93 97 // TODO: at some point, we may add an option to include the modules that
94 98 // 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.