Example #1
0
exports.index = function (req) {
    var template = getResource("./templates/index.html").content;
    return response.html(
        mustache.to_html(template, {
            title: "It's working!"
        })
    );
};
Example #2
0
var buildFile = function(path) {
   if (fs.isLink(path)) {
      traverse(path + '/');
      return;
   } else if (fs.isDirectory(path)) {
      return;
   }
   var context = {
      content: renderMarkdown(path),
      baseUri: opts.baseuri || '/'
   };
   var html = mustache.to_html(masterContent, context);
   var relativePath = fs.relative(opts.contentdir, path);
   relativePath = relativePath.slice(0, -3) + '.html';
   var outPath = fs.join(opts.outputdir, relativePath);
   fs.makeTree(fs.directory(outPath));
   fs.write(outPath, html);
}
Example #3
0
    '<Url',
    'type="text/html"',
    'method="GET"',
    'template="' + medial_query + '{searchTerms}" />',
    '<Url',
    'type="application/x-suggestions+json"',
    'template="http://' + host + ':' + port + '/{{type}}/{searchTerms}" />',
    '<moz:SearchForm>' + app_base + '</moz:SearchForm>',
    '</OpenSearchDescription>'
].join(' ');

var term_tmpl_args = {
    'type': 'term',
    'readable_type': 'term'
};
var osddoc_term = mustache.to_html(osddoc_tmpl, term_tmpl_args);

var gp_tmpl_args = {
    'type': 'gene_product',
    'readable_type': 'gene product'
};
var osddoc_gp = mustache.to_html(osddoc_tmpl, gp_tmpl_args);
		 
///
/// Helper functions.
///

// Wrapper for the common returns.
function common_doc(string, status, type){
    if( ! string ){ string = ''; }
    if( ! status ){ status = 200; }
Example #4
0
exports.app = function(req) {
   var path = req.pathInfo;
   if (path === '/json') {
      var helloObject = {message: "Hello, World!"};
      // JSON Response Test
      return {
         status: 200,
         headers: {"Content-Type": "application/json; charset=UTF-8"},
         body: [JSON.stringify(helloObject)]
      }
   } else if (path === '/db') {
      var queryCount = req.env.servletRequest.getParameter('queries');
      try {
         var connection = datasource.getConnection();
         if (queryCount === null) {
            var randId = ((Math.random() * 10000) | 0) + 1
            var world = sql.query(connection, 'select * from World where World.id = ' + randId)[0];
            return {
               status: 200,
               headers: {"Content-Type": "application/json; charset=UTF-8"},
               body: [JSON.stringify(world)]
            }
         } else {
            queryCount = parseInt(queryCount, 10);
            var body = [];
            var randId, world;
            for (var i = 0; i < queryCount; i++) {
               randId = ((Math.random() * 10000) | 0) + 1;
               world = sql.query(connection, 'select * from World where World.id = ' + randId)[0];
               body.push(world);
            }
            return {
               status: 200,
               headers: {"Content-Type": "application/json; charset=UTF-8"},
               body: [JSON.stringify(body)]
            }
         }
      } catch (e) {
         connection.close();
         connection = null;
      } finally {
         if (connection !== null) {
            connection.close();
         }
      }
   } else if (path === '/fortune') {
      try {
         var connection = datasource.getConnection();
         var fortunes = sql.query(connection, 'select * from Fortune');
         fortunes.push({
            id: 0,
            message: 'Additional fortune added at request time.'
         });
         fortunes.sort(sortFortunes);
         return {
            status: 200,
            headers: {"Content-Type": "text/html; charset=UTF-8"},
            body: [mustache.to_html(fortuneTemplate, {fortunes: fortunes})]
         }
      } catch (e) {
         connection.close();
         connection = null;
      } finally {
         if (connection !== null) {
            connection.close();
         }
      }
   } else if (path === '/plaintext') {
      return {
        status: 200,
        headers: {"Content-Type": 'text/plain'},
        body: ['Hello, World!']
      };
   } else if (path === '/updates') {
      var queryCount = parseInt(req.env.servletRequest.getParameter('queries'), 10);
      if (isNaN(queryCount) || queryCount < 1) {
         queryCount = 1;
      } else if (queryCount > 500) {
         queryCount = 500;
      }
      try {
         var connection = datasource.getConnection();
         var body = [];
         for (var i = 0; i < queryCount; i++) {
            let randId = ((Math.random() * 10000) | 0) + 1;
            world = sql.query(connection, 'select * from World where World.id = ' + randId)[0];
            world.randomNumber = ((Math.random() * 10000) | 0) + 1;
            sql.execute(connection, 'UPDATE World SET randomNumber = ' + world.randomNumber + ' WHERE id = ' + world.id);
            body.push(world);
         }
      } catch (e) {
         connection.close();
         connection = null;
      } finally {
         if (connection !== null) {
            connection.close();
         }
      }
      return {
         status: 200,
         headers: {"Content-Type": "application/json; charset=UTF-8"},
         body: [JSON.stringify(body)]
      }
   }
};