Skip to content

andrewrk/swig-dummy-context

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

swig-dummy-context

Note: this module does not work with swig 1.x and beyond.

Given a swig template, produce a dummy context that you can immediately use to preview your template.

See also swig-email-templates

Example Usage

Contents of template.html:

<div>
  {{ description }}
</div>
{% if articles %}
  <ul>
  {% for article in articles %}
    <li>{{ article.name }}</li>
  {% endfor %}
  </ul>
{% else %}
  <p>{{ defaultText }}</p>
{% endif %}
var swig = require('swig')
  , createDummyContext = require('swig-dummy-context')

swig.init({
  allowErrors: true,
  root: path.join(__dirname, "templates"),
});
var template = swig.compileFile("template.html");
assert.deepEqual(createDummyContext(template), {
  "description": "description",
  "articles": [{
    "name": "name",
  }],
  "defaultText": "defaultText"
});

About

given a swig template, create a dummy context which is useful for template composing tools

Resources

License

Stars

Watchers

Forks

Packages

No packages published