Skip to content

Commit

Permalink
Removes config options for template aliases #207.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 10, 2019
1 parent 3115dd4 commit f2218f8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
44 changes: 21 additions & 23 deletions src/EleventyExtensionMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ const TemplatePath = require("./TemplatePath");
const config = require("./Config");

class EleventyExtensionMap {
constructor(formats = []) {
this.config = config.getConfig();

this.unfilteredFormats = formats.map(function(key) {
constructor(formatKeys = []) {
this.unfilteredFormatKeys = formatKeys.map(function(key) {
return key.trim().toLowerCase();
});

this.formats = this.unfilteredFormats.filter(key => this.hasExtension(key));
this.formatKeys = this.unfilteredFormatKeys.filter(key =>
this.hasExtension(key)
);

this.prunedFormats = this.unfilteredFormats.filter(
this.prunedFormatKeys = this.unfilteredFormatKeys.filter(
key => !this.hasExtension(key)
);
}

setConfig(configOverride) {
this.config = configOverride || {};
get config() {
return this.configOverride || config.getConfig();
}
set config(cfg) {
this.configOverride = cfg;
}

/* Used for layout path resolution */
Expand All @@ -27,9 +30,9 @@ class EleventyExtensionMap {
}

let files = [];
this.formats.forEach(
this.formatKeys.forEach(
function(key) {
this.getExtensions(key).forEach(function(extension) {
this.getExtensionsFromKey(key).forEach(function(extension) {
files.push((dir ? dir + "/" : "") + path + "." + extension);
});
}.bind(this)
Expand All @@ -39,24 +42,24 @@ class EleventyExtensionMap {
}

getPrunedGlobs(inputDir) {
return this._getGlobs(this.prunedFormats, inputDir);
return this._getGlobs(this.prunedFormatKeys, inputDir);
}

getGlobs(inputDir) {
if (this.config.passthroughFileCopy) {
return this._getGlobs(this.unfilteredFormats, inputDir);
return this._getGlobs(this.unfilteredFormatKeys, inputDir);
}

return this._getGlobs(this.formats, inputDir);
return this._getGlobs(this.formatKeys, inputDir);
}

_getGlobs(formats, inputDir) {
_getGlobs(formatKeys, inputDir) {
let dir = TemplatePath.convertToGlob(inputDir);
let globs = [];
formats.forEach(
formatKeys.forEach(
function(key) {
if (this.hasExtension(key)) {
this.getExtensions(key).forEach(function(extension) {
this.getExtensionsFromKey(key).forEach(function(extension) {
globs.push(dir + "/*." + extension);
});
} else {
Expand All @@ -76,10 +79,6 @@ class EleventyExtensionMap {
return false;
}

getExtensions(key) {
return this.getExtensionsFromKey(key);
}

getExtensionsFromKey(key) {
let extensions = [];
for (var extension in this.keyMap) {
Expand Down Expand Up @@ -129,13 +128,12 @@ class EleventyExtensionMap {

get keyMap() {
return EleventyExtensionMap._getKeyMap(
this.config.templateExtensionAliases
this.config.templateExtensionAliases || {}
);
}

static get keyMap() {
return EleventyExtensionMap._getKeyMap(
config.getConfig().templateExtensionAliases
config.getConfig().templateExtensionAliases || {}
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UserConfig {
this.dataDeepMerge = false;
this.experiments = new Set();
// this.userExtensionMap = {};
this.templateExtensionAliases = {};
// this.templateExtensionAliases = {};
this.watchJavaScriptDependencies = true;
this.browserSyncConfig = {};
}
Expand Down Expand Up @@ -483,9 +483,9 @@ class UserConfig {
this.dataDeepMerge = !!deepMerge;
}

addTemplateExtensionAlias(targetKey, extension) {
this.templateExtensionAliases[extension] = targetKey;
}
// addTemplateExtensionAlias(targetKey, extension) {
// this.templateExtensionAliases[extension] = targetKey;
// }

setWatchJavaScriptDependencies(watchEnabled) {
this.watchJavaScriptDependencies = !!watchEnabled;
Expand Down Expand Up @@ -524,7 +524,7 @@ class UserConfig {
useGitIgnore: this.useGitIgnore,
dataDeepMerge: this.dataDeepMerge,
experiments: this.experiments,
templateExtensionAliases: this.templateExtensionAliases,
// templateExtensionAliases: this.templateExtensionAliases,
watchJavaScriptDependencies: this.watchJavaScriptDependencies,
browserSyncConfig: this.browserSyncConfig
};
Expand Down
16 changes: 8 additions & 8 deletions test/EleventyExtensionMapTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ test("Multiple formats", t => {

test("Invalid keys are filtered (no passthrough copy)", t => {
let map = new EleventyExtensionMap(["lksdjfjlsk"]);
map.setConfig({
map.config = {
passthroughFileCopy: false
});
};
t.deepEqual(map.getGlobs(), []);
});

test("Invalid keys are filtered (using passthrough copy)", t => {
let map = new EleventyExtensionMap(["lksdjfjlsk"]);
map.setConfig({
map.config = {
passthroughFileCopy: true
});
};
t.deepEqual(map.getGlobs(), ["./**/*.lksdjfjlsk"]);
});

Expand Down Expand Up @@ -110,12 +110,12 @@ test("getKey", t => {

test("Extension aliasing (one format key)", t => {
let map = new EleventyExtensionMap(["md"]);
map.setConfig({
map.config = {
templateExtensionAliases: {
markdown: "md",
nunjucks: "njk" // N/A to current format list
}
});
};
t.deepEqual(map.getExtensionsFromKey("md"), ["md", "markdown"]);
t.deepEqual(map.getExtensionsFromKey("njk"), ["njk", "nunjucks"]);

Expand All @@ -125,12 +125,12 @@ test("Extension aliasing (one format key)", t => {

test("Extension aliasing (two format keys)", t => {
let map = new EleventyExtensionMap(["md", "njk"]);
map.setConfig({
map.config = {
templateExtensionAliases: {
markdown: "md",
nunjucks: "njk"
}
});
};
t.deepEqual(map.getExtensionsFromKey("md"), ["md", "markdown"]);
t.deepEqual(map.getExtensionsFromKey("njk"), ["njk", "nunjucks"]);

Expand Down
4 changes: 2 additions & 2 deletions test/EleventyFilesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ test("Glob Watcher Files with passthroughAll", async t => {

test("File extension aliasing", async t => {
let map = new EleventyExtensionMap(["md"]);
map.setConfig({
map.config = {
templateExtensionAliases: {
markdown: "md"
}
});
};

let evf = new EleventyFiles(
"./test/stubs/writeTestMarkdown",
Expand Down

0 comments on commit f2218f8

Please sign in to comment.