Skip to content

Commit

Permalink
Merge f3c0b91 into 2b516d6
Browse files Browse the repository at this point in the history
  • Loading branch information
PK1A committed Mar 28, 2014
2 parents 2b516d6 + f3c0b91 commit c33d17b
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 61 deletions.
5 changes: 3 additions & 2 deletions build/grunt/hspserver.js
Expand Up @@ -5,7 +5,8 @@ var path = require("path");
module.exports = function(grunt) {
grunt.registerTask('hspserver', 'Start a web server to server compiled templates on the fly', function () {

var renderer = require("../../hsp/compiler/renderer");
var renderer = require("../../hsp/compiler/renderer");
var transpiler = require("../../hsp/transpiler");

grunt.config.requires('hspserver.port');
grunt.config.requires('hspserver.base');
Expand Down Expand Up @@ -44,7 +45,7 @@ module.exports = function(grunt) {
if (r.serverErrors && r.serverErrors.length) {
res.send(500,r.serverErrors[0].description);
} else {
res.send(200,r.code);
res.send(200,transpiler.processString(r.code).code);
}
} else {
res.send(500,"[/hsp/compile] src parameter is undefined");
Expand Down
12 changes: 6 additions & 6 deletions public/samples/clickhandler/clickhandler.hsp
@@ -1,4 +1,4 @@
var msg={text:""}, count=-1, $set=require("hsp/$set");
var msg={text:""}, count=-1;

# template message(msg)
<div title="click me!" onclick="{changeMessage()}" onselectstart="return false">
Expand All @@ -11,15 +11,15 @@ function changeMessage() {
count++;
switch(count%3) {
case 0:
$set(msg,"isWarning",false);
$set(msg,"text","Click me to discover hashspace event hanlders");
msg.isWarning = false;
msg.text = "Click me to discover hashspace event hanlders";
break;
case 1:
$set(msg,"text","Well done - you called the event handler and updated the data model in a row!");
msg.text = "Well done - you called the event handler and updated the data model in a row!";
break;
case 2:
$set(msg,"isWarning",true);
$set(msg,"text","If you click again you will be back to first step!");
msg.isWarning = true;
msg.text = "If you click again you will be back to first step!";
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions public/samples/clock/clock.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

var CITIES={
"SFO":{city:"San Francisco",offset:-8},
Expand Down Expand Up @@ -34,11 +34,11 @@ var ClockController=klass({
var to=CITIES[this.city].offset;
var o=d.getTimezoneOffset()/60;
d=new Date(d.getTime()+ ((o+to)*3600000)); // date in the target city
$set(this,"hours",d.getHours());
$set(this,"minutes",d.getMinutes());
$set(this,"seconds",d.getSeconds());
$set(this,"milliseconds",d.getMilliseconds());
$set(this,"cityName",CITIES[this.city].city);
this.hours = d.getHours();
this.minutes = d.getMinutes();
this.seconds = d.getSeconds();
this.milliseconds = d.getMilliseconds();
this.cityName = CITIES[this.city].city;
}
});

Expand Down
4 changes: 2 additions & 2 deletions public/samples/component1/timer.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

// klass is a utility to create JS objects with constructors & prototypes
var Timer=klass({
Expand All @@ -14,7 +14,7 @@ var Timer=klass({
},
tick:function() {
console.log("tick");
$set(this,"secondsElapsed",this.secondsElapsed+1);
this.secondsElapsed++;
}
});

Expand Down
15 changes: 7 additions & 8 deletions public/samples/component2/nbrfield.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

// Component controller
var NbrField = klass({
Expand All @@ -24,7 +24,7 @@ var NbrField = klass({
*/
onValueChange:function(newValue,oldValue) {
var n=getNumber(newValue);
$set(this,"internalValue",n!==null? n : 0);
this.internalValue = n!==null? n : 0;
this.checkValidity();
},
onMinChange:function(newValue,oldValue) {
Expand All @@ -39,24 +39,23 @@ var NbrField = klass({
*/
onInternalValueChange:function(newValue,oldValue) {
// validate and expose as attribute if ok
$set(this,"value",this.checkValidity()? parseInt(this.internalValue,10) : this.defaultvalue);
this.value = this.checkValidity()? parseInt(this.internalValue,10) : this.defaultvalue;
},
/**
* Check if the internal value is valid and update the isValid property accordingly
*/
checkValidity:function() {
var n=getNumber(this.internalValue);
var v=(n===null)? false : (n>=this.min) && (n<=this.max);
$set(this,"isValid",v);
return v;
var v=(n===null)? false : (n>=this.min) && (n<=this.max);
return this.isValid = v;
},
/**
* Reset the field value
*/
resetField:function() {
var v1=this.value, v2=this.defaultvalue;
$set(this,"internalValue",v2);
$set(this,"value",v2);
this.internalValue = v2;
this.value = v2;
this.checkValidity();
this.onreset({oldValue:v1,newValue:v2}); // call back event listener
}
Expand Down
10 changes: 5 additions & 5 deletions public/samples/component3/pagination.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

function calculateNoOfPages(collectionSize, pageSize) {
return Math.ceil(collectionSize / pageSize);
Expand All @@ -13,8 +13,8 @@ function rebuildPagesModel(noOfPages) {
}

function rebuildInternalModel(ctl) {
$set(ctl, 'noOfPages', calculateNoOfPages(ctl.collectionsize, ctl.pagesize));
$set(ctl, 'pages', rebuildPagesModel(ctl.noOfPages));
ctl.noOfPages = calculateNoOfPages(ctl.collectionsize, ctl.pagesize);
ctl.pages = rebuildPagesModel(ctl.noOfPages);
ctl.selectPage(ctl.activepage);
}

Expand All @@ -31,7 +31,7 @@ var Pagination=klass({
selectPage: function(newPageNo) {
newPageNo = Math.min(Math.max(0, newPageNo), this.noOfPages-1);
if (this.activepage!==newPageNo) {
$set(this, 'activepage', newPageNo);
this.activepage = newPageNo;
this.onpageselect({pageNumber:this.activepage});
}
},
Expand Down Expand Up @@ -79,7 +79,7 @@ var model = {
}

function updateSelection(newPageNumber) {
$set(model,"lastSelectedPage",newPageNumber);
model.lastSelectedPage = newPageNumber;
}

// display the test template in the #output div
Expand Down
4 changes: 2 additions & 2 deletions public/samples/conditions/conditions.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

// nt is an instance of NumberTester
# template test(nt)
Expand Down Expand Up @@ -31,7 +31,7 @@ var NumberTester=klass({
this.number=0;
},
increment:function(nbr2) {
$set(this,"number",this.number+nbr2);
this.number = this.number+nbr2;
}
});

Expand Down
12 changes: 5 additions & 7 deletions public/samples/cssclass/cssclass.hsp
@@ -1,31 +1,29 @@
var $set=require("hsp/$set");

# template message(msg)
// onselectstart: prevent double-click selection on a elements
<div onselectstart="return false">
<a onclick="{toggleUrgency()}">Change Urgency</a> -
<a onclick="{setCategory('personal')}">Set "Personal"</a> -
<a onclick="{setCategory('professional')}">Set "Professional"</a>
<div class="{'msg', 'urgent':msg.urgency===1, msg.category}">
<div class="{'msg', 'urgent':msg.urgency, msg.category}">
Message: {msg.text}
</div>
<div class="note">
Class value: "{'msg', 'urgent':msg.urgency===1, msg.category}"
Class value: "{'msg', 'urgent':msg.urgency, msg.category}"
</div>
</div>
# /template

var msg={
text:"Hello World",
urgency:0
urgency:false
}

function toggleUrgency() {
$set(msg,"urgency",msg.urgency? 0 : 1);
msg.urgency = !msg.urgency;
}

function setCategory(cat) {
$set(msg,"category",cat);
msg.category = cat;
}

// display the template in the #output div
Expand Down
4 changes: 1 addition & 3 deletions public/samples/dyntemplates/dyntemplates.hsp
@@ -1,5 +1,3 @@
var $set = require("hsp/$set");

# template test(ctxt)
<div><a onclick="{swapTemplate()}">Change template</a></div>
<#ctxt.view ctxt="{ctxt}"/>
Expand All @@ -25,7 +23,7 @@ var model={

function swapTemplate() {
var newtpl=(model.view===tplA)? tplB : tplA;
$set(model,"view",newtpl);
model.view = newtpl;
}

// display the template in the #output div
Expand Down
6 changes: 2 additions & 4 deletions public/samples/let/let.hsp
@@ -1,5 +1,3 @@
var $set=require("hsp/$set");

# template test(m)
{let p1=m.part1, m21=m.part2.part21.msg+"!"}
<div>
Expand Down Expand Up @@ -27,8 +25,8 @@ var model={
var count=0;
function updateModel() {
count++;
$set(model.part1.part11,"msg", "(1.1 update: "+count+")");
$set(model.part2.part21,"msg", "(2.1 update: "+count+")");
model.part1.part11.msg = "(1.1 update: "+count+")";
model.part2.part21.msg = "(2.1 update: "+count+")";
}

// render template in the #output div
Expand Down
6 changes: 3 additions & 3 deletions public/samples/list1/list.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

// simple list controller
var ListController = klass({
Expand Down Expand Up @@ -67,7 +67,7 @@ var count=0, model={
};

function toggle() {
$set(model,"preferredOption",model.preferredOption? null : "My favourite things");
model.preferredOption = model.preferredOption? null : "My favourite things";
}

function empty() {
Expand All @@ -77,7 +77,7 @@ function empty() {
function update() {
count++;
for (var i=0;count>i;i++) {
$set(model.items,i,"Item #"+(i+1)+" (change "+count+")");
model.items[i] = "Item #"+(i+1)+" (change "+count+")";
}
}

Expand Down
8 changes: 4 additions & 4 deletions public/samples/list2/list.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

// simple option controller
var OptionCtrl = klass({
Expand Down Expand Up @@ -28,7 +28,7 @@ var ListCtrl = klass({
var c=this.content;
for (var i=0,sz=c.length;sz>i;i++) {
if (c[i].tagName==="@option") {
$set(c[i],"selected",c[i].value===value);
c[i].selected = c[i].value===value;
}
}
this.onselect({value:value});
Expand Down Expand Up @@ -95,12 +95,12 @@ function empty() {
function update() {
count++;
for (var i=0;count>i;i++) {
$set(model.items,i,"Item #"+(i+1)+" (change "+count+")");
model.items[i] = "Item #"+(i+1)+" (change "+count+")";
}
}

function showSelection(v) {
$set(model,"selectedItem",v);
model.selectedItem = v;
}

// display the test template in the #output div
Expand Down
4 changes: 2 additions & 2 deletions public/samples/panel/panel.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

var PanelController = klass({
attributes: {
Expand Down Expand Up @@ -36,7 +36,7 @@ var model={text:"Hello World"}, count=0;

function update(incr) {
count+=incr;
$set(model,"text","Hello World ("+count+")");
model.text = "Hello World ("+count+")";
}

// display the test template in the #output div
Expand Down
4 changes: 1 addition & 3 deletions public/samples/simplelist/simplelist.hsp
@@ -1,5 +1,3 @@
var $set=require("hsp/$set");

# template people(d)
<div class="msg">Click on a person to see more details:</div>
<ul>
Expand All @@ -17,7 +15,7 @@ var $set=require("hsp/$set");
# /template

function toggleDetails(person) {
$set(person,"showdetails",!person.showdetails);
person.showdetails = !person.showdetails;
}

var d={
Expand Down
4 changes: 2 additions & 2 deletions public/samples/timer/timer.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

# template elapsedTime(timer)
Seconds Elapsed: {timer.secondsElapsed}
Expand All @@ -16,7 +16,7 @@ var Timer=klass({
clearInterval(this._iid);
},
tick:function() {
$set(this,"secondsElapsed",this.secondsElapsed+1);
this.secondsElapsed++;
}
});

Expand Down
4 changes: 2 additions & 2 deletions public/samples/todolist/todolist.hsp
@@ -1,4 +1,4 @@
var klass=require("hsp/klass"), $set=require("hsp/$set");
var klass=require("hsp/klass");

# template todolist(todo)
<div>
Expand Down Expand Up @@ -28,7 +28,7 @@ var TodoCtl=klass({
// add new item to the todo list
items.splice(items.length,0,d.newTodoItem);
// empty new todo field value
$set(d,"newTodoItem","");
d.newTodoItem = "";
// return false to prevent default behaviour
return false;
}
Expand Down

0 comments on commit c33d17b

Please sign in to comment.