diff --git a/package.json b/package.json index 5f32752..33519d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ef.js", - "version": "0.2.1-alpha.3", + "version": "0.2.1-alpha.4", "description": "(maybe) An elegant HTML template engine & basic framework", "main": "dist/ef.min.js", "module": "src/ef.js", @@ -42,6 +42,6 @@ "shelljs": "^0.7.5" }, "dependencies": { - "eft-parser": "^0.5.3" + "eft-parser": "^0.5.4" } } diff --git a/src/lib/utils/element-creator.js b/src/lib/utils/element-creator.js index 2778074..5525de4 100644 --- a/src/lib/utils/element-creator.js +++ b/src/lib/utils/element-creator.js @@ -17,7 +17,7 @@ const regTmpl = ({val, state, handlers, subscribers, innerData, handler}) => { if (Array.isArray(val)) { const [strs, ...exprs] = val const tmpl = [strs] - const _handler = () => handler(mixVal(tmpl)) + const _handler = () => handler(mixVal(...tmpl)) tmpl.push(...exprs.map((item) => { const {dataNode, handlerNode, _key} = initBinding({bind: item, state, handlers, subscribers, innerData}) handlerNode.push(_handler) @@ -74,9 +74,7 @@ const addProp = ({element, prop, key, state, handlers, subscribers, innerData}) const _handler = regTmpl({val: prop, state, handlers, subscribers, innerData, handler}) if ((key === 'value' || key === 'checked') && - prop[0][0] === '' && - prop[0][1] === '' && - prop.length === 2) addValListener({_handler, state, handlers, subscribers, innerData, element, key, expr: prop[1]}) + !prop[0]) addValListener({_handler, state, handlers, subscribers, innerData, element, key, expr: prop[1]}) queue([_handler]) } } diff --git a/src/lib/utils/literals-mix.js b/src/lib/utils/literals-mix.js index 8c50a31..7180ac6 100644 --- a/src/lib/utils/literals-mix.js +++ b/src/lib/utils/literals-mix.js @@ -6,8 +6,8 @@ const mixStr = (strs, ...exprs) => { const getVal = ({dataNode, _key}) => dataNode[_key] -const mixVal = (tmpl) => { - const [strs, ...exprs] = tmpl +const mixVal = (strs, ...exprs) => { + if (!strs) return getVal(exprs[0]) const template = [strs] template.push(...exprs.map(getVal)) return mixStr(...template) diff --git a/test/test.js b/test/test.js index 712460a..d1c4e0a 100644 --- a/test/test.js +++ b/test/test.js @@ -13,14 +13,32 @@ var template = '\n\ >br\n\ .Message: \n\ >br\n\ - .Two way binded:\n\ + .Two way binded 1: \n\ >input\n\ #type = text\n\ %value = {{class.text}}\n\ - .One way binded:\n\ + >br\n\ + .Two way binded 2: \n\ + >input\n\ + #type = text\n\ + %value = {{class.text2 = 23333}}\n\ + >br\n\ + .One way binded with particle update:\n\ >input\n\ #type = text\n\ - %value = aaa {{class.text}} bbb\n\ + %value = 1: {{class.text}} 2: {{class.text2}}\n\ + >br\n\ + >input\n\ + #type = radio\n\ + #name = testradio\n\ + %checked = {{testRadio1}}\n\ + >input\n\ + #type = radio\n\ + #name = testradio\n\ + %checked = {{testRadio2}}\n\ + >input\n\ + #type = checkbox\n\ + %checked = {{testCheck}}\n\ >br\n\ .Input style here: \n\ >br\n\ diff --git a/test/test_template.eft b/test/test_template.eft index e709ccb..2891de4 100644 --- a/test/test_template.eft +++ b/test/test_template.eft @@ -1,13 +1,12 @@ this is a comment ->div - #class = {{class}} +>div.jji=&x23rwr&u02adwew&ni&u}}ddd}}...#lll{{}}}}s{{dfgrgs#jjj + #class = {{class}} {{sdffef=ssef}} #style = {{attr.style = &x23rwr&u02adwew&ni&u}} #id = testdiv #some-attr = some text #content = %title = {{name}} %anotherProperty = text - %contentEditable = {{edit}} @click = updateInfo @mousedown = setState .Name: {{name}}&nJob: {{job}} @@ -20,3 +19,4 @@ this is a comment .some text -node2 +list1 + /#([^}]|}[^}])*$/