diff --git a/README.md b/README.md index 2a95fd3..4cb63c7 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The engine support the following data-attribute (the order isn't casual, is the * data-tdal-repeat="repeat-variabile path-expression" * data-tdal-content="path-expression-string-allowed" OR * data-tdal-replace="path-expression-string-allowed" -* data-tdal-attributes="attribute path-expression-string-allowed[; attributes path-expression-string-allowed]" +* data-tdal-attributes="attribute path-expression-string-allowed[#attributes path-expression-string-allowed]" * data-tdal-omittag="path-expression-boolean-mod-allowed" I plan the implement the jTDAL equivalent of the TAL's METAL (partials in mustache) in a future update. @@ -90,7 +90,7 @@ Replace the tag and its content with the result of the path-expression. Mutually If the result of the path expression is "false", the tag and its contents will be removed (like a false data-tdal-condition). If is "true", the default content will be kept. ### Attribute - data-tdal-attributes="href link | STRING:https://www.example.org/{page}; class STRING:link-color-blue" + data-tdal-attributes="href link | STRING:https://www.example.org/{page}#class STRING:link-color-blue" Add an attribute or replace the content of an attribute with the result of the path expression. If the expression value is "true" current attribute content will be kept. diff --git a/jTDAL.js b/jTDAL.js index 5ad2c3b..dfdd831 100644 --- a/jTDAL.js +++ b/jTDAL.js @@ -3,7 +3,7 @@ var jTDAL; (function (jTDAL) { const regexpPatternPath = '(?:[\\w-\\/]*[\\w](?:[\\s]*\\|[\\s]*[\\w-\\/]*[\\w])*)'; const regexpPatternPathAllowedBoolean = '(?:(?:!)?[\\w-\\/]*[\\w](?:[\\s]*\\|[\\s]*[\\w-\\/]*[\\w])*)'; - const regexpPatternExpressionAllowedBoolean = '(STRING:[^;]+|' + regexpPatternPathAllowedBoolean + ')'; + const regexpPatternExpressionAllowedBoolean = '(STRING:[^#]+|' + regexpPatternPathAllowedBoolean + ')'; const keywords = ['condition', 'repeat', 'content', 'replace', 'attributes', 'omittag']; const regexp = { 'tagWithTDAL': new RegExp('<((?:\\w+:)?\\w+)(\\s+[^<>]+?)??\\s+data-tdal-(?:' + keywords.join('|') + @@ -16,7 +16,7 @@ var jTDAL; 'condition': new RegExp('^[\\s]*(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*$'), 'repeat': new RegExp('^[\\s]*([\\w-]+?)[\\s]+(' + regexpPatternPath + ')[\\s]*$'), 'content': new RegExp('^[\\s]*(?:(text|structure)[\\s]+)?(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*$'), - 'attributes': new RegExp('[\\s]*(?:(?:([\\w-]+?)[\\s]+(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*)(?:;[\\s]*|$))', 'g'), + 'attributes': new RegExp('[\\s]*(?:(?:([\\w-]+?)[\\s]+(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*)(?:#[\\s]*|$))', 'g'), 'attributesTDAL': new RegExp('\\s*(data-tdal-[\\w-]+)=(?:([\'"])(.*?)\\2|([^>\\s\'"]+))', 'gi') }; const HTML5VoidElements = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']; diff --git a/jTDAL.min.js b/jTDAL.min.js index 4c6552b..e4bb073 100644 --- a/jTDAL.min.js +++ b/jTDAL.min.js @@ -1 +1 @@ -"use strict";var jTDAL;!function(t){const e="(?:[\\w-\\/]*[\\w](?:[\\s]*\\|[\\s]*[\\w-\\/]*[\\w])*)",i="(?:(?:!)?[\\w-\\/]*[\\w](?:[\\s]*\\|[\\s]*[\\w-\\/]*[\\w])*)",r="(STRING:[^;]+|"+i+")",n={tagWithTDAL:new RegExp("<((?:\\w+:)?\\w+)(\\s+[^<>]+?)??\\s+data-tdal-(?:"+["condition","repeat","content","replace","attributes","omittag"].join("|")+")=(['\"])(.*?)\\3(\\s+[^<>]+?)??\\s*(/)?>","i"),tagWithAttribute:new RegExp("<((?:w+:)?w+)(s+[^<>]+?)??s+%s=(['\"])(.*?)\\3(s+[^<>]+?)??s*(/)?>","i"),tagAttributes:new RegExp("(?<=\\s)((?:[\\w-]+:)?[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi"),pathString:new RegExp("(?:{("+e+")}|{\\?("+i+")}(.*?){\\?\\2})"),pathInString:new RegExp("{("+e+")}","g"),conditionInString:new RegExp("{\\?("+i+")}(.*?){\\?\\1}","g"),condition:new RegExp("^[\\s]*("+r+")[\\s]*$"),repeat:new RegExp("^[\\s]*([\\w-]+?)[\\s]+("+e+")[\\s]*$"),content:new RegExp("^[\\s]*(?:(text|structure)[\\s]+)?("+r+")[\\s]*$"),attributes:new RegExp("[\\s]*(?:(?:([\\w-]+?)[\\s]+("+r+")[\\s]*)(?:;[\\s]*|$))","g"),attributesTDAL:new RegExp("\\s*(data-tdal-[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi")},l=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"];function s(t){let e='""',i=null;for(;null!=(i=n.pathString.exec(t));)if(0]*(?","gi");let l=1;for(;void 0===e[0]&&null!==(r=n.exec(t));)r[1]?l--:l++,0==l&&(e=[r.index,r[0].length]);void 0===e[0]?a=!0:(u[4]+=o(t.substr(0,e[0])),u[6]+=t.substr(e[0],e[1]),t=t.substr(e[0]+e[1]))}t:{if(s["data-tdal-condition"]&&n.condition.exec(s["data-tdal-condition"][3])){let t=f(s["data-tdal-condition"][3],!0);if("false"===t)break t;"true"!==t&&(u[0]+="+(true==="+t+'?""',u[7]=':"")'+u[7])}let t;if(s["data-tdal-repeat"]&&(t=n.repeat.exec(s["data-tdal-repeat"][3]))){let e=f(t[2]);if("false"==e||'""'==e||"true"==e)break t;u[0]+="+(",u[0]+="false!==(t[i++]="+e+")&&",u[0]+="(!Array.isArray(t[--i])||(t[i]=Object.assign({},t[i])))&&",u[0]+='("object"===typeof t[i]&&null!==t[i]&&0$/,""),!a||""==u[4]&&""==u[3]&&""==u[5]||(u[6]="",a=!1),e+=u[0]+"+"+JSON.stringify(String(u[1]))+u[2]+(""!=u[1]?'+"'+(a?"/":"")+'>"':"")+u[3]+u[4]+u[5]+"+"+JSON.stringify(String(u[6]))+u[7]}return e+="+"+JSON.stringify(String(t)),e}function u(t,e=!0,i=!0){return('let r={"REPEAT":{}},i=0,t=[];return '+(e?"(":"")+'""'+o(i?t.replace(//gs,""):t)).replace(/(?]+?)??\\s+data-tdal-(?:"+["condition","repeat","content","replace","attributes","omittag"].join("|")+")=(['\"])(.*?)\\3(\\s+[^<>]+?)??\\s*(/)?>","i"),tagWithAttribute:new RegExp("<((?:w+:)?w+)(s+[^<>]+?)??s+%s=(['\"])(.*?)\\3(s+[^<>]+?)??s*(/)?>","i"),tagAttributes:new RegExp("(?<=\\s)((?:[\\w-]+:)?[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi"),pathString:new RegExp("(?:{("+e+")}|{\\?("+i+")}(.*?){\\?\\2})"),pathInString:new RegExp("{("+e+")}","g"),conditionInString:new RegExp("{\\?("+i+")}(.*?){\\?\\1}","g"),condition:new RegExp("^[\\s]*("+r+")[\\s]*$"),repeat:new RegExp("^[\\s]*([\\w-]+?)[\\s]+("+e+")[\\s]*$"),content:new RegExp("^[\\s]*(?:(text|structure)[\\s]+)?("+r+")[\\s]*$"),attributes:new RegExp("[\\s]*(?:(?:([\\w-]+?)[\\s]+("+r+")[\\s]*)(?:#[\\s]*|$))","g"),attributesTDAL:new RegExp("\\s*(data-tdal-[\\w-]+)=(?:(['\"])(.*?)\\2|([^>\\s'\"]+))","gi")},l=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"];function s(t){let e='""',i=null;for(;null!=(i=n.pathString.exec(t));)if(0]*(?","gi");let l=1;for(;void 0===e[0]&&null!==(r=n.exec(t));)r[1]?l--:l++,0==l&&(e=[r.index,r[0].length]);void 0===e[0]?a=!0:(u[4]+=o(t.substr(0,e[0])),u[6]+=t.substr(e[0],e[1]),t=t.substr(e[0]+e[1]))}t:{if(s["data-tdal-condition"]&&n.condition.exec(s["data-tdal-condition"][3])){let t=f(s["data-tdal-condition"][3],!0);if("false"===t)break t;"true"!==t&&(u[0]+="+(true==="+t+'?""',u[7]=':"")'+u[7])}let t;if(s["data-tdal-repeat"]&&(t=n.repeat.exec(s["data-tdal-repeat"][3]))){let e=f(t[2]);if("false"==e||'""'==e||"true"==e)break t;u[0]+="+(",u[0]+="false!==(t[i++]="+e+")&&",u[0]+="(!Array.isArray(t[--i])||(t[i]=Object.assign({},t[i])))&&",u[0]+='("object"===typeof t[i]&&null!==t[i]&&0$/,""),!a||""==u[4]&&""==u[3]&&""==u[5]||(u[6]="",a=!1),e+=u[0]+"+"+JSON.stringify(String(u[1]))+u[2]+(""!=u[1]?'+"'+(a?"/":"")+'>"':"")+u[3]+u[4]+u[5]+"+"+JSON.stringify(String(u[6]))+u[7]}return e+="+"+JSON.stringify(String(t)),e}function u(t,e=!0,i=!0){return('let r={"REPEAT":{}},i=0,t=[];return '+(e?"(":"")+'""'+o(i?t.replace(//gs,""):t)).replace(/(?]+?)??\\s+data-tdal-(?:' + keywords.join( '|' ) + @@ -16,7 +16,7 @@ namespace jTDAL { 'condition': new RegExp( '^[\\s]*(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*$' ), 'repeat': new RegExp( '^[\\s]*([\\w-]+?)[\\s]+(' + regexpPatternPath + ')[\\s]*$' ), 'content': new RegExp( '^[\\s]*(?:(text|structure)[\\s]+)?(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*$' ), - 'attributes': new RegExp( '[\\s]*(?:(?:([\\w-]+?)[\\s]+(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*)(?:;[\\s]*|$))', 'g' ), + 'attributes': new RegExp( '[\\s]*(?:(?:([\\w-]+?)[\\s]+(' + regexpPatternExpressionAllowedBoolean + ')[\\s]*)(?:#[\\s]*|$))', 'g' ), 'attributesTDAL': new RegExp( '\\s*(data-tdal-[\\w-]+)=(?:([\'"])(.*?)\\2|([^>\\s\'"]+))', 'gi' ) }; // {\?((?:[\w-\/]*[\w](?:[\s]*\|[\s]*[\w-\/]*[\w])*))}(.*?){\?(?:[\w-\/]*[\w](?:[\s]*\|[\s]*[\w-\/]*[\w])*)}