Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

work on v3

  • Loading branch information...
commit 81dfcae4fa362f3eee05885ff41b699805861d2e 1 parent 3a59793
@pure authored
View
8 libs/pure.js
@@ -7,7 +7,7 @@
Copyright (c) 2011 Michael Cvilic - BeeBole.com
Thanks to Rog Peppe for the functional JS jump
- revision: 2.71
+ revision: 2.72
*/
var $p, pure = $p = function(){
@@ -184,7 +184,11 @@ $p.core = function(sel, ctxt, plugins){
// can traverse the data accordingly, given a context.
function dataselectfn(sel){
if(typeof(sel) === 'function'){
- return sel;
+ //handle false values in function directive
+ return function(ctxt){
+ var r = sel.call( ctxt.item || ctxt.context || ctxt, ctxt );
+ return !r && r !== 0 ? '' : r;
+ };
}
//check for a valid js variable name with hyphen(for properties only), $, _ and :
var m = sel.match(/^[a-zA-Z\$_\@][\w\$:-]*(\.[\w\$:-]*[^\.])*$/);
View
23,385 v3_preview/data.js
23,385 additions, 0 deletions not shown
View
45 v3_preview/pure2.html
@@ -0,0 +1,45 @@
+<html>
+<head>
+ <title>PURE Unobtrusive Rendering Engine</title>
+ <script src="../libs/pure.js"></script>
+</head>
+<body>
+ <!-- HTML template -->
+ It took:<span id="duration"></span>
+ <ul class="template">
+ <li class="people">
+ <span class="name"></span>
+ <ul>
+ <li class="team">
+ <a href="http://domain.com/employee/" class="name"></a>
+ </li>
+ </ul>
+ </li>
+ </ul>
+
+ <script>
+ function callback(data){
+ var start = new Date().getTime(),
+ directive = {
+ 'li.people':{
+ 'person<-people':{
+ 'span.name':'person.name',
+ 'li.team':{
+ 'teamMember<-person.team':{
+ 'a.name':'#{teamMember.name} (#{person.id}-#{teamMember.id})',
+ 'a.name@href+':'teamMember.id'
+ }
+ }
+ }
+ }
+ };
+
+ // noClone() to transform the current node, instead of creating a new one
+ $p('ul.template').render(data, directive);
+
+ document.getElementById('duration').innerHTML = (new Date().getTime() - start) + 'ms for ' + data.people.length + ' records';
+ }
+</script>
+<script src="data.js"></script>
+</body>
+</html>
View
7 v3_preview/pure3.html
@@ -19,10 +19,8 @@
<script>
function callback(data){
- var start = new Date().getTime();
-
- //declaration of the actions PURE has to do
- var directive = {
+ var start = new Date().getTime(),
+ directive = {
'li.people':{
'person<-people':{
'span.name':'person.name',
@@ -38,6 +36,7 @@
// noClone() to transform the current node, instead of creating a new one
$p('ul.template').noClone().render(data, directive);
+
document.getElementById('duration').innerHTML = (new Date().getTime() - start) + 'ms for ' + data.people.length + ' records';
}
</script>
View
7 v3_preview/pure3.js
@@ -69,11 +69,6 @@ $p.core = function(sel, ctxt, plugins){
transform = function(node, data, directive){
var selector,
runLoopDirective = function(directive, data, node){
-
-
- //nested loops
-
-
var parseLoopSpec = function(p){
var m = p.match( /^(\w+)\s*<-\s*(\S+)?$/ );
if(m === null){
@@ -120,7 +115,7 @@ $p.core = function(sel, ctxt, plugins){
var dfrag = document.createDocumentFragment(),
items = readData(loopDef.loopSpec.arrayName, data),
i = 0, ii = items.length,
- tempCtxt = {context:ctxt},
+ tempCtxt = data.context ? data : {context:data},
loopCtxt = tempCtxt[loopDef.loopSpec.itemName] = {};
tempCtxt.items = loopCtxt.items = items;
Please sign in to comment.
Something went wrong with that request. Please try again.