From 821e26fa30372ad6e534a54134653d8f664c58dd Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 6 Jan 2013 19:45:09 +0100 Subject: fixed the lexer rules --- module/web/static/js/libs/handlebars.l | 48 ++++++++++++++++++++++++++++++ module/web/static/js/utils/initHB.js | 4 +-- module/web/static/js/views/settingsView.js | 27 ++++++++--------- 3 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 module/web/static/js/libs/handlebars.l (limited to 'module/web/static/js') diff --git a/module/web/static/js/libs/handlebars.l b/module/web/static/js/libs/handlebars.l new file mode 100644 index 000000000..f0c04f91e --- /dev/null +++ b/module/web/static/js/libs/handlebars.l @@ -0,0 +1,48 @@ + +%x mu emu + +%% + +[^\x00]*?/("<%") { + if(yytext.slice(-1) !== "\\") this.begin("mu"); + if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1), this.begin("emu"); + if(yytext) return 'CONTENT'; + } + +[^\x00]+ { return 'CONTENT'; } + +[^\x00]{2,}?/("{{"|<>) { + if(yytext.slice(-1) !== "\\") this.popState(); + if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1); + return 'CONTENT'; + } + +"{{>" { return 'OPEN_PARTIAL'; } +"<%=" { return 'OPEN_BLOCK'; } +"<%/" { return 'OPEN_ENDBLOCK'; } +"{{^" { return 'OPEN_INVERSE'; } +"<%"\s*"else" { return 'OPEN_INVERSE'; } +"{<%%" { return 'OPEN_UNESCAPED'; } +"{{&" { return 'OPEN_UNESCAPED'; } +"<%!"[\s\S]*?"%>" { yytext = yytext.substr(3,yyleng-5); this.popState(); return 'COMMENT'; } +"<%" { return 'OPEN'; } + +"=" { return 'EQUALS'; } +"."/[%} ] { return 'ID'; } +".." { return 'ID'; } +[\/.] { return 'SEP'; } +\s+ { /*ignore whitespace*/ } +"%%>" { this.popState(); return 'CLOSE'; } +"%>" { this.popState(); return 'CLOSE'; } +'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; } +"'"("\\"[']|[^'])*"'" { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; } +"@"[a-zA-Z]+ { yytext = yytext.substr(1); return 'DATA'; } +"true"/[%}\s] { return 'BOOLEAN'; } +"false"/[%}\s] { return 'BOOLEAN'; } +[0-9]+/[%}\s] { return 'INTEGER'; } +[a-zA-Z0-9_$-]+/[=%}\s\/.] { return 'ID'; } +'['[^\]]*']' { yytext = yytext.substr(1, yyleng-2); return 'ID'; } +. { return 'INVALID'; } + +<> { return 'EOF'; } + diff --git a/module/web/static/js/utils/initHB.js b/module/web/static/js/utils/initHB.js index 6d9436835..784032ca0 100644 --- a/module/web/static/js/utils/initHB.js +++ b/module/web/static/js/utils/initHB.js @@ -1,8 +1,8 @@ // Loads all helper and set own handlebars rules define(['underscore', 'handlebars', 'helpers/formatSize'], function(_, Handlebars) { - // TODO: create better lexer rules, these are just hacked - Handlebars.Parser.lexer.rules = [/^(?:[^\x00]*?(?=(<%)))/, /^(?:[^\x00]+)/, /^(?:[^\x00]{2,}?(?=(<%|$)))/, /^(?:<%>)/, /^(?:<%#)/, /^(?:<%\/)/, /^(?:<%\^)/, /^(?:<%\s*else\b)/, /^(?:<%=)/, /^(?:<%&)/, /^(?:<%![\s\S]*?\}\})/, /^(?:<%)/, /^(?:=)/, /^(?:\.(?=[%> ]))/, /^(?:\.\.)/, /^(?:[\/.])/, /^(?:\s+)/, /^(?:=%>)/, /^(?:%>)/, /^(?:"(\\["]|[^"])*")/, /^(?:'(\\[']|[^'])*')/, /^(?:@[a-zA-Z]+)/, /^(?:true(?=[%>\s]))/, /^(?:false(?=[%>\s]))/, /^(?:[0-9]+(?=[%>\s]))/, /^(?:[a-zA-Z0-9_$-]+(?=[%>=}\s\/.]))/, /^(?:\[[^\]]*\])/, /^(?:.)/, /^(?:$)/]; + // Replace with own lexer rules compiled from handlebars.l + Handlebars.Parser.lexer.rules = [/^(?:[^\x00]*?(?=(<%)))/, /^(?:[^\x00]+)/, /^(?:[^\x00]{2,}?(?=(\{\{|$)))/, /^(?:\{\{>)/, /^(?:<%=)/, /^(?:<%\/)/, /^(?:\{\{\^)/, /^(?:<%\s*else\b)/, /^(?:\{<%%)/, /^(?:\{\{&)/, /^(?:<%![\s\S]*?%>)/, /^(?:<%)/, /^(?:=)/, /^(?:\.(?=[%} ]))/, /^(?:\.\.)/, /^(?:[\/.])/, /^(?:\s+)/, /^(?:%%>)/, /^(?:%>)/, /^(?:"(\\["]|[^"])*")/, /^(?:'(\\[']|[^'])*')/, /^(?:@[a-zA-Z]+)/, /^(?:true(?=[%}\s]))/, /^(?:false(?=[%}\s]))/, /^(?:[0-9]+(?=[%}\s]))/, /^(?:[a-zA-Z0-9_$-]+(?=[=%}\s\/.]))/, /^(?:\[[^\]]*\])/, /^(?:.)/, /^(?:$)/]; _.compile = Handlebars.compile; return Handlebars diff --git a/module/web/static/js/views/settingsView.js b/module/web/static/js/views/settingsView.js index c6fe535b9..1b7f5e356 100644 --- a/module/web/static/js/views/settingsView.js +++ b/module/web/static/js/views/settingsView.js @@ -5,10 +5,10 @@ define(['jquery', 'underscore', 'backbone'], return Backbone.View.extend({ el: "#content", -// template: _.compile($("#template-package").html()), + template_menu: _.compile($("#template-menu").html()), events: { - + 'click .settings-menu li > a': 'change_section' }, menu: null, @@ -18,24 +18,21 @@ define(['jquery', 'underscore', 'backbone'], this.menu = $('.settings-menu'); var self = this; - $.ajax("/api/getCoreConfig", {success: function(data) { - self.data = data; - self.render() - }}); +// $.ajax("/api/getCoreConfig", {success: function(data) { +// self.data = data; +// self.render() +// }}); // $.ajax("/api/getPluginConfig"); console.log("Settings initialized"); }, + // TODO: this is only a showcase render: function() { - if (this.data != null) { - var self = this; - this.menu.empty(); - this.menu.append($('')); - - _.each(this.data, function(section) { - self.menu.append($('
  • ' + section.label + '
  • ')); - }) - } + this.menu.html(this.template_menu({core:false})); + }, + + change_section: function(el) { + console.log("Section changed"); } }); -- cgit v1.2.3