https://github.com/andrejewski/stachedown
you got mustache in my markdown
https://github.com/andrejewski/stachedown
Last synced: 6 months ago
JSON representation
you got mustache in my markdown
- Host: GitHub
- URL: https://github.com/andrejewski/stachedown
- Owner: andrejewski
- License: isc
- Created: 2014-08-22T18:19:49.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-23T22:37:54.000Z (over 11 years ago)
- Last Synced: 2025-04-05T00:02:40.373Z (10 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Stachedown
==========
Stachedown renders Mustache templates written in Markdown.
## Installation
```bash
npm install stachedown
```
## Usage
Stachedown can be used to `render` HTML from Markdown-Mustache templates and `inject` Mustache directly into Markdown without rendering the Makrdown.
### Rendering HTML
```javascript
var Stachedown = require("stachedown"),
stachedown = Stachedown();
var template = "{{a}} is *{{b}}*.",
data = {a: 'Shrek', b: 'love'};
stachedown.render(template, data);
// => "
Shrek is love.
\n"
```
### Injecting Mustache
```javascript
var Stachedown = require("stachedown"),
stachedown = Stachedown();
var template = "{{a}} is *{{b}}*.",
data = {a: 'Shrek', b: 'love'};
stachedown.inject(template, data);
// => "Shrek is *love*."
```
## Configuration
Stachedown requires [mustache.js](https://github.com/janl/mustache.js) and [marked](https://github.com/chjj/marked). While it does not provided anything more than functions, Stachedown does expose its dependencies for their own configuration options.
```javascript
var Stachedown = require("stachedown"),
Marked = Stachedown.Marked,
Mustache = Stachedown.Mustache;
```
Marked options can also be passed directly to the Stachedown constructor and will be used for each render with that Stachedown instance. [See marked for more details.](https://github.com/chjj/marked#options-1)
```javascript
var Stachedown = require("stachedown"),
stachedown = Stachedown({marked options});
```
Stachedown can determine whether marked is configured asynchronously and adapt to compliment an asynchronous call.
```javascript
stachedown.render(template, data, function(error, html) {
// Note: This only works for #render().
// Stachedown#inject() is always synchronous.
});
```
## Strict Templating
Suppose a template is rendered with an object literal as data using Mustache. Mustache ignores missing and undefined variables in templates.
```javascript
Mustache.render('The {{important_thing}} must be visible.', {});
// => 'The must be visible.'
```
This output almost always is not ideal. Stachedown exposes two methods `#renderStrict()` and `#injectStrict()` to ensure variables exist when put into the template. They have the same function signatures as their `#render()` and `#inject()` counterparts.
```javascript
stachedown.renderStrict('The {{important_thing}} must be visible.', {});
// throws Error
```
While strict templating is not a direct goal of Stachedown, I thought the use case was good enough to include it within this module as an option.
## Contributing
Contributions are incredibly welcome as long as they are standardly applicable and pass the tests (or break bad ones). Tests are written in Mocha and assertions are done with the Node.js core `assert` module.
```bash
# running tests
npm run test
npm run test-spec # spec reporter
```
Follow me on [Twitter](https://twitter.com/compooter) for updates or just for the lolz and please check out my other [repositories](https://github.com/andrejewski) if I have earned it. I thank you for reading.