This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

8
node_modules/nunjucks/samples/express/js/app.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
nunjucks.configure('views', {
autoescape: true
});
// aboutTmpl({ poop: 'pooop<><>' }, function(err, res) {
// console.log(res);
// });

48
node_modules/nunjucks/samples/express/js/extensions.js generated vendored Normal file
View File

@@ -0,0 +1,48 @@
function RemoteExtension() {
this.tags = ['remote'];
this.parse = function(parser, nodes, lexer) {
// get the tag token
var tok = parser.nextToken();
// parse the args and move after the block end. passing true
// as the second arg is required if there are no parentheses
var args = parser.parseSignature(null, true);
parser.advanceAfterBlockEnd(tok.value);
// parse the body and move after block end
var body = parser.parseUntilBlocks('error', 'endtruncate');
var errorBody = null;
if (parser.skipSymbol('error')) {
parser.skip(lexer.TOKEN_BLOCK_END);
errorBody = parser.parseUntilBlocks('endremote');
}
parser.advanceAfterBlockEnd();
return new nodes.CallExtension(this, 'run', args, [body, errorBody]);
};
this.run = function(context, url, body, errorBody) {
var id = 'el' + Math.floor(Math.random() * 10000);
var ret = new nunjucks.runtime.SafeString('<div id="' + id + '">' + body() + '</div>');
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (ajax.readyState == 4) {
if (ajax.status == 200) {
document.getElementById(id).innerHTML = ajax.responseText;
} else {
document.getElementById(id).innerHTML = errorBody();
}
}
};
ajax.open('GET', url, true);
ajax.send();
return ret;
};
}

37
node_modules/nunjucks/samples/express/main.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
/* eslint-disable func-names */
'use strict';
var path = require('path');
var nunjucks = require('../..');
var express = require('express');
var app = express();
nunjucks.configure(path.join(__dirname, 'views'), {
autoescape: true,
express: app,
watch: true
});
// app
app.use(express.static(__dirname));
app.use(function(req, res, next) {
res.locals.user = 'hello';
next();
});
app.get('/', function(req, res) {
res.render('index.html', {
username: 'James Long <strong>copyright</strong>'
});
});
app.get('/about', function(req, res) {
res.render('about.html');
});
app.listen(4000, function() {
console.log('Express server running on http://localhost:4000');
});

28
node_modules/nunjucks/samples/express/pre.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env node
'use strict';
var precompileString = require('../..').precompileString;
var fs = require('fs');
var path = require('path');
var out = 'window.baseTmpl = ' +
precompileString(
fs.readFileSync(path.join(__dirname, 'views/base.html'), 'utf-8'), {
name: 'base.html',
asFunction: true
});
out += 'window.aboutTmpl = ' +
precompileString(
fs.readFileSync(path.join(__dirname, 'views/about.html'), 'utf-8'), {
name: 'about.html',
asFunction: true
});
fs.writeFileSync(path.join(__dirname, 'js/templates.js'), out, 'utf-8');
fs.writeFileSync(path.join(__dirname, 'js/nunjucks.js'),
fs.readFileSync(path.join(__dirname, '../../browser/nunjucks.js'), 'utf-8'),
'utf-8');

12
node_modules/nunjucks/samples/express/views/about.html generated vendored Normal file
View File

@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block content %}
This is just the about page
{% endblock %}
{% block footer %}
{{ super() }}
You really should read this!
{{ poop }}
{% endblock %}

28
node_modules/nunjucks/samples/express/views/base.html generated vendored Normal file
View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>A quick app</title>
<style>
body {
background-color: #ccffcc;
}
.footer {
margin-top: 5em;
font-size: .75em;
}
</style>
<script src="/js/nunjucks.js"></script>
<script src="/js/templates.js"></script>
<script src="/js/app.js"></script>
</head>
<body>
{% block content %}{% endblock %}
<div class="footer">
{% block footer %}(c) James Long 2012{% endblock %}
</div>
</body>
</html>

View File

@@ -0,0 +1 @@
{% set bar = "FOO" %}

View File

@@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block content %}
Hello, {{ username | default('poop') | safe }}! This is just some content.
<div id="dynamic"></div>
{% endblock %}

View File

@@ -0,0 +1,6 @@
Editing item: {{ name }}
{% block description %}
A basic description is: {{ desc }}
{% endblock %}

View File

@@ -0,0 +1,7 @@
{% extends "item-base.html" %}
{% block description %}
I told you, it's name is {{ name }}.
It also has the description: {{ desc }}.
{% endblock %}

1
node_modules/nunjucks/samples/express/views/set.html generated vendored Normal file
View File

@@ -0,0 +1 @@
{% set username = "foooo" %}