Permalink
Browse files

add support for node.js exports and jslint

  • Loading branch information...
1 parent 74bf126 commit 378b926319e05caf3e4a23745d8014daf9cd7999 @pure committed Nov 21, 2010
Showing with 106 additions and 67 deletions.
  1. +1 −1 index.html
  2. 0 index.js
  3. +51 −51 js/{index.js → demo.js}
  4. +20 −15 libs/pure.js
  5. +13 −0 node/test.js
  6. +21 −0 package.json
View
@@ -11,7 +11,7 @@
<script src="libs/pure.js"></script>
<!-- Example page files -->
- <script src="js/index.js"></script>
+ <script src="js/demo.js"></script>
<script src="js/examples.js"></script>
</head>
<body>
View
No changes.
View
@@ -67,7 +67,7 @@ var loadLib, runAll, run, transform;
}else{
span = h.nextSibling;
}
- var cn = lis[i].className;
+ cn = lis[i].className;
window[cn].id = cn;
span.id = cn;
span.innerHTML =
@@ -168,59 +168,59 @@ var loadLib, runAll, run, transform;
transform = function(ex, debug){
var template;
if(typeof ex === 'function'){
- return ex();
- }
-
- switch(currLib){
- case 'domassistant':
- case 'jquery':
- template = $( ex.template );
- break;
- case 'mootools':
- template = $(document).getElement( ex.template );
- case 'prototype':
- template = $$( ex.template )[0];
- default:
- template = $p( ex.template );
- }
+ ex();
+ }else{
+ switch(currLib){
+ case 'domassistant':
+ case 'jquery':
+ template = $( ex.template );
+ break;
+ case 'mootools':
+ template = $(document).getElement( ex.template );
+ case 'prototype':
+ template = $$( ex.template )[0];
+ default:
+ template = $p( ex.template );
+ }
- //keep a copy of the template
- var dv = document.createElement('DIV');
- dv.appendChild((template[0] || template).cloneNode(true));
- ex.original = dv.innerHTML;
+ //keep a copy of the template
+ var dv = document.createElement('DIV');
+ dv.appendChild((template[0] || template).cloneNode(true));
+ ex.original = dv.innerHTML;
- switch(ex.id){
- case 'ex01':
- case 'ex02':
- case 'ex03':
- case 'ex04':
- case 'ex06':
- //autoRender with data (and directives)
- template.autoRender( ex.data , ex.directive );
- break;
-
- case 'ex05':
- /* double rendering */
- template.render( ex.data, ex.directive1 ).render( ex.data, ex.directive2 );
- break;
-
- case 'ex07':
- /* Recursion */
- var rfn = template.compile( ex.directive );
-
- if(typeof rfn[0] === 'function'){ //DOMAssistant sends back an array?
- rfn = rfn[0];
- }
- ex.rfn = rfn;
- //some libs send back an array, some send the node
- ( template[0] || template ).parentNode.innerHTML = rfn( ex.data );
- break;
-
- default:
- // default rendering with data and directive
- template.render( ex.data, ex.directive );
- }
+ switch(ex.id){
+ case 'ex01':
+ case 'ex02':
+ case 'ex03':
+ case 'ex04':
+ case 'ex06':
+ //autoRender with data (and directives)
+ template.autoRender( ex.data , ex.directive );
+ break;
+
+ case 'ex05':
+ /* double rendering */
+ template.render( ex.data, ex.directive1 ).render( ex.data, ex.directive2 );
+ break;
+
+ case 'ex07':
+ /* Recursion */
+ var rfn = template.compile( ex.directive );
+
+ if(typeof rfn[0] === 'function'){ //DOMAssistant sends back an array?
+ rfn = rfn[0];
+ }
+ ex.rfn = rfn;
+ //some libs send back an array, some send the node
+ ( template[0] || template ).parentNode.innerHTML = rfn( ex.data );
+ break;
+
+ default:
+ // default rendering with data and directive
+ template.render( ex.data, ex.directive );
+ }
+ }
};
}());
View
@@ -7,7 +7,7 @@
Copyright (c) 2010 Michael Cvilic - BeeBole.com
Thanks to Rog Peppe for the functional JS jump
- revision: 2.56
+ revision: 2.58
*/
var $p, pure = $p = function(){
@@ -22,8 +22,8 @@ var $p, pure = $p = function(){
$p.core = function(sel, ctxt, plugins){
//get an instance of the plugins
- var plugins = getPlugins(),
- templates = [];
+ var templates = [];
+ plugins = plugins || getPlugins();
//search for the template node(s)
switch(typeof sel){
@@ -65,9 +65,6 @@ $p.core = function(sel, ctxt, plugins){
return Object.prototype.toString.call(o) === "[object Array]";
};
- return plugins;
-
-
/* * * * * * * * * * * * * * * * * * * * * * * * * *
core functions
* * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -122,7 +119,7 @@ $p.core = function(sel, ctxt, plugins){
if(typeof document.querySelectorAll !== 'undefined'){
return (n||document).querySelectorAll( sel );
}else{
- error('You can test PURE standalone with: iPhone, FF3.5+, Safari4+ and IE8+\n\nTo run PURE on your browser, you need a JS library/framework with a CSS selector engine');
+ return error('You can test PURE standalone with: iPhone, FF3.5+, Safari4+ and IE8+\n\nTo run PURE on your browser, you need a JS library/framework with a CSS selector engine');
}
}
@@ -431,6 +428,7 @@ $p.core = function(sel, ctxt, plugins){
target.nodes = [node]; // N.B. side effect on target.
setsig(target, fns.length - 1);
}
+ return target;
}
function getAutoNodes(n, data){
@@ -465,7 +463,6 @@ $p.core = function(sel, ctxt, plugins){
}
}
}
- return an;
function checkClass(c, tagName){
// read the class
@@ -504,16 +501,18 @@ $p.core = function(sel, ctxt, plugins){
}
return cspec;
}
+
+ return an;
+
}
// returns a function that, given a context argument,
// will render the template defined by dom and directive.
function compiler(dom, directive, data, ans){
- var fns = [];
+ var fns = [], j, jj, cspec, n, target, nodes, itersel, node, inner, dsel, sels, sel, sl, i, h, parts, pfns = [], p;
// autoRendering nodes parsing -> auto-nodes
ans = ans || data && getAutoNodes(dom, data);
if(data){
- var j, jj, cspec, n, target, nodes, itersel, node, inner;
// for each auto-nodes
while(ans.length > 0){
cspec = ans[0].cspec;
@@ -540,8 +539,7 @@ $p.core = function(sel, ctxt, plugins){
}
}
// read directives
- var target, dsel, sels, sl, i;
- for(var sel in directive){
+ for(sel in directive){
if(directive.hasOwnProperty(sel)){
i = 0;
dsel = directive[sel];
@@ -562,7 +560,7 @@ $p.core = function(sel, ctxt, plugins){
}
}
// convert node to a string
- var h = outerHTML(dom), pfns = [];
+ h = outerHTML(dom);
// IE adds an unremovable "selected, value" attribute
// hard replace while waiting for a better solution
h = h.replace(/<([^>]+)\s(value\=""|selected)\s?([^>]*)>/ig, "<$1 $3>");
@@ -571,9 +569,9 @@ $p.core = function(sel, ctxt, plugins){
h = h.split(attPfx).join('');
// slice the html string at "Sig"
- var parts = h.split( Sig ), p;
+ parts = h.split( Sig );
// for each slice add the return string of
- for(var i = 1; i < parts.length; i++){
+ for(i = 1; i < parts.length; i++){
p = parts[i];
// part is of the form "fn-number:..." as placed there by setsig.
pfns[i] = fns[ parseInt(p, 10) ];
@@ -649,6 +647,8 @@ $p.core = function(sel, ctxt, plugins){
ne = ep = null;
return elm;
}
+
+ return plugins;
};
$p.plugins = {};
@@ -766,4 +766,9 @@ $p.libs = {
typeof Sly !== 'undefined' && 'sly';
libkey && $p.libs[libkey]();
+
+ //for node.js
+ if(typeof exports !== 'undefined'){
+ exports.$p = $p;
+ }
})();
View
@@ -0,0 +1,13 @@
+var http = require('http'),
+ $p = require('pure');
+
+ console.log($p);
+
+http.createServer(function (req, res) {
+
+
+
+}).listen(1234, "127.0.0.1");
+console.log('Server running at http://127.0.0.1:1234/');
+
+
View
@@ -0,0 +1,21 @@
+//node.js installation
+{
+ "name" : "pure",
+ "description" : "PURE Unobtrusive Rendering Engine",
+ "url" : "http://beebole.com/pure/",
+ "keywords" : ["unobtrusive", "templating", "engine", "think different"],
+ "author" : "Mic Cvilic <mic@beebole.com>",
+ "contributors" : [],
+ "dependencies" : [],
+ "lib" : "libs",
+ "main" : "libs/pure.js",
+ "version" : "2.58.0",
+ "repository" : {
+ "type" : "git",
+ "url" : "http://github.com/pure/pure.git"
+ },
+ "licenses": [{
+ "type": "The MIT License",
+ "url": "http://www.opensource.org/licenses/mit-license.php"}
+ ]
+}

0 comments on commit 378b926

Please sign in to comment.