Example #1
0
	private populateTemplate(mailData: Mailer): Promise<Mailer> {
		let deferred = Q.defer();
		mailData.message = Handlebars.compile(mailData.template.html)(mailData.templateData);
		mailData.template.subject = Handlebars.compile(mailData.template.subject)(mailData.templateData);
		deferred.resolve(mailData);
		return deferred.promise;
	}
Example #2
0
  getTemplateFunction() {
    // Template compilation
    // --------------------

    // This demo uses Handlebars templates to render views.
    // The template is loaded with Require.JS and stored as string on
    // the view prototype. On rendering, it is compiled on the
    // client-side. The compiled template function replaces the string
    // on the view prototype.
    //
    // In the end you might want to precompile the templates to JavaScript
    // functions on the server-side and just load the JavaScript code.
    // Several precompilers create a global JST hash which stores the
    // template functions. You can get the function by the template name:
    //
    // templateFunc = JST[@templateName];
    let template = this.template;
    let templateFunction: Function;

    if (typeof template === 'string') {
      // Compile the template string to a function and save it
      // on the prototype. This is a workaround since an instance
      // shouldn't change its prototype normally.

      templateFunction = Handlebars.compile(template);
      this.template = templateFunction;
    } else if (typeof template === 'function') {
      templateFunction = template;
    }

    return templateFunction;
  }
Example #3
0
function exportTexturePoolViaHandlebarsTemplate(
  folderRootTo: string,
  templateFolderAndFile: string,
  data: any,
) {
  let text = fs.readFileSync(templateFolderAndFile, 'utf8');
  if (text && text.length > 0) {
    text = text.replace(/\r/g, '');

    const lines = text.split('\n');
    if (lines.length > 1 && lines[0]) {
      const resultFile = path.resolve(folderRootTo, lines[0]);
      text = lines.slice(1).join('\n');

      console.log(`${templateFolderAndFile} => ${resultFile}`);
      const template = handlebars.compile(text);
      if (template) {
        fs.ensureDirSync(path.dirname(resultFile));
        fs.writeFileSync(resultFile, template(data));
      } else {
        console.log('template error in ' + resultFile);
      }
    }
  }
}
Example #4
0
Marionette.TemplateCache.prototype.compileTemplate = (rawTemplate: any): any => {
  if (_.isFunction(rawTemplate)) {
    return rawTemplate;
  } else {
    return Handlebars.compile(rawTemplate);
  }
};
Example #5
0
    private _compileTemplate(templatePath: string, data: Object) {
        const templateFileName = path.join(process.cwd(), templatePath);
        const templateFile = fs.readFileSync(templateFileName, 'UTF-8');

        const templateFunc: Function = handlebars.compile(templateFile);
        return templateFunc(data);
    }
Example #6
0
        .then((data) => {
            const [file, pack, meta] = data;
            const connectionTypes = ['mainnet', 'testnet'];

            if (!param.scripts) {
                const sourceFiles = getFilesFrom(join(__dirname, '../src'), '.js', function (name, path) {
                    return !name.includes('.spec') && !path.includes('/test/');
                });
                param.scripts = meta.vendors.map((i) => join(__dirname, '..', i)).concat(sourceFiles);
                param.scripts.push(join(__dirname, '../loginDaemon.js'));
            }

            if (!param.styles) {
                param.styles = meta.stylesheets.map((i) => join(__dirname, '..', i)).concat(getFilesFrom(join(__dirname, '../src'), '.less'));
            }

            const networks = connectionTypes.reduce((result, item) => {
                result[item] = meta.configurations[item];
                return result;
            }, Object.create(null));

            return compile(file)({
                pack: pack,
                domain: meta.domain,
                build: {
                    type: 'web'
                },
                network: networks[param.connection]
            });
        })
Example #7
0
        handler: function(request, reply) {
            let paths = getPaths(server, baseUri, filter);
            let source = fs.readFileSync(__dirname + '/sitemap.xml.hbs', 'utf8');

            let template = handlebars.compile(source);
            reply(template({paths: paths}))
                .type('application/xml');
        },
Example #8
0
function subHandle(fullPath: string, args: any) {
  wd = path.dirname(fullPath);
  let tmpl = fs.readFileSync(fullPath, 'utf8');

  var template = hbs.compile(tmpl.toString());
  var result = template(args);
  return result;
}
Example #9
0
export function loadTemplate(name: string): Template {

  const template = handlebars.compile(
    fs.readFileSync(__dirname + '/../templates/' + name + '.hbs', 'utf-8')
  );

  return template;

}
Example #10
0
      tmpl: function(resolver, templateString, refObj, wire) {
        var template = handlebars.compile(templateString);

        // get the entire wire context
        wire.createChild({}).
          // render the template with the context
          then(template).
          // resolve with the rendered template
          then(resolver.resolve).
          catch(resolver.reject);
      }