ef starting point

by Yukino Song

HTML

<script src="https://unpkg.com/[email protected]/dist/ef.dev.js"></script>
<script type="text/efml" data-id="main">
>body
	>h1
  	.Welcome to the world of ef.js!
	+content
</script>
<script type="text/efml" data-id="hello">
>div
  >h2
    .Hello, {{name = World}}!
  >input
  	%value = {{name}}
</script>

JavaScript

const { create, t, inform, exec } = ef

const tpls = Array.prototype.reduce.call(
	document.querySelectorAll('script[type="text/efml"]'),
	(l, r) => {
		const content = r.textContent.trim()
		if (!content) {
			console.warn(`Skipping empty template "${r.dataset.id}"!`, r)
			return l
		}
		if (l[r.dataset.id]) {
			console.warn(`Duplicated template id "${r.dataset.id}"! Last template of this id will be used.`, r)
		}
		l[r.dataset.id] = create(r.textContent)
		return l
	},
	{}
)

inform()

const main = new tpls.main({
	content: [
  	new tpls.hello()
  ]
})

main.$mount({target: document.body, option: 'replace'})
exec()