raw/ace/mustache/js/classes/Page.js
function(data_dir) {
	var data_files = {}

	var format = new RegExp("([0-9a-z\\-_]+)\\.(json|csv)$" , "i");

	//see if there's a folder for partial data relating to this page or layout
	//if so iterate all json/csv files and load the data
	var partial_data_folder = data_dir + "/"+$type +"s/partials/" + $name;
	var stats;
	if(fs.existsSync(partial_data_folder) && (stats = fs.statSync(partial_data_folder)) && stats.isDirectory()) {
		var files = fs.readdirSync(partial_data_folder)
		files.forEach(function (name) {
			var filename;//file name, which we use as the variable name
			if (! (filename = name.match(format)) ) return;
			data_files[filename[1]] = partial_data_folder + "/" + name;
		})
	}


	for(var var_name in data_files) if(data_files.hasOwnProperty(var_name)) {

		var new_data
		try {
			if(data_files[var_name].match(/\.json$/i)) {
				new_data = fs.readFileSync(data_files[var_name] , 'utf-8');
				new_data = JSON.parse(new_data);
			} else if(data_files[var_name].match(/\.csv$/i)) {
				//load csv data into an array
				var csv_data = require(data_files[var_name]);
				
				//now convert it to json
				var csv_header = csv_data[0];
				var length = csv_data.length;

				var json_data = []
				for(var i = 1 ; i < length; i++) {
					var csv_row = csv_data[i];
					var json_row = {}
					for(var j = 0; j < csv_row.length; j++) {
						json_row[csv_header[j]] = csv_row[j];
					}
					//for example if we have "status":"pending" , add this to it as well : "pending":true
					if("status" in json_row) json_row[json_row["status"].toLowerCase()] = true;
					json_data.push(json_row);
				}
				
				new_data = json_data
			}
		} catch(e) {
			console.log("Invalid JSON Data File : " + data_files[var_name]);
			continue;
		}
		
		$vars[var_name.replace(/\./g , '_')] = new_data
		//here we replace '.' with '_' in variable names, so template compiler can recognize it as a variable not an object
		//for example change sidebar.navList to sidebar_navList , because sidebar is not an object

	}


  return true;
 }
function(data_dir) {
	var data_files = {}

	var format = new RegExp("([0-9a-z\\-_]+)\\.(json|csv)$" , "i");

	//see if there's a folder for partial data relating to this page or layout
	//if so iterate all json/csv files and load the data
	var partial_data_folder = data_dir + "/"+$type +"s/partials/" + $name;
	var stats;
	if(fs.existsSync(partial_data_folder) && (stats = fs.statSync(partial_data_folder)) && stats.isDirectory()) {
		var files = fs.readdirSync(partial_data_folder)
		files.forEach(function (name) {
			var filename;//file name, which we use as the variable name
			if (! (filename = name.match(format)) ) return;
			data_files[filename[1]] = partial_data_folder + "/" + name;
		})
	}


	for(var var_name in data_files) if(data_files.hasOwnProperty(var_name)) {

		var new_data
		try {
			if(data_files[var_name].match(/\.json$/i)) {
				new_data = fs.readFileSync(data_files[var_name] , 'utf-8');
				new_data = JSON.parse(new_data);
			} else if(data_files[var_name].match(/\.csv$/i)) {
				//load csv data into an array
				var csv_data = require(data_files[var_name]);
				
				//now convert it to json
				var csv_header = csv_data[0];
				var length = csv_data.length;

				var json_data = []
				for(var i = 1 ; i < length; i++) {
					var csv_row = csv_data[i];
					var json_row = {}
					for(var j = 0; j < csv_row.length; j++) {
						json_row[csv_header[j]] = csv_row[j];
					}
					//for example if we have "status":"pending" , add this to it as well : "pending":true
					if("status" in json_row) json_row[json_row["status"].toLowerCase()] = true;
					json_data.push(json_row);
				}
				
				new_data = json_data
			}
		} catch(e) {
			console.log("Invalid JSON Data File : " + data_files[var_name]);
			continue;
		}
		
		$vars[var_name.replace(/\./g , '_')] = new_data
		//here we replace '.' with '_' in variable names, so template compiler can recognize it as a variable not an object
		//for example change sidebar.navList to sidebar_navList , because sidebar is not an object

	}


  return true;
 }
function ( data_dir ) { var data_files = { } var format = new RegExp ( "([0-9a-z\\-_]+)\\.(json|csv)$" , "i" ) ; //see if there's a folder for partial data relating to this page or layout //if so iterate all json/csv files and load the data var partial_data_folder = data_dir + "/" + $type + "s/partials/" + $name ; var stats ; if ( fs . existsSync ( partial_data_folder ) && ( stats = fs . statSync ( partial_data_folder ) ) && stats . isDirectory ( ) ) { var files = fs . readdirSync ( partial_data_folder ) files . forEach ( function ( name ) { var filename ; //file name, which we use as the variable name if ( ! ( filename = name . match ( format ) ) ) return ; data_files [ filename [ 1 ] ] = partial_data_folder + "/" + name ; } ) } for ( var var_name in data_files ) if ( data_files . hasOwnProperty ( var_name ) ) { var new_data try { if ( data_files [ var_name ] . match ( / \.json$ / i ) ) { new_data = fs . readFileSync ( data_files [ var_name ] , 'utf-8' ) ; new_data = JSON . parse ( new_data ) ; } else if ( data_files [ var_name ] . match ( / \.csv$ / i ) ) { //load csv data into an array var csv_data = require ( data_files [ var_name ] ) ; //now convert it to json var csv_header = csv_data [ 0 ] ; var length = csv_data . length ; var json_data = [ ] for ( var i = 1 ; i < length ; i ++ ) { var csv_row = csv_data [ i ] ; var json_row = { } for ( var j = 0 ; j < csv_row . length ; j ++ ) { json_row [ csv_header [ j ] ] = csv_row [ j ] ; } //for example if we have "status":"pending" , add this to it as well : "pending":true if ( "status" in json_row ) json_row [ json_row [ "status" ] . toLowerCase ( ) ] = true ; json_data . push ( json_row ) ; } new_data = json_data } } catch ( e ) { console . log ( "Invalid JSON Data File : " + data_files [ var_name ] ) ; continue ; } $vars [ var_name . replace ( / \. / g , '_' ) ] = new_data //here we replace '.' with '_' in variable names, so template compiler can recognize it as a variable not an object //for example change sidebar.navList to sidebar_navList , because sidebar is not an object } return true ; }
This functions loads the data related to each page or layout
for a page we load all files in the related directory
for a layout we check the "datas-sources" attribute of our layout_file.json and load them
In your real world application you can load data only when it is needed according to each page inside controllers
This functions loads the data related to each page or layout for a page we load all files in the related directory for a layout we check the datas - sources attribute of our layout_file . json and load them In your real world application you can load data only when it is needed according to each page inside controllers