Permalink
Browse files

ENYO-554: Modify loader to load and compile .less files from package.…

…js when the Less.js client-side library is present, otherwise falls back to loading same-named .css file.

Enyo-DCO-1.0-Signed-off-by: Kevin Schaaf <kevin.schaaf@palm.com>
  • Loading branch information...
1 parent 471d2ab commit 15eb0cfe3d01e0e3761a21e60370e0beb1f40f1c Kevin Schaaf committed Oct 9, 2012
Showing with 41 additions and 14 deletions.
  1. +8 −4 loader.js
  2. +33 −10 source/boot/boot.js
View
@@ -51,6 +51,7 @@
packageName: "",
packageFolder: "",
verbose: false,
+ finishCallbacks: {},
//
loadScript: function(inScript) {
this.machine.script(inScript);
@@ -102,8 +103,11 @@
finish: function() {
this.packageFolder = "";
this.verbose && console.log("-------------- fini");
- if (this.finishCallback) {
- this.finishCallback();
+ for (var i in this.finishCallbacks) {
+ if (this.finishCallbacks[i]) {
+ this.finishCallbacks[i]();
+ this.finishCallbacks[i] = null;
+ }
}
},
continueBlock: function(inBlock) {
@@ -132,7 +136,7 @@
// assemble path
path = prefix + path;
// process path
- if (path.slice(-4) == ".css") {
+ if ((path.slice(-4) == ".css") || (path.slice(-5) == ".less")) {
this.verbose && console.log("+ stylesheet: [" + prefix + "][" + inPath + "]");
this.requireStylesheet(path);
} else if (path.slice(-3) == ".js" && path.slice(-10) != "package.js") {
@@ -280,4 +284,4 @@
this.loadPackage(this.manifest);
}
};
-})();
+})();
View
@@ -1,16 +1,40 @@
// machine for a loader instance
enyo.machine = {
- sheet: function(s) {
+ sheet: function(inPath) {
+ var type = "text/css";
+ var rel = "stylesheet";
+ var isLess = (inPath.slice(-5) == ".less");
+ if (isLess) {
+ if (window.less) {
+ // If client-side less is loaded, insert the less stylesheet
+ type = "text/less";
+ rel = "stylesheet/less";
+ } else {
+ // Otherwise, we expect a css file of the same name to exist
+ inPath = inPath.slice(0, inPath.length-4) + "css";
+ }
+ }
+ var link;
+ if (enyo.runtimeLoading || isLess) {
+ link = document.createElement('link');
+ link.href = inPath;
+ link.media = "screen";
+ link.rel = rel;
+ link.type = type;
+ }
if (!enyo.runtimeLoading) {
- document.write('<link href="' + s + '" media="screen" rel="stylesheet" type="text/css" />');
+ document.write('<link href="' + inPath + '" media="screen" rel="' + rel + '" type="' + type + '" />');
} else {
- var link = document.createElement('link');
- link.href = s;
- link.media = "screen";
- link.rel = "stylesheet";
- link.type = "text/css";
document.getElementsByTagName('head')[0].appendChild(link);
}
+ if (isLess && window.less) {
+ less.sheets.push(link);
+ if (!enyo.loader.finishCallbacks.lessRefresh) {
+ enyo.loader.finishCallbacks.lessRefresh = function() {
+ less.refresh(true);
+ }
+ }
+ }
},
script: function(inSrc, onLoad, onError) {
if (!enyo.runtimeLoading) {
@@ -69,7 +93,7 @@ enyo.depends = function() {
var depends = args[0];
var dependsArg = enyo.isArray(depends) ? depends : [depends];
var onLoadCallback = args[1];
- enyo.loader.finishCallback = function() {
+ enyo.loader.finishCallbacks.runtimeLoader = function() {
// Once loader is done loading a package, we chain a call to runtimeLoad(),
// which will call the onLoadCallback from the original load call, passing
// a reference to the depends argument from the original call for tracking,
@@ -83,7 +107,6 @@ enyo.depends = function() {
enyo.depends.apply(this, dependsArg);
} else {
enyo.runtimeLoading = false;
- enyo.loader.finishCallback = null;
enyo.loader.packageFolder = "";
}
}
@@ -93,4 +116,4 @@ enyo.depends = function() {
enyo.path.addPaths({
enyo: enyo.args.root,
lib: "$enyo/../lib"
-});
+});

0 comments on commit 15eb0cf

Please sign in to comment.