**********************************
modules/module/templates/templates.js
**********************************
325770
function (module) {
    
        var templates = {};
    
        this.register = function (path, template) {
    
            if (templates[path]) {
                console.error('template "' + path + '" is already registered in module "' + module.ID + '"');
            }
    
            templates[path] = template;
    
        };
    
        this.render = function (path, params) {
    
            if (!templates[path]) {
                console.error('invalid template path: "' + path + '"');
                return '';
            }
    
            return templates[path].render(params);
    
        };
    
    }
1222624
function (done) {
      var root = node_path.join(__dirname, 'templates', template);

      fs.exists(root, function(exists){
        if(exists){
          template_root = root;
        }else{
          template_root = node_path.join(DIR_CUSTOM_TEMPLATES, template)
        }
        done(null);
      });
    }
360763
function renderModule(context, options) {
	var  cacheKey
		,modSourceTemplate
		,mergedData
		,html
	;

	// this check is used when rendering isolated modules or views for development and testing (in the default layout!).
	// skip any modules that are not THE module or THE view.
	// view: skip all modules that have the attribute _isLayout="true"
	// module: skip all other modules
	if (
		context.skipModules === true ||                         // case: module
		context.skipModules == 'layout' && options._isLayout    // case: view
		)
	{ return ''; }

	options.template = options.template || options.name;
	options.tag = options.tag || defaults.tag;
	options.data = options.data || {};
	options.data.moduleNestingLevel = typeof context.moduleNestingLevel === 'undefined' ? 0 : context.moduleNestingLevel + 1;
	autoIncrementIndent = options.data.moduleNestingLevel > 0 ? 1 : false;
	options.data.indent = options.indent || autoIncrementIndent || context.indent || 0;

	// merge the request context and data in the module include, with the latter trumping the former.
	mergedData = _.merge({}, context, options.data);

	// create a unique identifier for the module/template combination
	cacheKey = options.name + ' ' + options.template;

	// If addTest exists it means we should pass module options into it for later client-side module testing.
	context._locals && context._locals.addTest && context._locals.addTest(options);

	// force reading from disk in development mode
	NODE_ENV == 'development' && (cache[cacheKey] = null);

	// if the module/template combination is cached use it, else read from disk and cache it.
	modSourceTemplate = cache[cacheKey] || (cache[cacheKey] = getModTemplate(options));

	// render the module source in the locally merged context
	// moduleSrc is a {{variable}} in the moduleWrapper template
	try {
		options.moduleSrc = modSourceTemplate.fn(mergedData);
	}
	catch (e) {
		if (process.env.NODE_ENV != 'test') {
			if (e instanceof RenderError)   // if this is our error from a nested template rethrow it.
				throw e;
			else                            // if this is the original Handlebars error, make it useful
				throw new RenderError('Module: ' + options.name + ', Template: ' + options.template + cfg.templateExtension +'\n'+ e.toString().replace(/^Error/, 'Reason'));
		}
	}


	if (options.noWrapper) {
		html = options.moduleSrc;
	}
	else {
		// if we have a persisted read error, add the error class to the module.
		modSourceTemplate.err && (options.classes = options.classes ? options.classes + ' xtc-error' : 'xtc-error');

		if (annotateModules) {
			options._module = modSourceTemplate.name;
			options._file = modSourceTemplate.file;
			options._path = modSourceTemplate.path;
			options._repository = modSourceTemplate.repository;
		}

		// render the wrapper template
		html = wrapperFn(options);
	}

	// manage indentation
	if (mergedData.indent) {
		html = utils.indent(html, mergedData.indent, cfg.indentString);
	}

	return html;
}
909017
function(template, options) {
    options = options || {};
    options.pretty = true;
    var fn = jade.compile(template, options);
    return fn(options.locals);
  }
678325
function( pathToTemplateDir ){

    this.templateDir = pathToTemplateDir;
    this.templates = {};

    this.updateEachHTMLFiles = this.updateEachHTMLFiles.bind( this );
    this.updateHTMLFile = this.updateHTMLFile.bind( this );
}
220883
function getTemplate (templates, fileName) {
  var extMatch = fileName.match(/\.([^\.]*)$/);
  if (extMatch && extMatch.length > 1)
    return templates[extMatch[1]];
  return null;
}
657095
function generatedJsFiles(what) {
        var ret = [];
        if ((!what || what === 'templates') && cog.getOption('template')) {
            ret.push({src: null, dst: cog.getOption('template')});
        }
        if (cog.getOption('compile_typescript')) {
            var src = srcTypescriptFiles();
            for (var i = 0; i < src.length; i++) {
                if (src[i].src.substr(-3) === '.ts') {
                    src[i].dst = src[i].src.substr(0, src[i].src.length - 3) + '.js';
                    ret.push(src[i]);
                }
            }
        }
        return ret;
    }
952210
function () {
			this.writeDebug('_loadTemplates');
			var source;
			var _this = this;
			var templateError = '<div class="bh-sl-error">Error: Could not load plugin templates. Check the paths and ensure they have been uploaded. Paths will be wrong if you do not run this from a web server.</div>';
			// Get the KML templates
			if (this.settings.dataType === 'kml' && this.settings.listTemplateID === null && this.settings.infowindowTemplateID === null) {

				// Try loading the external template files
				$.when(
					// KML infowindows
					$.get(this.settings.KMLinfowindowTemplatePath, function (template) {
						source = template;
						infowindowTemplate = Handlebars.compile(source);
					}),

					// KML locations list
					$.get(this.settings.KMLlistTemplatePath, function (template) {
						source = template;
						listTemplate = Handlebars.compile(source);
					})
				).then(function () {
					// Continue to the main script if templates are loaded successfully
					_this.locator();

				}, function () {
					// KML templates not loaded
					$('.' + _this.settings.formContainer).append(templateError);
					throw new Error('Could not load storeLocator plugin templates');
				});
			}
			// Handle script tag template method
			else if (this.settings.listTemplateID !== null && this.settings.infowindowTemplateID !== null) {
				// Infowindows
				infowindowTemplate = Handlebars.compile($('#' + this.settings.infowindowTemplateID).html());

				// Locations list
				listTemplate = Handlebars.compile($('#' + this.settings.listTemplateID).html());

				// Continue to the main script
				_this.locator();
			}
			// Get the JSON/XML templates
			else {
				// Try loading the external template files
				$.when(
					// Infowindows
					$.get(this.settings.infowindowTemplatePath, function (template) {
						source = template;
						infowindowTemplate = Handlebars.compile(source);
					}),

					// Locations list
					$.get(this.settings.listTemplatePath, function (template) {
						source = template;
						listTemplate = Handlebars.compile(source);
					})
				).then(function () {
					// Continue to the main script if templates are loaded successfully
					_this.locator();

				}, function () {
					// JSON/XML templates not loaded
					$('.' + _this.settings.formContainer).append(templateError);
					throw new Error('Could not load storeLocator plugin templates');
				});
			}
		}
986563
function() {
  gulp.task('tpl-precompile', function() {
    return gulp.src([paths.src.partials])
    .pipe($.htmlmin({
      removeComments: true,
      collapseWhitespace: plugins.tpls.ext === '.jade' ? false : true
    }))
    .pipe(plugins.tpls.cmd(plugins.tpls.config))
    .on('error', handleError)
    .pipe($.defineModule('plain'))
    .pipe($.declare({
      namespace: 'R.templates',
      processName: function(file) {
        var dir = config.paths.src.partials || config.paths.src.templates;
        return file.slice(file.indexOf(dir) + dir.length).replace('.js', '');
      }
    }))
    .pipe($.concat('templates.js'))
    .pipe(gulp.dest(paths.out.js));
  });

  /* Template livereloading  */
  gulp.task('tpl-reload', ['tpl-precompile'], function() {
    return gulp.src([paths.src.views])
    .pipe($.livereload(lrport));
  });
}
795217
function (template) {
      var tree = this.getTree(template)
      var runTimePlugins

      // Copy so far runtime plugins were generated.
      runTimePlugins = this.runTimePlugins

      var blocks = this.blocks

      var outerBlocks = this.outerBlocks

      this.clear()
      // Nope, we do not want to clear the cache.
      // Refactor to maintain cache. Until that keep commented.
      // this.files = {};
      return {
        tree: tree,
        runTimePlugins: runTimePlugins,
        blocks: blocks,
        outerBlocks: outerBlocks
      }
    }
962543
function compile(templates) {
    templates.forEach(partial => {
      partials[partial.name] = Handlebars.compile(partial.source);
      Handlebars.registerPartial(partial.name, partials[partial.name]);
    });
  }
169911
function compile(template, context) {
        for (var name in context) {
            template = template.replace('{{' + name + '}}', context[name])
        }
        return template
    }
1240562
function Templater(options) {
  if (options == null) {
    options = { allowEval: true };
  }
  this.options = options;
  if (options.stack && Array.isArray(options.stack)) {
    this.stack = options.stack;
  }
  else if (typeof options.stack === 'string') {
    this.stack = [ options.stack ];
  }
  else {
    this.stack = [];
  }
  this.nodes = [];
}
1345382
function compileFile(module, filename) {
		const templateString = fs.readFileSync(filename, 'utf8');

		module.exports = handlebars.compile(templateString);
	}
584944
function renderTemplate(template, context) {
			try {
				var func = _.template(template.template);
				return func(context);
			}
			catch (e) {
				grunt.fail.fatal('Error while rendering template ' + template.filename + ': ' + e.message);
			}
		}
1218757
function template(files, staticPath) {
			return files ? files.map(function(filepath){
				paths = filepath.split(staticPath)[1].split('/')
				jsonpart = buildJsonPath(paths, filepath);
				return jsonpart;
			}) : ''
		}
853879
function Bobsled(opts)
{
  require('http').Server.call(this);

  if (typeof(opts) == "undefined") opts = {};

  this.port = ("port" in opts) ? opts.port : 8085; // reads like BOBS on an old calculator

  if ("env" in opts) this.env = opts.env;
  if ("uid" in opts) this.uid = opts.uid;
  if ("gid" in opts) this.gid = opts.gid;

  this.template_compiler = ("template_compiler" in opts) ? opts.template_compiler : function () { throw new Error("no template compiler configured"); };

  // TODO: support other template engines besides doT?
  //
  this.template_config = {
    evaluate:    /<%([\s\S]+?)%>/g, // some erb like delimiters
    interpolate: /<%=([\s\S]+?)%>/g,
    varname: ["Page", "Server"],
    strip: false,
    append: true
  };

  this.templates = {};

  // compile all templates, useful for checking correctness on startup
  this.compileTemplates = function() {
    for (var template_name in this.templates) this.templates[template_name].compile();
  };

  this.controllers = {
    template: function(pathinfo, request, response) {
      var template_name = pathinfo.basename || "index"
      if (template_name in this.templates) {
        this.templateResponder(template_name, pathinfo, response);
      } else {
        this.emit("notFound", pathinfo, request, response);
      }
    }.bind(this),
    "static": function(pathinfo, request, response) {
      var filename = "." + pathinfo.dirname + "/" + pathinfo.basename + pathinfo.extname;
      if (!fs.statSync(filename).isFile()) {
        this.emit("notFound", pathinfo, request, response);
      } else {
        response.writeHead(200, {"content-type": "text/css"}); // HACK TODO mimetype
        fs.readFile(filename, function (err, data) { response.end(data); });
      }
    }.bind(this),
    favicon: function(pathinfo, request, response) {
      response.writeHead(200, {"content-type": "image/x-icon"}); // TODO: set expires
      fs.readFile("favicon.ico", function (err, data) { response.end(data); });
    },
    notFound: function (pathinfo, request, response) {
      if ("404" in this.templates) {
        this.templateResponder("404", { statusCode: 404, pathinfo: pathinfo, request: request }, response);
      } else {
        response.writeHead(404, {"content-type": "text/plain"});
        response.end(request.url + " not found");
      }
    }.bind(this)
  };

  // TODO: config/recipe for default routes
  this.routes = {
    GET: {
      "/": {
        "favicon.ico": this.controllers.favicon,
        "*.html": this.controllers.template
      },
    },
    POST: { }
  };

  // setup static routes
  if (true) { // TODO: opts.static? (could pass in path?)
    var static_folders = {"css": "/css", "img": "/img", "js": "/js"}; // TODO: pass in opts?
    for (folder in static_folders) {
      if (fs.existsSync(folder) && fs.statSync(folder).isDirectory()) {
        this.routes.GET[static_folders[folder]] = { "*": this.controllers.static };
      }
    }
  }

  if (opts.env) {
    // TODO: make path part of config?
    this.routes.GET["/"]["env"] = function(pathinfo, request, response) {
      response.writeHead(200, {"content-type": "application/json"}); // TODO switch to HTML on extname
      var data = { env: process.env, uid: process.getuid(), os: {} };
      var os = require("os");
      ["hostname", "type", "platform", "arch", "release", "networkInterfaces", "cpus"].forEach(function (a) {
        data.os[a] = os[a]();
      });
      if (process.env.HOME) data.home = fs.readdirSync(process.env.HOME);
      // data.passwd = require("getpw").getpwuid(data.uid); (TODO: pass to constructor to eliminate hard dep)
      response.end(JSON.stringify(data, null, "  "));
    }
  }

  this.redirect = function(new_url, response) {
      response.writeHead(302, { 'Location': new_url });
      response.end();
  };

  this.on("notFound", this.controllers.notFound);

  this.route = function(request, response, body) {
    var parsed_url = url.parse(request.url, true);
    var method = request.method,
        dirname = path.dirname(parsed_url.pathname).replace(/\/*$/, ''), // strip any trailing slash
        extname = path.extname(parsed_url.pathname), // TODO: should have a default for extname?
        basename = path.basename(parsed_url.pathname, extname) || "index"; // TODO: configurable default basename?

    console.log("%s %s/%s%s", method, dirname, basename, extname); // TODO: add an on/off switch for this logging

    if (dirname == "") dirname = "/"; // special case root routes, where the leading and trailing slash are the same

    // TODO: add a switch for case (in)sensitivity
    // dirname = dirname.toLowerCase();
    // basename = basename.toLowerCase();

    var controller = this.controllers.notFound;
    if (this.routes[method] && this.routes[method][dirname]) {
       // find the most specific match possible
       var candidate, candidates = [basename + extname, basename, "*" + extname, "*"];
       while (candidate = candidates.shift()) {
         if (candidate in this.routes[method][dirname]) {
             controller = this.routes[method][dirname][candidate];
             break; // while
         }
       }
    }
    return controller({ dirname: dirname, basename: basename, extname: extname, query: parsed_url.query }, request, response, body);
  };
}