Skip to content

Instantly share code, notes, and snippets.

@xicond
Created September 23, 2015 07:20
Show Gist options
  • Save xicond/9f8bcb33d66c789b866d to your computer and use it in GitHub Desktop.
Save xicond/9f8bcb33d66c789b866d to your computer and use it in GitHub Desktop.
"use strict";
var app = require('express')(),
swig = require('swig'),
async = require("async"),
sleep = require('sleep'),
people;
// This is where all the magic happens!
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
// Swig will cache templates for you, but you can disable
// that and use Express's caching instead, if you like:
app.set('view cache', false);
// To disable Swig's cache, do the following:
swig.setDefaults({ cache: false });
// NOTE: You should always cache templates in a production environment.
// Don't leave both of these to `false` in production!
app.get('/', function (req, res) {
var locals = [], asyncTasks = [];
var q = async.queue(function (task, callback) {
// console.log('hello ' + task.name);
callback();
}, 100);
for (var i=1; i<=5000; i++){
locals.push(i);
q.push({name: 'foo'+i}, function (err) {
for(var j=10000; j<=100000; j++){
locals[i-1] = locals[i-1]+j ;
}
// console.log(locals[i-1]);
// callback(null, 'folder');
});
}
/*async.parallel(asyncTasks, function(){
// All tasks are done now
console.log('in');
res.render('index', { *//* template locals context *//* });
res.end();
});*/
q.process();
while(q.length())sleep.usleep(1000);
// res.
res.render('index', { /* template locals context */ });
});
app.listen(1337);
console.log('Application Started on http://localhost:1337/');
@xicond
Copy link
Author

xicond commented Sep 23, 2015

{% extends 'layout.html' %}
{# views/index.html #}
{% block title %}My Page{% endblock %}

{% block head %}
{% parent %}

{% endblock %}

{% block content %}

This is just an awesome page.

{% endblock %}

@xicond
Copy link
Author

xicond commented Sep 23, 2015

{# views/layout.html #}
<!doctype html>

<title>{% block title %}My Site{% endblock %}</title>
{% block head %}
<link rel="stylesheet" href="main.css">
{% endblock %}
{% block content %}{% endblock %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment