How to use the mustache.render function in mustache

To help you get started, we’ve selected a few mustache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1PhoenixM / avior-service / node_modules / sails / node_modules / i18n / i18n.js View on Github external
msg = translate(getLocaleFromObject(this), singular, plural);
  }
  if (count == null) count = namedValues.count;

  // parse translation and replace all digets '%d' by `count`
  // this also replaces extra strings '%%s' to parseble '%s' for next step
  // simplest 2 form implementation of plural, like https://developer.mozilla.org/en/docs/Localization_and_Plurals#Plural_rule_.231_.282_forms.29
  if (count > 1) {
    msg = vsprintf(msg.other, [parseInt(count, 10)]);
  } else {
    msg = vsprintf(msg.one, [parseInt(count, 10)]);
  }

  // if the msg string contains {{Mustache}} patterns we render it as a mini tempalate
  if ((/{{.*}}/).test(msg)) {
    msg = Mustache.render(msg, namedValues);
  }

  // if we have extra arguments with strings to get replaced,
  // an additional substition injects those strings afterwards
  if ((/%/).test(msg) && args && args.length > 0) {
    msg = vsprintf(msg, args);
  }

  return msg;
};
github yzane / vscode-markdown-pdf / extension.js View on Github external
var filename = path.join(__dirname, 'template', 'template.html');
    var template = readFile(filename);

     // read mermaid javascripts
     var mermaid = readFile(path.join(__dirname, 'node_modules', 'mermaid', 'dist', 'mermaid.min.js'));

    // compile template
    var mustache = require('mustache');

    var view = {
      title: title,
      style: style,
      content: data,
      mermaid: mermaid
    };
    return mustache.render(template, view);
  } catch (error) {
    showErrorMessage('makeHtml()', error);
  }
}
github jvitela / mustache-wax / test / spec.js View on Github external
it('Should call formatter with one additional integer parameter', () => {
            const result1 = Mustache.render("{{ name | lpad:30 }}", data);
            expect(result1).to.equal(fmt.lpad(data.name, 30));
        })
github standard-release / app / index.js View on Github external
const fp = path.resolve(config.templatePath);
    template = await readFile(fp);
  }

  const repository = context.payload.repository.full_name;
  const [date] = context.payload.head_commit.timestamp.split('T');
  const { currentVersion: prev, nextVersion: next } = opts;
  const compareLink = `https://github.com/${repository}/compare/v${prev}}...v${next}}`;

  const locals = Object.assign({}, config.locals, opts, {
    date,
    repository,
    compareLink,
  });

  return mustache.render(template, locals);
}
github sirensolutions / sentinl / server / lib / actions.js View on Github external
*      "from" : "sentinl@localhost",
    *      "subject" : "Alarm Title",
    *      "priority" : "high",
    *      "body" : "Series Alarm {{ payload._id}}: {{payload.hits.total}}",
    *      "html" : "<p>Series Alarm {{ payload._id}}: {{payload.hits.total}}</p>",
    *      "stateless" : false
    *	    }
    */
    var html;
    if (_.has(action, 'email_html')) {
      formatterS = action.email_html.subject ? action.email_html.subject : 'SENTINL: ' + key;
      formatterB = action.email_html.body ? action.email_html.body : 'Series Alarm {{ payload._id}}: {{payload.hits.total}}';
      formatterC = action.email_html.body ? action.email_html.body : '<p>Series Alarm {{ payload._id}}: {{payload.hits.total}}</p>';
      subject = mustache.render(formatterS, {payload: payload});
      body = mustache.render(formatterB, {payload: payload});
      html = mustache.render(formatterC, {payload: payload});
      priority = action.email_html.priority ? action.email_html.priority : 'INFO';
      server.log(['status', 'info', 'Sentinl', 'email_html'], 'Subject: ' + subject + ', Body: ' + body + ', HTML:' + html);

      if (!emailServer || !config.settings.email.active) {
        server.log(['status', 'info', 'Sentinl', 'email_html'], 'Delivery Disabled!');
      }
      else {
        server.log(['status', 'info', 'Sentinl', 'email'], 'Delivering to Mail Server');
        emailServer.send({
          text: body,
          from: action.email_html.from,
          to: action.email_html.to,
          subject: subject,
          attachment: [{data: html, alternative: true}]
        }, function (err, message) {
          server.log(['status', 'info', 'Sentinl', 'email_html'], err || message);
github navikt / nav-frontend-moduler / _scripts / generateReadmes.js View on Github external
DISCLAIMER() {
                const renderdata = { name: moduleName };
                return mustache.render(disclaimerMD, renderdata);
            },
            INSTALL() {
github mineral-ui / mineral-ui / packages / mineral-ui-icons / scripts / build-icons.js View on Github external
async function generateIndex(components) {
  const template = await fs.readFile(INDEX_TEMPLATE_PATH, 'utf8');
  Mustache.parse(template);

  const content = Mustache.render(template, { components });
  const filePath = path.join(COMPONENTS_DIR, 'index.js');

  return fs.writeFile(filePath, content);
}
github flowup / api-client-generator / src / generator.ts View on Github external
async function generateModuleExportIndex(viewContext: MustacheData, outputPath: string): Promise {
  const exportTemplate = (await promisify(readFile)(`${__dirname}/../templates/ngx-module-export.mustache`)).toString();
  const result = Mustache.render(exportTemplate, viewContext);
  const outfile = join(outputPath, '/index.ts');

  await promisify(writeFile)(outfile, result, 'utf-8');
  return [outfile];
}
github jedrichards / portfolio / site / js / portfolio / views / about / about-view.js View on Github external
if ( data.twitter ) {
                data.twitter.text = DataFormatting.linkifyTweetText(data.twitter.text);
                data.twitter.dateText = DataFormatting.getTimeAgo(data.twitter.date);
                this.appendSocialItem(Mustache.render(require("text!portfolio/templates/about/twitter.mustache"),data.twitter));
            }

            if ( data.github ) {
                data.github.dateText = DataFormatting.getTimeAgo(data.github.date);
                data.github.sha = data.github.sha.substring(0,6);
                data.github.repoUrl = "https://github.com/"+data.github.repo;
                this.appendSocialItem(Mustache.render(require("text!portfolio/templates/about/github.mustache"),data.github));
            }

            if ( data.foursquare ) {
                data.foursquare.dateText = DataFormatting.getTimeAgo(data.foursquare.date);
                this.appendSocialItem(Mustache.render(require("text!portfolio/templates/about/foursquare.mustache"),data.foursquare));
            }

            if ( data.lastfm ) {
                data.lastfm.dateText = DataFormatting.getTimeAgo(data.lastfm.date);
                data.lastfm.verb = data.lastfm.nowPlaying === "true" ? "Listening" : "Listened";
                this.appendSocialItem(Mustache.render(require("text!portfolio/templates/about/lastfm.mustache"),data.lastfm));
            }
        },
github Enalean / tuleap / src / scripts / FlamingParrot / project-privacy.js View on Github external
const template = render(
        `<div class="popover current-project-nav-popover current-project-nav-popover-privacy">
                <div class="arrow"></div>
                <h3>{{ title }}</h3>
                <div class="popover-content"></div>
        </div>`,
        {
            title:
                project_flags.length &gt; 0
                    ? project_privacy_element.dataset.projectName
                    : project_privacy_element.dataset.privacyTitle,
        }
    );

    const content = render(
        `{{# has_project_flags }}
            <div class="current-project-nav-flag-popover-flag">
                <i class="fa {{ privacy_icon}}"></i>
                <h2 class="current-project-nav-flag-popover-content-title">
                    {{ privacy_title }}
                </h2>
                <p class="current-project-nav-flag-popover-content-description">{{ privacy_description }}</p>
            </div>
            <hr class="current-project-nav-flag-popover-separator">
            {{# project_flags }}
                <div class="current-project-nav-flag-popover-flag">
                    ${shield_icon_html}
                    <h2 class="current-project-nav-flag-popover-content-title">
                        {{ label }}
                    </h2>
                    {{# description }}</div>