Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@11ty/eleventy

Package Overview
Dependencies
Maintainers
1
Versions
189
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/eleventy - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

src/UserConfig.js

20

cmd.js

@@ -29,7 +29,4 @@ #!/usr/bin/env node

if (process.env.DEBUG) {
elev.setIsVerbose(false);
} else {
elev.setIsVerbose(!argv.quiet);
}
let isVerbose = process.env.DEBUG ? false : !argv.quiet;
elev.setIsVerbose(isVerbose);

@@ -41,2 +38,15 @@ elev.init().then(function() {

console.log(elev.getHelp());
} else if (argv.serve) {
elev.watch().then(function() {
const serve = require("serve");
const server = serve(elev.getOutputDir(), {
port: argv.port || 8080,
ignore: ["node_modules"]
});
process.on("SIGINT", function() {
server.stop();
process.exit();
});
});
} else if (argv.watch) {

@@ -43,0 +53,0 @@ elev.watch();

@@ -1,7 +0,7 @@

{"total": {"lines":{"total":1555,"covered":1353,"skipped":0,"pct":87.01},"statements":{"total":1557,"covered":1355,"skipped":0,"pct":87.03},"functions":{"total":333,"covered":277,"skipped":0,"pct":83.18},"branches":{"total":505,"covered":411,"skipped":0,"pct":81.39}}
{"total": {"lines":{"total":1576,"covered":1371,"skipped":0,"pct":86.99},"statements":{"total":1578,"covered":1373,"skipped":0,"pct":87.01},"functions":{"total":336,"covered":278,"skipped":0,"pct":82.74},"branches":{"total":513,"covered":418,"skipped":0,"pct":81.48}}
,"/Users/zachleat/Code/eleventy/config.js": {"lines":{"total":6,"covered":6,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":6,"covered":6,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/Users/zachleat/Code/eleventy/src/Config.js": {"lines":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":5,"covered":5,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/Users/zachleat/Code/eleventy/src/Eleventy.js": {"lines":{"total":151,"covered":81,"skipped":0,"pct":53.64},"functions":{"total":20,"covered":7,"skipped":0,"pct":35},"statements":{"total":151,"covered":81,"skipped":0,"pct":53.64},"branches":{"total":34,"covered":10,"skipped":0,"pct":29.41}}
,"/Users/zachleat/Code/eleventy/src/Eleventy.js": {"lines":{"total":155,"covered":84,"skipped":0,"pct":54.19},"functions":{"total":21,"covered":7,"skipped":0,"pct":33.33},"statements":{"total":155,"covered":84,"skipped":0,"pct":54.19},"branches":{"total":34,"covered":10,"skipped":0,"pct":29.41}}
,"/Users/zachleat/Code/eleventy/src/EleventyCommandCheck.js": {"lines":{"total":27,"covered":27,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":27,"covered":27,"skipped":0,"pct":100},"branches":{"total":8,"covered":7,"skipped":0,"pct":87.5}}
,"/Users/zachleat/Code/eleventy/src/EleventyConfig.js": {"lines":{"total":83,"covered":65,"skipped":0,"pct":78.31},"functions":{"total":25,"covered":18,"skipped":0,"pct":72},"statements":{"total":84,"covered":66,"skipped":0,"pct":78.57},"branches":{"total":28,"covered":16,"skipped":0,"pct":57.14}}
,"/Users/zachleat/Code/eleventy/src/EleventyConfig.js": {"lines":{"total":2,"covered":2,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/Users/zachleat/Code/eleventy/src/EleventyError.js": {"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}

@@ -19,5 +19,6 @@ ,"/Users/zachleat/Code/eleventy/src/Template.js": {"lines":{"total":247,"covered":223,"skipped":0,"pct":90.28},"functions":{"total":42,"covered":34,"skipped":0,"pct":80.95},"statements":{"total":247,"covered":223,"skipped":0,"pct":90.28},"branches":{"total":95,"covered":79,"skipped":0,"pct":83.16}}

,"/Users/zachleat/Code/eleventy/src/TemplatePermalink.js": {"lines":{"total":31,"covered":31,"skipped":0,"pct":100},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":31,"covered":31,"skipped":0,"pct":100},"branches":{"total":20,"covered":20,"skipped":0,"pct":100}}
,"/Users/zachleat/Code/eleventy/src/TemplateRender.js": {"lines":{"total":79,"covered":78,"skipped":0,"pct":98.73},"functions":{"total":17,"covered":17,"skipped":0,"pct":100},"statements":{"total":79,"covered":78,"skipped":0,"pct":98.73},"branches":{"total":36,"covered":34,"skipped":0,"pct":94.44}}
,"/Users/zachleat/Code/eleventy/src/TemplateRender.js": {"lines":{"total":81,"covered":80,"skipped":0,"pct":98.77},"functions":{"total":17,"covered":17,"skipped":0,"pct":100},"statements":{"total":81,"covered":80,"skipped":0,"pct":98.77},"branches":{"total":38,"covered":36,"skipped":0,"pct":94.74}}
,"/Users/zachleat/Code/eleventy/src/TemplateWriter.js": {"lines":{"total":155,"covered":103,"skipped":0,"pct":66.45},"functions":{"total":27,"covered":15,"skipped":0,"pct":55.56},"statements":{"total":155,"covered":103,"skipped":0,"pct":66.45},"branches":{"total":32,"covered":20,"skipped":0,"pct":62.5}}
,"/Users/zachleat/Code/eleventy/src/Engines/Ejs.js": {"lines":{"total":18,"covered":16,"skipped":0,"pct":88.89},"functions":{"total":7,"covered":5,"skipped":0,"pct":71.43},"statements":{"total":18,"covered":16,"skipped":0,"pct":88.89},"branches":{"total":4,"covered":3,"skipped":0,"pct":75}}
,"/Users/zachleat/Code/eleventy/src/UserConfig.js": {"lines":{"total":86,"covered":66,"skipped":0,"pct":76.74},"functions":{"total":27,"covered":18,"skipped":0,"pct":66.67},"statements":{"total":87,"covered":67,"skipped":0,"pct":77.01},"branches":{"total":28,"covered":16,"skipped":0,"pct":57.14}}
,"/Users/zachleat/Code/eleventy/src/Engines/Ejs.js": {"lines":{"total":22,"covered":21,"skipped":0,"pct":95.45},"functions":{"total":7,"covered":6,"skipped":0,"pct":85.71},"statements":{"total":22,"covered":21,"skipped":0,"pct":95.45},"branches":{"total":6,"covered":5,"skipped":0,"pct":83.33}}
,"/Users/zachleat/Code/eleventy/src/Engines/Haml.js": {"lines":{"total":10,"covered":10,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}

@@ -27,7 +28,7 @@ ,"/Users/zachleat/Code/eleventy/src/Engines/Handlebars.js": {"lines":{"total":18,"covered":18,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":18,"covered":18,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}

,"/Users/zachleat/Code/eleventy/src/Engines/JavaScript.js": {"lines":{"total":15,"covered":14,"skipped":0,"pct":93.33},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":15,"covered":14,"skipped":0,"pct":93.33},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"/Users/zachleat/Code/eleventy/src/Engines/Liquid.js": {"lines":{"total":33,"covered":33,"skipped":0,"pct":100},"functions":{"total":10,"covered":10,"skipped":0,"pct":100},"statements":{"total":33,"covered":33,"skipped":0,"pct":100},"branches":{"total":6,"covered":5,"skipped":0,"pct":83.33}}
,"/Users/zachleat/Code/eleventy/src/Engines/Markdown.js": {"lines":{"total":28,"covered":26,"skipped":0,"pct":92.86},"functions":{"total":8,"covered":7,"skipped":0,"pct":87.5},"statements":{"total":28,"covered":26,"skipped":0,"pct":92.86},"branches":{"total":10,"covered":8,"skipped":0,"pct":80}}
,"/Users/zachleat/Code/eleventy/src/Engines/Liquid.js": {"lines":{"total":34,"covered":34,"skipped":0,"pct":100},"functions":{"total":10,"covered":10,"skipped":0,"pct":100},"statements":{"total":34,"covered":34,"skipped":0,"pct":100},"branches":{"total":6,"covered":5,"skipped":0,"pct":83.33}}
,"/Users/zachleat/Code/eleventy/src/Engines/Markdown.js": {"lines":{"total":32,"covered":29,"skipped":0,"pct":90.63},"functions":{"total":8,"covered":7,"skipped":0,"pct":87.5},"statements":{"total":32,"covered":29,"skipped":0,"pct":90.63},"branches":{"total":14,"covered":11,"skipped":0,"pct":78.57}}
,"/Users/zachleat/Code/eleventy/src/Engines/Mustache.js": {"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"/Users/zachleat/Code/eleventy/src/Engines/Nunjucks.js": {"lines":{"total":20,"covered":19,"skipped":0,"pct":95},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":20,"covered":19,"skipped":0,"pct":95},"branches":{"total":4,"covered":3,"skipped":0,"pct":75}}
,"/Users/zachleat/Code/eleventy/src/Engines/Pug.js": {"lines":{"total":16,"covered":16,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":16,"covered":16,"skipped":0,"pct":100},"branches":{"total":4,"covered":3,"skipped":0,"pct":75}}
,"/Users/zachleat/Code/eleventy/src/Engines/Pug.js": {"lines":{"total":17,"covered":17,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":17,"covered":17,"skipped":0,"pct":100},"branches":{"total":4,"covered":3,"skipped":0,"pct":75}}
,"/Users/zachleat/Code/eleventy/src/Engines/TemplateEngine.js": {"lines":{"total":34,"covered":34,"skipped":0,"pct":100},"functions":{"total":11,"covered":11,"skipped":0,"pct":100},"statements":{"total":34,"covered":34,"skipped":0,"pct":100},"branches":{"total":6,"covered":6,"skipped":0,"pct":100}}

@@ -34,0 +35,0 @@ ,"/Users/zachleat/Code/eleventy/src/Filters/Slug.js": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}

@@ -1,11 +0,11 @@

# Code Coverage for Eleventy v0.3.1
# Code Coverage for Eleventy v0.3.2
| Filename | % Lines | % Statements | % Functions | % Branches |
| ------------------------------- | ------- | ------------ | ----------- | ---------- |
| `total` | 87.01% | 87.03% | 83.18% | 81.39% |
| `total` | 86.99% | 87.01% | 82.74% | 81.48% |
| `config.js` | 100% | 100% | 100% | 100% |
| `src/Config.js` | 100% | 100% | 100% | 100% |
| `src/Eleventy.js` | 53.64% | 53.64% | 35% | 29.41% |
| `src/Eleventy.js` | 54.19% | 54.19% | 33.33% | 29.41% |
| `src/EleventyCommandCheck.js` | 100% | 100% | 100% | 87.5% |
| `src/EleventyConfig.js` | 78.31% | 78.57% | 72% | 57.14% |
| `src/EleventyConfig.js` | 100% | 100% | 100% | 100% |
| `src/EleventyError.js` | 100% | 100% | 100% | 100% |

@@ -23,5 +23,6 @@ | `src/Template.js` | 90.28% | 90.28% | 80.95% | 83.16% |

| `src/TemplatePermalink.js` | 100% | 100% | 100% | 100% |
| `src/TemplateRender.js` | 98.73% | 98.73% | 100% | 94.44% |
| `src/TemplateRender.js` | 98.77% | 98.77% | 100% | 94.74% |
| `src/TemplateWriter.js` | 66.45% | 66.45% | 55.56% | 62.5% |
| `src/Engines/Ejs.js` | 88.89% | 88.89% | 71.43% | 75% |
| `src/UserConfig.js` | 76.74% | 77.01% | 66.67% | 57.14% |
| `src/Engines/Ejs.js` | 95.45% | 95.45% | 85.71% | 83.33% |
| `src/Engines/Haml.js` | 100% | 100% | 100% | 100% |

@@ -32,3 +33,3 @@ | `src/Engines/Handlebars.js` | 100% | 100% | 100% | 100% |

| `src/Engines/Liquid.js` | 100% | 100% | 100% | 83.33% |
| `src/Engines/Markdown.js` | 92.86% | 92.86% | 87.5% | 80% |
| `src/Engines/Markdown.js` | 90.63% | 90.63% | 87.5% | 78.57% |
| `src/Engines/Mustache.js` | 100% | 100% | 100% | 100% |

@@ -35,0 +36,0 @@ | `src/Engines/Nunjucks.js` | 95% | 95% | 100% | 75% |

@@ -8,3 +8,3 @@ # Release Procedure

5. Tag new version
6. `npm publish --access=public
6. `npm publish --access=public`
7. Check in a new `11ty.io` site with updated version.

@@ -82,4 +82,16 @@ # Permalinks

### Custom File Formats
To generate different file formats for your built site, you can use a different extension in the `permalink` option of your front matter.
For example, to generate a JSON search index to be used by popular search libraries.
```
---
permalink: index.json
---
<%- JSON.stringify(collections.all) _%>
```
### Pagination
Pagination variables also work here. [Read more about Pagination](pagination.md)
{
"name": "@11ty/eleventy",
"version": "0.3.1",
"version": "0.3.2",
"description": "Transform a directory of templates into HTML.",

@@ -50,3 +50,4 @@ "main": "src/Eleventy.js",

"nyc": "^11.6.0",
"prettier": "1.11.1"
"prettier": "1.11.1",
"serve": "^6.5.5"
},

@@ -53,0 +54,0 @@ "dependencies": {

@@ -1,2 +0,2 @@

# eleventy 🕚 v0.3.1
# eleventy 🕚 v0.3.2

@@ -3,0 +3,0 @@ A simpler static site generator. An alternative to Jekyll. Written in JavaScript. Transforms a directory of templates (of varying types) into HTML.

@@ -42,2 +42,6 @@ const fs = require("fs");

Eleventy.prototype.getOutputDir = function() {
return this.outputDir;
};
Eleventy.prototype.setDryRun = function(isDryRun) {

@@ -159,2 +163,4 @@ this.isDryRun = !!isDryRun;

out.push(" --version");
out.push(" --serve");
out.push(" Run web server on --port (default 8080) and --watch too");
out.push(" --watch");

@@ -161,0 +167,0 @@ out.push(" Wait for files to change and automatically rewrite");

@@ -5,5 +5,12 @@ const debug = require("debug")("Eleventy:CommandCheck");

constructor(argv) {
this.valueArgs = ["input", "output", "formats", "config", "pathprefix"];
this.valueArgs = [
"input",
"output",
"formats",
"config",
"pathprefix",
"port"
];
this.booleanArgs = ["quiet", "version", "watch", "dryrun", "help"];
this.booleanArgs = ["quiet", "version", "watch", "dryrun", "help", "serve"];

@@ -10,0 +17,0 @@ this.args = argv;

@@ -1,261 +0,3 @@

const EventEmitter = require("events");
const chalk = require("chalk");
const semver = require("semver");
const { DateTime } = require("luxon");
const debug = require("debug")("Eleventy:EleventyConfig");
const pkg = require("../package.json");
const UserConfig = require("./UserConfig");
// API to expose configuration options in config file
class EleventyConfig {
constructor() {
this.reset();
}
reset() {
debug("Resetting EleventyConfig to initial values.");
this.events = new EventEmitter();
this.collections = {};
this.liquidOptions = {};
this.liquidTags = {};
this.liquidFilters = {};
this.nunjucksFilters = {};
this.nunjucksAsyncFilters = {};
this.handlebarsHelpers = {};
this.passthroughCopies = {};
this.pugOptions = {};
this.libraryOverrides = {};
this.layoutAliases = {};
// now named `transforms` in API
this.filters = {};
this.activeNamespace = "";
this.DateTime = DateTime;
}
versionCheck(expected) {
if (!semver.satisfies(pkg.version, expected)) {
throw new Error(
`This project requires the eleventy version to match '${expected}' but found ${
pkg.version
}. Use \`npm update @11ty/eleventy -g\` to upgrade the eleventy global or \`npm update @11ty/eleventy --save\` to upgrade your local project version.`
);
}
}
on(eventName, callback) {
return this.events.on(eventName, callback);
}
emit(eventName, ...args) {
return this.events.emit(eventName, ...args);
}
// tagCallback: function(liquidEngine) { return { parse: …, render: … }} };
addLiquidTag(name, tagFn) {
name = this.getNamespacedName(name);
if (typeof tagFn !== "function") {
throw new Error(
`EleventyConfig.addLiquidTag expects a callback function to be passed in for ${name}: addLiquidTag(name, function(liquidEngine) { return { parse: …, render: … } })`
);
}
if (this.liquidTags[name]) {
debug(
chalk.yellow(
"Warning, overwriting a Liquid tag with `addLiquidTag(%o)`"
),
name
);
}
this.liquidTags[name] = tagFn;
}
addLiquidFilter(name, callback) {
name = this.getNamespacedName(name);
if (this.liquidFilters[name]) {
debug(
chalk.yellow(
"Warning, overwriting a Liquid filter with `addLiquidFilter(%o)`"
),
name
);
}
this.liquidFilters[name] = callback;
}
addNunjucksAsyncFilter(name, callback) {
name = this.getNamespacedName(name);
if (this.nunjucksAsyncFilters[name]) {
debug(
chalk.yellow(
"Warning, overwriting a Nunjucks filter with `addNunjucksAsyncFilter(%o)`"
),
name
);
}
this.nunjucksAsyncFilters[name] = callback;
}
// Support the nunjucks style syntax for asynchronous filter add
addNunjucksFilter(name, callback, isAsync) {
if (isAsync) {
this.addNunjucksAsyncFilter(name, callback);
} else {
name = this.getNamespacedName(name);
if (this.nunjucksFilters[name]) {
debug(
chalk.yellow(
"Warning, overwriting a Nunjucks filter with `addNunjucksFilter(%o)`"
),
name
);
}
this.nunjucksFilters[name] = callback;
}
}
addHandlebarsHelper(name, callback) {
name = this.getNamespacedName(name);
if (this.handlebarsHelpers[name]) {
debug(
chalk.yellow(
"Warning, overwriting a Handlebars helper with `addHandlebarsHelper(%o)`"
),
name
);
}
this.handlebarsHelpers[name] = callback;
}
addFilter(name, callback) {
debug("Adding universal filter %o", this.getNamespacedName(name));
this.addLiquidFilter(name, callback);
this.addNunjucksFilter(name, callback);
// these seem more akin to tags but they’re all handlebars has, so
this.addHandlebarsHelper(name, callback);
}
addTransform(name, callback) {
name = this.getNamespacedName(name);
this.filters[name] = callback;
}
addLayoutAlias(from, to) {
this.layoutAliases[from] = to;
}
getCollections() {
return this.collections;
}
addCollection(name, callback) {
name = this.getNamespacedName(name);
if (this.collections[name]) {
throw new Error(
`config.addCollection(${name}) already exists. Try a different name for your collection.`
);
}
this.collections[name] = callback;
}
addPlugin(pluginCallback) {
if (typeof pluginCallback !== "function") {
throw new Error(
"EleventyConfig.addPlugin expects the first argument to be a function."
);
}
pluginCallback(this);
}
getNamespacedName(name) {
return this.activeNamespace + name;
}
namespace(pluginNamespace, callback) {
this.activeNamespace = pluginNamespace || "";
callback();
this.activeNamespace = "";
}
/**
* Adds a path to a file or directory to the list of pass-through copies
* which are copied as-is to the output.
*
* @param {String} fileOrDir The path to the file or directory that should
* be copied.
* @returns {any} a reference to the `EleventyConfig` object.
* @memberof EleventyConfig
*/
addPassthroughCopy(fileOrDir) {
this.passthroughCopies[fileOrDir] = true;
return this;
}
setTemplateFormats(templateFormats) {
if (typeof templateFormats === "string") {
templateFormats = templateFormats.split(",").map(format => format.trim());
}
this.templateFormats = templateFormats;
}
setLibrary(engineName, libraryInstance) {
// Pug options are passed to `compile` and not in the library constructor so we don’t need to warn
if (engineName === "liquid" && this.mdOptions) {
debug(
"WARNING: using `eleventyConfig.setLibrary` will override any configuration set using `.setLiquidOptions` or with the `liquidOptions` key in the config object. You’ll need to pass these options to the library yourself."
);
}
this.libraryOverrides[engineName.toLowerCase()] = libraryInstance;
}
setPugOptions(options) {
this.pugOptions = options;
}
setLiquidOptions(options) {
this.liquidOptions = options;
}
getMergingConfigObject() {
return {
templateFormats: this.templateFormats,
filters: this.filters,
layoutAliases: this.layoutAliases,
passthroughCopies: this.passthroughCopies,
liquidOptions: this.liquidOptions,
liquidTags: this.liquidTags,
liquidFilters: this.liquidFilters,
nunjucksFilters: this.nunjucksFilters,
nunjucksAsyncFilters: this.nunjucksAsyncFilters,
handlebarsHelpers: this.handlebarsHelpers,
pugOptions: this.pugOptions,
libraryOverrides: this.libraryOverrides
};
}
}
let config = new EleventyConfig();
module.exports = config;
module.exports = new UserConfig();

@@ -5,2 +5,3 @@ const ejsLib = require("ejs");

const config = require("../Config");
const path = require("path");

@@ -15,2 +16,3 @@ class Ejs extends TemplateEngine {

this.setLibrary(this.config.libraryOverrides.ejs);
this.setEjsOptions(this.config.ejsOptions);
}

@@ -44,5 +46,8 @@

async compile(str) {
let fn = this.ejsLib.compile(str, this.getEjsOptions());
async compile(str, inputPath) {
let options = this.getEjsOptions();
options.filename = inputPath || options.filename;
let fn = this.ejsLib.compile(str, options);
return function(data) {

@@ -49,0 +54,0 @@ return fn(data);

@@ -12,5 +12,6 @@ const LiquidLib = require("liquidjs");

this.config = config.getConfig();
this.liquidOptions = this.config.liquidOptions;
this.liquidOptions = {};
this.setLibrary(this.config.libraryOverrides.liquid);
this.setLiquidOptions(this.config.liquidOptions);
}

@@ -17,0 +18,0 @@

@@ -19,2 +19,11 @@ const markdownIt = require("markdown-it");

this.mdLib = mdLib || markdownIt(this.getMarkdownOptions());
// Overrides a highlighter set in `markdownOptions`
// This is separate so devs can pass in a new mdLib and still use the official eleventy plugin for markdown highlighting
if (this.config.markdownHighlighter) {
this.mdLib.set({
highlight: this.config.markdownHighlighter
});
}
this.setEngineLib(this.mdLib);

@@ -41,5 +50,7 @@ }

async compile(str, preTemplateEngine, bypassMarkdown) {
async compile(str, inputPath, preTemplateEngine, bypassMarkdown) {
let mdlib = this.mdLib;
if (preTemplateEngine) {
let fn;
let engine = TemplateEngine.getEngine(

@@ -49,4 +60,9 @@ preTemplateEngine,

);
let fn = await engine.compile(str);
if (preTemplateEngine === "ejs") {
fn = await engine.compile(str, inputPath);
} else {
fn = await engine.compile(str);
}
if (bypassMarkdown) {

@@ -53,0 +69,0 @@ return async function(data) {

@@ -11,5 +11,6 @@ const PugLib = require("pug");

this.config = config.getConfig();
this.pugOptions = this.config.pugOptions;
this.pugOptions = {};
this.setLibrary(this.config.libraryOverrides.pug);
this.setPugOptions(this.config.pugOptions);
}

@@ -16,0 +17,0 @@

@@ -398,3 +398,3 @@ const pify = require("pify");

let fn = await this.templateRender.getCompiledTemplate(str);
let fn = await this.templateRender.getCompiledTemplate(str, this.inputPath);
let rendered = fn(data);

@@ -401,0 +401,0 @@ return rendered;

@@ -152,8 +152,15 @@ const parsePath = require("parse-filepath");

TemplateRender.prototype.getCompiledTemplate = async function(str) {
TemplateRender.prototype.getCompiledTemplate = async function(str, inputPath) {
// TODO refactor better, move into TemplateEngine logic
if (this.engineName === "md") {
return this.engine.compile(str, this.parseMarkdownWith, !this.useMarkdown);
return this.engine.compile(
str,
inputPath,
this.parseMarkdownWith,
!this.useMarkdown
);
} else if (this.engineName === "html") {
return this.engine.compile(str, this.parseHtmlWith);
} else if (this.engineName === "ejs") {
return this.engine.compile(str, inputPath);
} else {

@@ -160,0 +167,0 @@ return this.engine.compile(str);

@@ -17,3 +17,3 @@ import test from "ava";

test("EJS Render Include Preprocessor Directive", async t => {
test("EJS Render Absolute Include, Preprocessor Directive", async t => {
let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(

@@ -25,3 +25,3 @@ "<p><% include /included %></p>"

test("EJS Render Include, New Style no Data", async t => {
test("EJS Render Absolute Include, Fxn no Data", async t => {
let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(

@@ -33,32 +33,30 @@ "<p><%- include('/included') %></p>"

test("EJS Render Include, New Style", async t => {
test("EJS Render Absolute Include, Fxn with Data", async t => {
let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(
"<p><%- include('/included', {}) %></p>"
"<p><%- include('/includedvar', { name: 'Bill' }) %></p>"
);
t.is(await fn(), "<p>This is an Bill.</p>");
});
test("EJS Render Relative Include, Preprocessor Directive", async t => {
let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(
"<p><% include _includes/included %></p>"
);
t.is(await fn(), "<p>This is an include.</p>");
});
test("EJS Render Include, New Style with Data", async t => {
test("EJS Render Relative Include, Fxn no Data", async t => {
let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(
"<p><%- include('/includedvar', { name: 'Bill' }) %></p>"
"<p><%- include('_includes/included', {}) %></p>"
);
t.is(await fn(), "<p>This is an include.</p>");
});
test("EJS Render Relative Include, Fxn with Data", async t => {
let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(
"<p><%- include('_includes/includedvar', { name: 'Bill' }) %></p>"
);
t.is(await fn(), "<p>This is an Bill.</p>");
});
// test("EJS Render Include Preprocessor Directive Relative", async t => {
// let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(
// "<p><% include included %></p>"
// );
// t.is(await fn(), "<p>This is an include.</p>");
// });
// test("EJS Render Include, Relative Path New Style", async t => {
// let fn = await new TemplateRender("ejs", "./test/stubs/").getCompiledTemplate(
// "<p><%- include('stubs/includedrelative', {}) %></p>"
// );
// t.is(await fn(), "<p>This is a relative include.</p>");
// });
test("EJS Render: with Library Override", async t => {

@@ -65,0 +63,0 @@ let tr = new TemplateRender("ejs");

@@ -5,2 +5,4 @@ import test from "ava";

import mdEmoji from "markdown-it-emoji";
import UserConfig from "../src/UserConfig";
// import eleventySyntaxHighlightPlugin from "@11ty/eleventy-plugin-syntaxhighlight";

@@ -104,1 +106,116 @@ // Markdown

});
test("Markdown Render: use a custom highlighter", async t => {
let tr = new TemplateRender("md");
let mdLib = md();
mdLib.set({
highlight: function(str, lang) {
return "This is overrrrrrride";
}
});
tr.engine.setLibrary(mdLib);
let fn = await tr.getCompiledTemplate(`\`\`\`
This is some code.
\`\`\``);
t.is((await fn()).trim(), "<pre><code>This is overrrrrrride</code></pre>");
});
// TODO Uncomment these after syntax-highlighter v1.0.4 is released (and/or bundled—see #97)
// test("Markdown Render: use prism highlighter (no language)", async t => {
// let tr = new TemplateRender("md");
// let userConfig = new UserConfig();
// userConfig.addPlugin(eleventySyntaxHighlightPlugin);
// let markdownHighlight = userConfig.getMergingConfigObject().markdownHighlighter;
// let mdLib = md();
// mdLib.set({
// "highlight": markdownHighlight
// });
// tr.engine.setLibrary(mdLib);
// let fn = await tr.getCompiledTemplate(`\`\`\`
// This is some code.
// \`\`\``);
// t.is((await fn()).trim(), `<pre><code>This is some code.
// </code></pre>`);
// });
// test("Markdown Render: use prism highlighter", async t => {
// let tr = new TemplateRender("md");
// let userConfig = new UserConfig();
// userConfig.addPlugin(eleventySyntaxHighlightPlugin);
// let markdownHighlight = userConfig.getMergingConfigObject().markdownHighlighter;
// let mdLib = md();
// mdLib.set({
// "highlight": markdownHighlight
// });
// tr.engine.setLibrary(mdLib);
// let fn = await tr.getCompiledTemplate(`\`\`\` js
// var key = "value";
// \`\`\``);
// t.is((await fn()).trim(), `<pre class="language-js"><code class="language-js"><div class="highlight-line"><span class="token keyword">var</span> key <span class="token operator">=</span> <span class="token string">"value"</span><span class="token punctuation">;</span></div></code></pre>`);
// });
// test("Markdown Render: use prism highlighter (no space before language)", async t => {
// let tr = new TemplateRender("md");
// let userConfig = new UserConfig();
// userConfig.addPlugin(eleventySyntaxHighlightPlugin);
// let markdownHighlight = userConfig.getMergingConfigObject().markdownHighlighter;
// let mdLib = md();
// mdLib.set({
// "highlight": markdownHighlight
// });
// tr.engine.setLibrary(mdLib);
// let fn = await tr.getCompiledTemplate(`\`\`\`js
// var key = "value";
// \`\`\``);
// t.is((await fn()).trim(), `<pre class="language-js"><code class="language-js"><div class="highlight-line"><span class="token keyword">var</span> key <span class="token operator">=</span> <span class="token string">"value"</span><span class="token punctuation">;</span></div></code></pre>`);
// });
// test("Markdown Render: use prism highlighter, line highlighting", async t => {
// let tr = new TemplateRender("md");
// let userConfig = new UserConfig();
// userConfig.addPlugin(eleventySyntaxHighlightPlugin);
// let markdownHighlight = userConfig.getMergingConfigObject().markdownHighlighter;
// let mdLib = md();
// mdLib.set({
// "highlight": markdownHighlight
// });
// tr.engine.setLibrary(mdLib);
// let fn = await tr.getCompiledTemplate(`\`\`\`js/0
// var key = "value";
// \`\`\``);
// t.is((await fn()).trim(), `<pre class="language-js"><code class="language-js"><div class="highlight-line highlight-line-active"><span class="token keyword">var</span> key <span class="token operator">=</span> <span class="token string">"value"</span><span class="token punctuation">;</span></div></code></pre>`);
// });
// test("Markdown Render: use prism highlighter, line highlighting with fallback `text` language.", async t => {
// let tr = new TemplateRender("md");
// let userConfig = new UserConfig();
// userConfig.addPlugin(eleventySyntaxHighlightPlugin);
// let markdownHighlight = userConfig.getMergingConfigObject().markdownHighlighter;
// let mdLib = md();
// mdLib.set({
// "highlight": markdownHighlight
// });
// tr.engine.setLibrary(mdLib);
// let fn = await tr.getCompiledTemplate(`\`\`\` text/0
// var key = "value";
// \`\`\``);
// t.is((await fn()).trim(), `<pre class="language-text"><code class="language-text"><div class="highlight-line highlight-line-active">var key = "value";</div></code></pre>`);
// });
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc