How to use hogan - 10 common examples

To help you get started, we’ve selected a few hogan 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 StreetSupport / streetsupport-web / src / js / page-services.js View on Github external
getApiData.data(categoryUrl).then(function (result) {
    // Append object name for Hogan
    var theData = { organisations: result }

    // Compile and render template
    var theTemplate = document.getElementById('js-category-result-tpl').innerHTML
    var compileTemplate = Hogan.compile(theTemplate)
    var theOutput = compileTemplate.render(theData)

    document.getElementById('js-category-result-output').innerHTML = theOutput

    loading.stop()
  })
})
github jxson / haiku / lib / template.js View on Github external
Template.prototype.set = function(key, content) {
  this.collection[key] = {
    template: hogan.compile(content),
    partials: hogan.scan(content)
      .filter(isPartial)
      .map(name)
  }

  // allows chaining like: t.set(k, v).render(ctx, cb)
  return {
    render: this.render.bind(this, key)
  }
}
github ftlabs / fruitmachine / test / helpers.js View on Github external
var Hogan = require('hogan.js');
var fruitmachine = require('../lib/');

var helpers = {};

/**
 * Templates
 */

var templates = helpers.templates = {
  'apple': Hogan.compile('{{{1}}}'),
  'layout': Hogan.compile('{{{1}}}{{{2}}}{{{3}}}'),
  'list': Hogan.compile('{{#children}}{{{child}}}{{/children}}'),
  'orange': Hogan.compile('{{text}}'),
  'pear': Hogan.compile('{{text}}')
};

/**
 * Module Definitions
 */

helpers.Views = {};

var Layout = helpers.Views.Layout = fruitmachine.define({
  name: 'layout',
  template: templates.layout,

  initialize: function() {},
  setup: function() {},
  teardown: function() {},
  destroy: function() {}
github ftlabs / fruitmachine / test / helpers.js View on Github external
var Hogan = require('hogan.js');
var fruitmachine = require('../lib/');

var helpers = {};

/**
 * Templates
 */

var templates = helpers.templates = {
  'apple': Hogan.compile('{{{1}}}'),
  'layout': Hogan.compile('{{{1}}}{{{2}}}{{{3}}}'),
  'list': Hogan.compile('{{#children}}{{{child}}}{{/children}}'),
  'orange': Hogan.compile('{{text}}'),
  'pear': Hogan.compile('{{text}}')
};

/**
 * Module Definitions
 */

helpers.Views = {};

var Layout = helpers.Views.Layout = fruitmachine.define({
  name: 'layout',
  template: templates.layout,

  initialize: function() {},
  setup: function() {},
  teardown: function() {},
github alphagov / pay-selfservice / lib / template-engine.js View on Github external
return function (templatePath) {
    var templateName = TemplateEngine._getTemplateName(basePath, templatePath)

    TemplateEngine.__templates[templateName] = Hogan.compile(FS.readFileSync(templatePath, 'utf-8'))

    if (argv.verbose) {
      console.log('Stored template', templateName)
    }
  }
}
github alphagov / pay-frontend / lib / template-engine.js View on Github external
return function (templatePath) {
    var templateName = TemplateEngine._getTemplateName(basePath, templatePath)

    TemplateEngine.__templates[templateName] = hogan.compile(fs.readFileSync(templatePath, 'utf-8'))

    if (argv.verbose) {
      console.log('Stored template', templateName)
    }
  }
}
github sethyuan / fgen / lib / fgen.js View on Github external
fs.readFile(filePath, "utf8", function(err, data) {
          if (err) {
            walker.removeAllListeners("file");
            self.emit("error", err);
          } else {
            self.templates_[key] = hogan.compile(data);
            next();
          }
        });
        break;
github openwhyd / openwhyd / app / templates / templateLoader.js View on Github external
fs.readFile(fileName, 'utf-8', function(err, data) {
    if (err) console.log('template.templateLoader ERROR ', err, err.stack);
    instance.template = hogan.compile(data);
    instance.render = function(params) {
      try {
        return this.template.render(params); //.replace(RE_AVATAR_URL, getFinalAvatarUrl);
      } catch (err) {
        console.log('template.templateLoader ERROR ', err, err.stack);
        return null;
      }
    };
    templateCache[fileName] = instance;
    if (callback) callback(instance, err);
  });
github alexyoung / nodejsinaction / ch08-templates / listing8_8 / index.js View on Github external
const hogan = require('hogan.js');
const md = require('github-flavored-markdown');
const templateSource = `
  {{#markdown}}**Name**: {{name}}{{/markdown}}
`;
const context = {
  name: 'Rick LaRue',
  markdown: () => text => md.parse(text)
};
const template = hogan.compile(templateSource);

console.log(template.render(context));
github aozora / bootmetro / build / page-builder.js View on Github external
function getCompiledFile(path){
   //console.log('getCompiledFile(\'' + path + '\')')
   var layout = fs.readFileSync(path, 'utf-8')
   layout = hogan.compile(layout, { sectionTags:[ {o:'_i', c:'i'} ] })
   return layout;
}

hogan

hogan === hogan.js

MIT
Latest version published 10 years ago

Package Health Score

45 / 100
Full package analysis

Popular hogan functions