Beispiel #1
0
router.get('/', function(req, res, next) {
	var indexPage = pug.compileFile('views/index.pug');
	var layout = pug.compileFile('views/layout.pug', {
		filters: {
			'content': function () {
			    return indexPage({ data: data });
			  }
		}
	});
	var html = layout({ 
		title: data.meta.title,
		description: data.meta.description
	});
	res.send(html);
});
 glob(LOCATION + '/*.json', function(err, files){
   if(err) throw err;
   var countryFiles = [];
   var countryNames = [];
   files.forEach( (filePath) => {
     // find its name
     var fileName = path.basename(filePath);
     var countryFile = fileName.substring(0, fileName.length-5)
     var countryName = countryFile.replace(/_/g, ' ');
     var countryChineseName = NAMES[countryName];
     if(countryName in NAMES){
       countryFiles.push('echarts-countries-js/' + countryFile + '.js');
       countryNames.push(NAMES[countryName]);
     }else{
       console.log("Ignored " + countryName);
     }
   });
   countryFiles.push('echarts-countries-js/china.js');
   countryFiles.push('echarts-countries-js/world.js');
   countryNames.push('china');
   countryNames.push('world');
   var index = pug.compileFile(path.join("templates", "index.pug"));
   var options = {num_countries: countryFiles.length,
                  countryFiles: countryFiles,
                  countries: countryNames};
   fs.writeFile('preview.html', index(options), function(err){
     if(err) throw err;
   });
 });
Beispiel #3
0
	function render(template, locals, next) {
		if (!locals) {
			locals = {};
		}
		locals.userModel = theUserModel.pluralModelName;
		locals.menu = tableNames;
		locals.adminGetUploadForProperty = adminGetUploadForProperty;
		locals.adminOptions = options;

		var templatePath = path.join(__dirname, '../views/', template);
		var fn = pug.compileFile(templatePath, {
			'pretty': true,
			'filename': templatePath
		});

		if (options.dashboard) {
			options.dashboard(function (err, dash) {
				locals.dashboardData = dash;
				var html = fn(extend(server.locals, locals));
				next(null, html);
			});
		}
		else {

			var html = fn(extend(server.locals, locals));
			next(null, html);
		}
	}
 it('should render a custom list group with custom style', function () {
     var fn = pug.compileFile(path.join(__dirname, "fixtures/list-groups", 'list-group-custom.pug'));
     var actual = '<div class="well list-group"><a class="list-group-item active" href="url1"><h4 class="list-group-item-heading">heading1</h4><p class="list-group-item-text">text1</p></a><a class="list-group-item" href="#url2" data-toggle="collapse"><i class="glyphicon glyphicon-chevron-right"></i>Collapsible item</a><div class="list-group collapse" id="url2"><h4 class="list-group-item-heading">heading2</h4><p class="list-group-item-text">text2</p><a class="list-group-item" href="url3"><h4 class="list-group-item-heading">heading3</h4><p class="list-group-item-text">text3</p></a></div></div>';
     var locals = {
         style: 'well'
     };
     assert.equal(actual, fn(locals));
 });
function compileTemplate(fileNameWithoutExtension, localObjectToExpose) {
    const pathToSourcePugFile = `${process.env.HTML}/${fileNameWithoutExtension}.pug`;

    const compiledFile = pug.compileFile(pathToSourcePugFile, pugOptions);
    const renderedHtmlString = compiledFile(localObjectToExpose);

    return renderedHtmlString;
}
Beispiel #6
0
var pugCompiler = function(filePrefix) {
    return pug.compileFile(
        __dirname + '/../sections/' + filePrefix + '.pug', {
            pretty: true,
            debug: false
        }
    );
};
Beispiel #7
0
 require.extensions['.pug'] = function compile(module, filename) {
   var template = pug.compileFile(filename, {
     pretty: false,
     client: true,
     inlineRuntimeFunctions: true,
   });
   module.exports = template
 }
Beispiel #8
0
 return new Promise((resolve, reject) => {
   const render = pug.compileFile(path.resolve(__dirname, `templates/${page.template}.pug`), {pretty:true});
   const html = render(props);
   fs.writeFile(path.resolve(__dirname, OUTPUT_DIR, page.filename), html, err => {
     if (err) return reject(err);
     resolve();
   });
 });
server.app.use('/', (_req, res) => {
  var locals = {
    props: JSON.stringify({ comments }),
  };
  var layout = `${process.cwd()}/index.pug`;
  var html = pug.compileFile(layout, { pretty: true })(locals);
  res.send(html);
});
Beispiel #10
0
function researcher(req) {
    debug("researcher page accesses, requestList %s", req.params.requestList);
    return {
        text: pug.compileFile('sections/research/researcher.pug', {
            pretty: true,
            debug: false
        })()
    };
};
Beispiel #11
0
function renderFile(path, rootPath) {
  var isPug = /\.(?:pug|jade)$/;
  var isIgnored = /([\/\\]_)|(^_)/;

  var stat = fs.lstatSync(path);
  // Found pug file
  if (stat.isFile() && isPug.test(path) && !isIgnored.test(path)) {
    // Try to watch the file if needed. watchFile takes care of duplicates.
    if (program.watch) watchFile(path, null, rootPath);
    if (program.nameAfterFile) {
      options.name = getNameFromFileName(path);
    }
    var fn = options.client
           ? pug.compileFileClient(path, options)
           : pug.compileFile(path, options);
    if (program.watch && fn.dependencies) {
      // watch dependencies, and recompile the base
      fn.dependencies.forEach(function (dep) {
        watchFile(dep, path, rootPath);
      });
    }

    // --extension
    var extname;
    if (program.extension)   extname = '.' + program.extension;
    else if (options.client) extname = '.js';
    else if (program.extension === '') extname = '';
    else                     extname = '.html';

    // path: foo.pug -> foo.<ext>
    path = path.replace(isPug, extname);
    if (program.out) {
      // prepend output directory
      if (rootPath) {
        // replace the rootPath of the resolved path with output directory
        path = relative(rootPath, path);
      } else {
        // if no rootPath handling is needed
        path = basename(path);
      }
      path = resolve(program.out, path);
    }
    var dir = resolve(dirname(path));
    mkdirp.sync(dir);
    var output = options.client ? fn : fn(options);
    fs.writeFileSync(path, output);
    consoleLog('  ' + chalk.gray('rendered') + ' ' + chalk.cyan('%s'), normalize(path));
  // Found directory
  } else if (stat.isDirectory()) {
    var files = fs.readdirSync(path);
    files.map(function(filename) {
      return path + '/' + filename;
    }).forEach(function (file) {
      render(file, rootPath || path);
    });
  }
}
Beispiel #12
0
 var toLoginIfUnauthenticated = function (req, res, next) {
     if (!/\.json/.test(req.path) && !/\.properties/.test(req.path) && enableAuth && !req.user) {
         // TODO sending the login page only makes sense for browser requests. if anybody is e.g. using curl to
         // retrieve message bundles, we should only return a 401 but no content
         res.status(401).send(pug.compileFile(__dirname + '/lib/client/pug/login.pug')());
     } else {
         next();
     }
 };
 it('should render a simple list group', function () {
     var fn = pug.compileFile(path.join(__dirname, "fixtures/list-groups", 'list-group.pug'));
     var actual = '<ul class="list-group"><li class="list-group-item">item1</li><li class="list-group-item active">item2</li><li class="list-group-item">item3</li></ul>';
     var locals = {
         items: items,
         active: 1
     };
     assert.equal(actual, fn(locals));
 });
 it('should render a link list group', function () {
     var fn = pug.compileFile(path.join(__dirname, "fixtures/list-groups", 'list-group-links.pug'));
     var actual = '<div class="list-group"><a class="list-group-item" href="url1">item1</a><a class="list-group-item active" href="url2">item2</a><a class="list-group-item" href="url3">item3</a></div>';
     var locals = {
         items: items,
         active: 1
     };
     assert.equal(actual, fn(locals));
 });
 it('should render a simple list ordered group with custom style', function () {
     var fn = pug.compileFile(path.join(__dirname, "fixtures/list-groups", 'list-group-ordered.pug'));
     var actual = '<ol class="well list-group"><li class="list-group-item">item1</li><li class="list-group-item active">item2</li><li class="list-group-item">item3</li></ol>';
     var locals = {
         items: items,
         active: 1,
         style: "well"
     };
     assert.equal(actual, fn(locals));
 });
Beispiel #16
0
 mainRouter.get('*', (req, res) => {
     if (config.translatronUi) {
         res.header('version', packageJSON.version)
         res.sendFile(__dirname + '/node_modules/@eightyfour84/translatron-ui/dist/index.html')
     } else {
         res.send(pug.compileFile(__dirname + '/lib/client/pug/index.pug')({
             version: packageJSON.version
         }));
     }
 });
Beispiel #17
0
    it("should generate a top tooltip", function(){
        let fn = pug.compileFile(path.join(__dirname, "fixtures/tooltips","top-tooltip.pug"));
        let locals = {
            text: "Top tooltip",
            tooltip: "Tooltip on the top",
            placement: "top"
        };

        let markup = `<a href="#" data-toggle="tooltip" data-placement="${locals.placement}" title="${locals.tooltip}">${locals.text}</a>`;
        assert.equal(markup,fn(locals));
    });
Beispiel #18
0
 function endStream(cb) {
     const htmlFile = new File({
       cwd: "/",
       base: "/",
       path: "/index.html"
     });
     const compile = pug.compileFile(path.join(__dirname, "./index.jade"));
     htmlFile.contents = new Buffer(compile({ icons, fontAlias: options.fontAlias, fontName: options.fontName }));
     this.push(htmlFile);
     cb();
 }
Beispiel #19
0
 render() {
   this.demos = [];
   const rawHtml = markdown(this.body, this);
   return pug(tmpl(this.attributes.template))(Object.assign({
     dirname,
     relative,
     jsStringify,
     rawHtml,
     id: this.attributes.id
   }, this));
 }
Beispiel #20
0
 $.render = function(filename) {
   $.header('Content-Type', 'text/html; charset=UTF-8')
   console.log(filename);
   filename ? (filename.indexOf('.pug')>-1 ? (options.file = filename) : (options.file = filename + '.pug')) : ($.error('No pug file specified'))
   var path = (options.path.slice(-1) === '/') ? options.path : options.path + '/'
   var fn = pug.compileFile(path + options.file, {
     pretty: true,
   })
   var html = fn($.data)
   // console.log(html);
   $.end(html)
 }
Beispiel #21
0
app.get("/:type/exercise", function(req,res){
	var exercise = require("./modules/" + req.params.type + ".js");
	var render   = pug.compileFile("./views/" + req.params.type + "/render.pug");

	// ook!
	var cookieName = cookie.getName (req.params.type);
	var exer = exercise.create (render, req.cookies[cookieName]);

	// for use with sllist+: if it has an ook!
	if (typeof (exer) === "object" && exer.ook){
		cookie.send (res, cookieName, exer.ook);
		exer = exer.exercise;
	}

	// send them the exercise
	res.status(200).send(exer);
});
module.exports = (key, config = {}) => async (invoiceId, data = {}) => {
  const stripe = new Stripe(key);
  if(!invoiceId) {
    throw new Error('missing_invoice_id');
  }
  const invoice = await stripe.invoices.retrieve(invoiceId);
  const tpld = template(Object.assign({
    currency_symbol: '$',
    label_invoice: 'invoice',
    label_invoice_to: 'invoice to',
    label_invoice_by: 'invoice by',
    label_due_on: 'Due on',
    label_invoice_for: 'invoice for',
    label_description: 'description',
    label_unit: 'unit',
    label_price: 'price ($)',
    label_amount: 'Amount',
    label_subtotal: 'subtotal',
    label_total: 'total',
    label_vat: 'vat',
    label_invoice_by: 'invoice by',
    label_invoice_date: 'invoice date',
    label_company_siret: 'Company SIRET',
    label_company_vat_number: 'Company VAT N°',
    label_invoice_number: 'invoice number',
    label_reference_number: 'ref N°',
    label_invoice_due_date: 'Due date',
    company_name: 'My company',
    date_format: 'MMMM Do, YYYY',
    client_company_name: 'Client Company',
    number: '12345',
    currency_position_before: true,
    language: 'en',
  }, invoice, config, data));
  return wkhtmltopdf(pug.compileFile(tpld.body)(Object.assign(tpld.data, {
    moment,
    path,
    fs,
    sizeOf
  })), { pageSize: 'letter' });
}
Beispiel #23
0
var renderTemplate = function(templateName, data){
  var renderHeadTemplate = pug.compile(
      'doctype html\n'
    + 'html\n'
    + ' head\n'
    + '   link(rel="stylesheet", href="/'+templateName+'/' + STD_CSS_FILENAME + '")\n'
    + '   title #{pageTitle}\n'
    ,options
    );

  //it compiles Jade File based on dynamic route
  var renderBodyTemplate = pug.compileFile(
                              TEMPLATE_FOLDER + '/'
                            + templateName + '/'
                            + STD_PUG_FILENAME
                            , options
                            );

  return renderHeadTemplate(data) + renderBodyTemplate(data);

}
Beispiel #24
0
'use strict';

let pug = require('pug'),
    fs = require('fs'),
    spawnSync = require('child_process').spawnSync,
    spawn = require('child_process').spawn,
    out = fs.openSync('./web.log', 'w'),
    err = fs.openSync('./web.log', 'w');

let index = pug.compileFile('../client/templates/index.pug');

fs.writeFileSync('../client/public/index.html', index({
    server: process.env.BRIDGET_SERVER
}));

spawnSync('pkill', ['-f', 'http-server'], {
    stdio: 'ignore'
});

process.chdir('../client');

spawn('http-server', ['-p', '2222'], {
    stdio: ['ignore', out, err],
    detached: true
}).unref();
Beispiel #25
0
 render (data = {}) {
   data.config = this.config
   const template = pug.compileFile(this.template)
   return Promise.resolve(template(data))
 }
Beispiel #26
0
const express = require('express');
const app = express();

const bodyParser = require('body-parser');
app.use(bodyParser.json());

const compression = require('compression');
app.use(compression({ threshold: 0 }));

const pug = require('pug');
const compiledTemplate = pug.compileFile('./views/index.pug');

app.use(express.static('dist'));

const apiController = require('./server/apiController').default;
app.use('/api', apiController);

app.get('/', (req, res) => {
    res.send(compiledTemplate({ title: 'PUG Compiled Workout Tracker' }));
});

app.listen(3000, function() {
    console.log("Listening on port 3000");
});
Beispiel #27
0
const express = require('express')
const path = require('path')
const dev = process.env.NODE_ENV === 'development'
const pug = require('pug')
const fs = require('fs')

const app = express()

app.db = require('./lib/db')

if (dev) app.use(require('morgan')('tiny'))
if (dev) app.use(require('stylus').middleware(path.join(__dirname, 'public')))
app.use(express.static(path.join(__dirname, '/public')))

app.locals = {
  srm2hex: require('srm2hex'),
  _: require('underscore'),
  rp: require('round-precision')
}

app.templates = {
  index: pug.compileFile(path.join(__dirname, 'views/index.pug'))
}

require('./routes')(app)

module.exports = app
Beispiel #28
0
 it("should generate a modal",function() {
     var fn = pug.compileFile(path.join(__dirname,"fixtures/modal","modal.pug"));
 });
Beispiel #29
0
tutorials.map(function (json) {
  var fn = pug.compileFile(path.relative('.', path.resolve(json.dir, 'index.pug')), {pretty: true});
  fs.writeFileSync(path.resolve(json.output, 'index.html'), fn(json));
});
Beispiel #30
0
var tutorials = buildUtils.getList('tutorials', 'tutorial', 'dist');

tutorials.map(function (json) {
  var fn = pug.compileFile(path.relative('.', path.resolve(json.dir, 'index.pug')), {pretty: true});
  fs.writeFileSync(path.resolve(json.output, 'index.html'), fn(json));
});

// copy common files
fs.copySync('tutorials/common', 'dist/tutorials/common');

// create the main tutorial page
var data = {
  hideNavbar: false,
  tutorialCss: ['main.css'],
  tutorialJs: ['main.js'],
  tutorials: tutorials,
  bundle: './bundle.js',
  about: {hidden: true},
  title: 'GeoJS'
};

// copy assets for the main page
fs.copySync('tutorials/main.js', 'dist/tutorials/main.js');
fs.copySync('tutorials/main.css', 'dist/tutorials/main.css');

var fn = pug.compileFile('./tutorials/index.pug', {pretty: true});
fs.writeFileSync(
  path.resolve('dist', 'tutorials', 'index.html'),
  fn(data)
);