Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 15eb0cfe3d01e0e3761a21e60370e0beb1f40f1c 1 parent 471d2ab
authored October 09, 2012
12  loader.js
@@ -51,6 +51,7 @@
51 51
 		packageName: "",
52 52
 		packageFolder: "",
53 53
 		verbose: false,
  54
+		finishCallbacks: {},
54 55
 		//
55 56
 		loadScript: function(inScript) {
56 57
 			this.machine.script(inScript);
@@ -102,8 +103,11 @@
102 103
 		finish: function() {
103 104
 			this.packageFolder = "";
104 105
 			this.verbose && console.log("-------------- fini");
105  
-			if (this.finishCallback) {
106  
-				this.finishCallback();
  106
+			for (var i in this.finishCallbacks) {
  107
+				if (this.finishCallbacks[i]) {
  108
+					this.finishCallbacks[i]();
  109
+					this.finishCallbacks[i] = null;
  110
+				}
107 111
 			}
108 112
 		},
109 113
 		continueBlock: function(inBlock) {
@@ -132,7 +136,7 @@
132 136
 			// assemble path
133 137
 			path = prefix + path;
134 138
 			// process path
135  
-			if (path.slice(-4) == ".css") {
  139
+			if ((path.slice(-4) == ".css") || (path.slice(-5) == ".less")) {
136 140
 				this.verbose && console.log("+ stylesheet: [" + prefix + "][" + inPath + "]");
137 141
 				this.requireStylesheet(path);
138 142
 			} else if (path.slice(-3) == ".js" && path.slice(-10) != "package.js") {
@@ -280,4 +284,4 @@
280 284
 			this.loadPackage(this.manifest);
281 285
 		}
282 286
 	};
283  
-})();
  287
+})();
43  source/boot/boot.js
... ...
@@ -1,16 +1,40 @@
1 1
 // machine for a loader instance
2 2
 enyo.machine = {
3  
-	sheet: function(s) {
  3
+	sheet: function(inPath) {
  4
+		var type = "text/css";
  5
+		var rel = "stylesheet";
  6
+		var isLess = (inPath.slice(-5) == ".less");
  7
+		if (isLess) {
  8
+			if (window.less) {
  9
+				// If client-side less is loaded, insert the less stylesheet
  10
+				type = "text/less";
  11
+				rel = "stylesheet/less";
  12
+			} else {
  13
+				// Otherwise, we expect a css file of the same name to exist
  14
+				inPath = inPath.slice(0, inPath.length-4) + "css";
  15
+			}
  16
+		}
  17
+		var link;
  18
+		if (enyo.runtimeLoading || isLess) {
  19
+			link = document.createElement('link');
  20
+			link.href = inPath;
  21
+			link.media = "screen";
  22
+			link.rel = rel;
  23
+			link.type = type;
  24
+		}
4 25
 		if (!enyo.runtimeLoading) {
5  
-			document.write('<link href="' + s + '" media="screen" rel="stylesheet" type="text/css" />');
  26
+			document.write('<link href="' + inPath + '" media="screen" rel="' + rel + '" type="' + type + '" />');
6 27
 		} else {
7  
-			var link = document.createElement('link');
8  
-			link.href = s;
9  
-			link.media = "screen";
10  
-			link.rel = "stylesheet";
11  
-			link.type = "text/css";
12 28
 			document.getElementsByTagName('head')[0].appendChild(link);
13 29
 		}
  30
+		if (isLess && window.less) {
  31
+			less.sheets.push(link);
  32
+			if (!enyo.loader.finishCallbacks.lessRefresh) {
  33
+				enyo.loader.finishCallbacks.lessRefresh = function() {
  34
+					less.refresh(true);
  35
+				}
  36
+			}
  37
+		}
14 38
 	},
15 39
 	script: function(inSrc, onLoad, onError) {
16 40
 		if (!enyo.runtimeLoading) {
@@ -69,7 +93,7 @@ enyo.depends = function() {
69 93
 			var depends = args[0];
70 94
 			var dependsArg = enyo.isArray(depends) ? depends : [depends];
71 95
 			var onLoadCallback = args[1];
72  
-			enyo.loader.finishCallback = function() {
  96
+			enyo.loader.finishCallbacks.runtimeLoader = function() {
73 97
 				// Once loader is done loading a package, we chain a call to runtimeLoad(),
74 98
 				// which will call the onLoadCallback from the original load call, passing
75 99
 				// a reference to the depends argument from the original call for tracking,
@@ -83,7 +107,6 @@ enyo.depends = function() {
83 107
 			enyo.depends.apply(this, dependsArg);
84 108
 		} else {
85 109
 			enyo.runtimeLoading = false;
86  
-			enyo.loader.finishCallback = null;
87 110
 			enyo.loader.packageFolder = "";
88 111
 		}
89 112
 	}
@@ -93,4 +116,4 @@ enyo.depends = function() {
93 116
 enyo.path.addPaths({
94 117
 	enyo: enyo.args.root,
95 118
 	lib: "$enyo/../lib"
96  
-});
  119
+});

0 notes on commit 15eb0cf

Please sign in to comment.
Something went wrong with that request. Please try again.