1.1.1 • Published 7 years ago

madex v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Madex

This module is under development, but you can try it now because it's ready to use already.

###Render dynamic data to your template easily. this module is superfast and lightweight, works using simple Js functions.

##Example

html index.html

	<body>
		<%name%> // single % for output
		<%% if (user){echo(user.name)}%> // double %% for controlling
		<%names[1]%>
		<%cat.color%>
		<%include("somefile.txt")%>
	</body>

now node.js

	
	var madex = require("madex");
	
	var data = fs.readFileSync("./index.html");
	
	var obj={
		name:"John",
		user:{name:"Smith"},
		name:["John", "Doe", "Smith"],
		cat : {color:"white", name:"mew"}
	}
	madex.render(data, obj, function(output){
		console.log(output);
	});
	

render() takes three params, first one the data read from file, second one an object containing to be rendered datas and third one a callback function with one param, the returning output.

echo() is a function introduced to print outputs, which takes one argument.

files get automatically included ( the last line in html page).

##change the delimeter if you dont like it

	madex.delim = "$" //or anything else
	

Sync version of render() is renderSync()

var output = madex.renderSync(data, obj);

two parameters. first one the data read from file and second one the list to be renderd datas.