Skip to content

Commit

Permalink
Raw value supported
Browse files Browse the repository at this point in the history
  • Loading branch information
ClassicOldSong committed Apr 30, 2017
1 parent d4388f1 commit 1d90487
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -42,6 +42,6 @@
"shelljs": "^0.7.5"
},
"dependencies": {
"eft-parser": "^0.5.3"
"eft-parser": "^0.5.4"
}
}
6 changes: 2 additions & 4 deletions src/lib/utils/element-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/literals-mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 21 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
6 changes: 3 additions & 3 deletions test/test_template.eft
Original file line number Diff line number Diff line change
@@ -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}}
Expand All @@ -20,3 +19,4 @@ this is a comment
.some text
-node2
+list1
/#([^}]|}[^}])*$/

0 comments on commit 1d90487

Please sign in to comment.