From db7227e197882d283a399d58c0c2fac9f802697f Mon Sep 17 00:00:00 2001 From: jakub-g Date: Fri, 19 Sep 2014 17:42:26 +0200 Subject: [PATCH] feat(syntax) mandatory ` + + + - + diff --git a/docs/samples/component3/pagination.hsp b/docs/samples/component3/pagination.hsp index fd0ca08..5274cfb 100644 --- a/docs/samples/component3/pagination.hsp +++ b/docs/samples/component3/pagination.hsp @@ -1,3 +1,4 @@ + + diff --git a/docs/samples/conditions/conditions.hsp b/docs/samples/conditions/conditions.hsp index 3bf7476..84ed8d6 100644 --- a/docs/samples/conditions/conditions.hsp +++ b/docs/samples/conditions/conditions.hsp @@ -1,6 +1,10 @@ + + + diff --git a/docs/samples/cssclass/cssclass.hsp b/docs/samples/cssclass/cssclass.hsp index 8e1b8c6..5228118 100644 --- a/docs/samples/cssclass/cssclass.hsp +++ b/docs/samples/cssclass/cssclass.hsp @@ -13,6 +13,7 @@ + \ No newline at end of file diff --git a/docs/samples/dynpath/dynpath.hsp b/docs/samples/dynpath/dynpath.hsp index c828a68..5588b00 100644 --- a/docs/samples/dynpath/dynpath.hsp +++ b/docs/samples/dynpath/dynpath.hsp @@ -18,6 +18,7 @@ Show/Hide columns C + diff --git a/docs/samples/dyntemplates/dyntemplates.hsp b/docs/samples/dyntemplates/dyntemplates.hsp index bb67f06..cca6824 100644 --- a/docs/samples/dyntemplates/dyntemplates.hsp +++ b/docs/samples/dyntemplates/dyntemplates.hsp @@ -15,6 +15,7 @@ + \ No newline at end of file diff --git a/docs/samples/gestures/gestures.hsp b/docs/samples/gestures/gestures.hsp index c4ed7ea..88d866d 100644 --- a/docs/samples/gestures/gestures.hsp +++ b/docs/samples/gestures/gestures.hsp @@ -1,4 +1,6 @@ + + diff --git a/docs/samples/global/global.hsp b/docs/samples/global/global.hsp index 2339646..89a3183 100644 --- a/docs/samples/global/global.hsp +++ b/docs/samples/global/global.hsp @@ -1,4 +1,6 @@ + + + diff --git a/docs/samples/helloworld/hello.hsp b/docs/samples/helloworld/hello.hsp index 39af818..d916fa6 100644 --- a/docs/samples/helloworld/hello.hsp +++ b/docs/samples/helloworld/hello.hsp @@ -1,13 +1,18 @@ + + + \ No newline at end of file diff --git a/docs/samples/inputsample/inputsample.hsp b/docs/samples/inputsample/inputsample.hsp index 7bd2032..3e5319f 100644 --- a/docs/samples/inputsample/inputsample.hsp +++ b/docs/samples/inputsample/inputsample.hsp @@ -31,6 +31,7 @@ + diff --git a/docs/samples/let/let.hsp b/docs/samples/let/let.hsp index 508e012..7868aed 100644 --- a/docs/samples/let/let.hsp +++ b/docs/samples/let/let.hsp @@ -13,6 +13,7 @@ Change Model + \ No newline at end of file diff --git a/docs/samples/list1/list.hsp b/docs/samples/list1/list.hsp index f821539..9ce68d5 100644 --- a/docs/samples/list1/list.hsp +++ b/docs/samples/list1/list.hsp @@ -1,3 +1,4 @@ + + + + + diff --git a/docs/samples/list2/list.hsp b/docs/samples/list2/list.hsp index f41ae32..73d3756 100644 --- a/docs/samples/list2/list.hsp +++ b/docs/samples/list2/list.hsp @@ -1,3 +1,4 @@ + + + + diff --git a/docs/samples/listsorting/list.hsp b/docs/samples/listsorting/list.hsp index 87bf01c..f3f5299 100644 --- a/docs/samples/listsorting/list.hsp +++ b/docs/samples/listsorting/list.hsp @@ -26,6 +26,7 @@ + diff --git a/docs/samples/listupdate/list.hsp b/docs/samples/listupdate/list.hsp index 31959f1..a0e7671 100644 --- a/docs/samples/listupdate/list.hsp +++ b/docs/samples/listupdate/list.hsp @@ -20,6 +20,7 @@ + diff --git a/docs/samples/logs/logs.hsp b/docs/samples/logs/logs.hsp index 7a90800..bd938ba 100644 --- a/docs/samples/logs/logs.hsp +++ b/docs/samples/logs/logs.hsp @@ -1,4 +1,6 @@ + + diff --git a/docs/samples/modifiers/modifiers.hsp b/docs/samples/modifiers/modifiers.hsp index 56b0e01..59c01a4 100644 --- a/docs/samples/modifiers/modifiers.hsp +++ b/docs/samples/modifiers/modifiers.hsp @@ -1,3 +1,4 @@ + + diff --git a/docs/samples/panel/panel.hsp b/docs/samples/panel/panel.hsp index 82b2b0f..baf963e 100644 --- a/docs/samples/panel/panel.hsp +++ b/docs/samples/panel/panel.hsp @@ -1,3 +1,4 @@ + + + diff --git a/docs/samples/simplelist/simplelist.hsp b/docs/samples/simplelist/simplelist.hsp index 5b05f07..745b115 100644 --- a/docs/samples/simplelist/simplelist.hsp +++ b/docs/samples/simplelist/simplelist.hsp @@ -14,6 +14,7 @@ + diff --git a/docs/samples/subtemplates/subtemplates.hsp b/docs/samples/subtemplates/subtemplates.hsp index 37ec832..351e30d 100644 --- a/docs/samples/subtemplates/subtemplates.hsp +++ b/docs/samples/subtemplates/subtemplates.hsp @@ -25,6 +25,7 @@ {/if} + diff --git a/docs/samples/tabbar/tabbar.hsp b/docs/samples/tabbar/tabbar.hsp index 372a2ed..4a65785 100644 --- a/docs/samples/tabbar/tabbar.hsp +++ b/docs/samples/tabbar/tabbar.hsp @@ -1,3 +1,4 @@ + + diff --git a/docs/samples/textarea/textarea.hsp b/docs/samples/textarea/textarea.hsp index 66a340f..bfaf153 100644 --- a/docs/samples/textarea/textarea.hsp +++ b/docs/samples/textarea/textarea.hsp @@ -11,6 +11,7 @@ Change text + diff --git a/docs/samples/thirdpartycpts/chart.hsp b/docs/samples/thirdpartycpts/chart.hsp index 17df679..7c11192 100644 --- a/docs/samples/thirdpartycpts/chart.hsp +++ b/docs/samples/thirdpartycpts/chart.hsp @@ -1,3 +1,4 @@ + - + diff --git a/docs/samples/timer/timer.hsp b/docs/samples/timer/timer.hsp index 00b024d..7d6debf 100644 --- a/docs/samples/timer/timer.hsp +++ b/docs/samples/timer/timer.hsp @@ -1,9 +1,12 @@ + + diff --git a/docs/samples/todolist/todolist.hsp b/docs/samples/todolist/todolist.hsp index 3b6f021..941f0b1 100644 --- a/docs/samples/todolist/todolist.hsp +++ b/docs/samples/todolist/todolist.hsp @@ -1,4 +1,6 @@ + + diff --git a/gruntfile.js b/gruntfile.js index ad1a397..2e154af 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -23,7 +23,7 @@ module.exports = function (grunt) { test: { options: { reporter: 'spec', - require: 'build/blanket' + require: 'build/blanket' // comment this line out to disable coverage when debugging mocha tests }, src: [ 'test/compiler/**/*.js', @@ -173,6 +173,7 @@ module.exports = function (grunt) { }, unit: { singleRun: true + // logLevel: 'DEBUG' // uncomment for investigating hashspace precompilation issues }, tdd: { singleRun: false, diff --git a/hsp/compiler/jsgenerator/index.js b/hsp/compiler/jsgenerator/index.js index d994258..47d88c8 100644 --- a/hsp/compiler/jsgenerator/index.js +++ b/hsp/compiler/jsgenerator/index.js @@ -53,7 +53,9 @@ exports.generate = function(res, template, fileName, dirPath, options) { res.codeFragments = templateWalker.templates; } - res.code = HEADER + out.join('\r\n'); + // don't add any newlines when joining blocks; + // emit necessary newlines from the parser or template walker instead + res.code = HEADER + out.join(''); res.errors = templateWalker.errors; } else { // Generate a JS script to show the errors when the generated file is loaded @@ -159,7 +161,7 @@ function _generateLineMap (res, file) { } } - var nbrOfLinesInCompiledTemplate = 7; //all generated templates got fixed no of LOC + var nbrOfLinesInCompiledTemplate = 5; //all generated templates got fixed no of LOC var lineMap = [], pos = HEADER_SZ, template; var pos1 = -1; // position of the next template start var pos2 = -1; // position of the next template end diff --git a/hsp/compiler/parser/hspblocks.pegjs b/hsp/compiler/parser/hspblocks.pegjs index 9ab2e1c..80d9194 100644 --- a/hsp/compiler/parser/hspblocks.pegjs +++ b/hsp/compiler/parser/hspblocks.pegjs @@ -7,13 +7,25 @@ * with hashspace constraints) * @see https://github.com/dmajda/pegjs */ - TemplateFile - = blocks:(TemplateBlock / TextBlock)* - {return blocks;} + = blocks:(TemplateBlock / ScriptBlock / TopLevelWhitespace)* + { + return blocks; + } + +TopLevelWhitespace + = lines:(chars:WhiteSpace* eol:EOL {return chars.join("") + eol})+ + {return {type:"plaintext", value:lines.join('')}} + +ScriptBlock "script block" + = (_ "" _ eol2:(EOL / EOF)) + { + content.value = (eol1 || "") + content.value + (eol2 || ""); + return content; + } TextBlock - = lines:(!(_ ("<") _ "template") !(_ ("<") _ [a-zA-Z0-9]+ _ "template") !("#" _ "require") chars:[^\n\r]* eol:EOL {return chars.join("")+eol})+ + = lines:(!(_ ("<") ("template" / "/script")) !(_ ("<") _ [a-zA-Z0-9]+ _ "template") !("#" _ "require") chars:[^\n\r]* eol:EOL {return chars.join("")+eol})+ {return {type:"plaintext", value:lines.join('')}} TemplateBlock "template block" diff --git a/test/compiler/errsamples/mixed1.txt b/test/compiler/errsamples/mixed1.txt index f9ed5c4..9f27b6e 100644 --- a/test/compiler/errsamples/mixed1.txt +++ b/test/compiler/errsamples/mixed1.txt @@ -1,8 +1,10 @@ ##### Template: + + ##### Errors: diff --git a/test/compiler/errsamples/mixed2.txt b/test/compiler/errsamples/mixed2.txt index 3f91f7a..032e814 100644 --- a/test/compiler/errsamples/mixed2.txt +++ b/test/compiler/errsamples/mixed2.txt @@ -1,8 +1,10 @@ ##### Template: +