This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 213
Support per-page HTML template customisation via 'mains' #1029
Merged
edmorley
merged 2 commits into
neutrinojs:master
from
edmorley:mains-html-template-options
Aug 21, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ const requireFromRoot = (moduleId, root) => { | |
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
return require(path); | ||
}; | ||
// Support both a shorter string form and an object form that allows | ||
// specifying any page-specific options supported by the preset. | ||
const normalizeMainConfig = (config) => | ||
(typeof config === 'string') ? { entry: config } : config; | ||
|
||
module.exports = class Neutrino { | ||
constructor(options) { | ||
|
@@ -138,38 +142,46 @@ module.exports = class Neutrino { | |
|
||
bindMainsOnOptions(options, optionsSource) { | ||
Object | ||
.keys(options.mains) | ||
.forEach(key => { | ||
let value = options.mains[key]; | ||
.entries(options.mains) | ||
.forEach(([key, value]) => { | ||
let normalizedConfig = normalizeMainConfig(value); | ||
|
||
Reflect.defineProperty(options.mains, key, { | ||
enumerable: true, | ||
get() { | ||
const source = optionsSource && | ||
optionsSource.source || options.source; | ||
|
||
return normalizePath(source, value); | ||
return { | ||
...normalizedConfig, | ||
// Lazily normalise the path, in case `source` changes after mains is updated. | ||
entry: normalizePath(source, normalizedConfig.entry) | ||
}; | ||
}, | ||
set(newValue) { | ||
value = newValue; | ||
normalizedConfig = normalizeMainConfig(newValue); | ||
} | ||
}); | ||
}); | ||
|
||
this.mainsProxy = new Proxy(options.mains, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the Proxy itself, but only exposed it on the Neutrino API just in case. We can certainly remove it if we don't foresee exposing it as being useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing seemed to break when I removed it fwiw |
||
defineProperty: (target, prop, { value }) => { | ||
let currentValue = value; | ||
let normalizedConfig = normalizeMainConfig(value); | ||
|
||
return Reflect.defineProperty(target, prop, { | ||
enumerable: true, | ||
get() { | ||
const source = optionsSource && | ||
optionsSource.source || options.source; | ||
|
||
return normalizePath(source, currentValue); | ||
return { | ||
...normalizedConfig, | ||
// Lazily normalise the path, in case `source` changes after mains is updated. | ||
entry: normalizePath(source, normalizedConfig.entry) | ||
}; | ||
}, | ||
set(newValue) { | ||
currentValue = newValue; | ||
normalizedConfig = normalizeMainConfig(newValue); | ||
} | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of pre-existing duplication between
api.md
,creating-presets.md
andcustomization.md
that is out of scope for this PR, but something we should figure out how to avoid at some point.