-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor preprocess and url processing functions #1026
Refactor preprocess and url processing functions #1026
Conversation
e56c14f
to
016d781
Compare
Ready for review Some quirks I noticed while refactoring which I'm not so sure about:
Save for point 2 which is likely unintended, the rest of the refactor keeps the same functionality as before |
console.warn(`<body> tag found in ${node.attribs[ATTRIB_CWF]}. This may cause formatting errors.`); | ||
} | ||
|
||
function preProcessComponent(node, context, config, parser) { |
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.
Entry point to the original _preprocess
function, the respective switch cases are the respective control flows of _preprocess
for different types of elements
} | ||
|
||
// TODO clarify why this is only done if there is a hash, or fix it if it is unintended | ||
if (hash) _rebaseReferenceForStaticIncludes(actualContent, element, config); |
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.
Is this intentional? ( point 5 )
element.attribs.boilerplate = element.attribs.boilerplate || path.basename(filePath); | ||
actualFilePath | ||
= Parser.calculateBoilerplateFilePath(element.attribs.boilerplate, filePath, config); | ||
this.boilerplateIncludeSrc.push({ from: context.cwf, to: actualFilePath }); |
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.
Is boilerplateIncludeSrc
necessary?
For both panels and includes we eventually still push either dynamicIncludeSrc
or staticIncludeSrc
} | ||
|
||
// TODO move this to componentParser | ||
function _preProcessThumbnail(node) { |
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.
Should this be moved?
actualContent = isInline ? actualContent : `\n\n${actualContent}\n`; | ||
} else { | ||
// TODO do we need this branch? | ||
actualContent = md.render(actualContent); |
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.
A quick usage find for _preprocess
reveals that it is never called with anything other than context.mode = 'include'
016d781
to
4f735f7
Compare
if (element.children && element.children.length > 0) { | ||
element.children = element.children.map(e => self._preprocess(e, context, config)); | ||
} | ||
extractInnerVariablesIfNotProcessed(content, childContext, config, filePathToExtract) { |
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.
To allow componentPreprocessor
and _extractInnerVariables
to share this common code
this.preprocess(actualFilePath, pageData, context, config) | ||
.then(resolve) | ||
.catch(reject); | ||
const currentContext = context; |
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.
This chunk is moved from the preprocess
( not _preprocess
) function, which was added in the expressive layouts pr,
to remove naming ambiguity.
A future PR may look into whether expressive layouts can be introduced in similar fashion to the page header
, sitenav
, etc., as includeData
( the function this code is under ) is very similar to includeFile
. ( to reduce code duplication )
let newBase = Parser.calculateNewBaseUrls(filePath, this.rootPath, this.baseUrlMap); | ||
if (newBase) { | ||
const { relative, parent } = newBase; | ||
let newBaseUrl = urlUtils.calculateNewBaseUrls(filePath, this.rootPath, this.baseUrlMap); |
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.
The only irrelevant refactor to remove the nested ifs
, and slightly better variable naming; Let me know if this should be removed!
Instead of relying on non-exhaustive functional tests, for extensive refactoring, let's check that there is no diff to the generated |
5b18ab0
to
b33008b
Compare
Thanks for the suggestion! Will take note of it for upcoming refactors. I've removed the specific processing for Interestingly, |
b33008b
to
ae39616
Compare
Rebased on latest, no changes Will keep this up to date, and update here if there are changes / conflicts |
ae39616
to
c647c49
Compare
ac1a05d
to
9644a60
Compare
The parser class houses a large number of functions. This can be daunting for newer developers to the project, and decreases maintainability of the code. Let’s start by modularising the preprocess and url processing functions into separate files. Let’s also enhance some in-code documentation for these functions. Some of these functions can also be abstracted into smaller units of functionality, increasing the maintainability of the code.
9644a60
to
d2a24dd
Compare
Whether it should be moved or not will depend on how specialised componentProcessor will eventually get. I noted that there's some coupling between this and the parser that still needs to be resolved in future PRs, so I believe the answer will naturally come by as the refactoring process goes. Also noted about the weird quirks that you have found. Refactoring by itself is usually quite a tough task by itself; verifying additional changes on top of it is going to make it even more tough, so always welcome to settle those problems in separate PRs (and good to open these in the issue tracker too). Since my time is now quite restricted as compared to the past, I am no longer able to manually verify that everything works. So these green ticks approval that I give from now on would basically be just a glance through your code to see that there's no major source of issues in terms of design and implementation. You guys might want to test out each other's code from time to time to see if there's any problems. With all that said, will be merging this. 👍 |
…nvert-to-code-block * 'master' of https://github.com/MarkBind/markbind: Allow changing parameter properties (MarkBind#1075) Custom timezone for built-in timestamp (MarkBind#1073) Fix reload inconsistency when updating frontmatter (MarkBind#1068) Implement an api to ignore content in certain tags (MarkBind#1047) Enable AppVeyor CI (MarkBind#1040) Add heading and line highlighting to code blocks (MarkBind#1034) Add dividers and fix bug in siteNav (MarkBind#1063) Fixed navbar no longer covers modals (MarkBind#1070) Add copy code-block plugin (MarkBind#1043) Render plugins on dynamic resources (MarkBind#1051) Documentation for Implement no-* attributes for <box> (MarkBind#1042) Migrate to bootstrap-vue popovers (MarkBind#1033) Refactor preprocess and url processing functions (MarkBind#1026) Add pageNav to Using Plugins Page (MarkBind#1062) # Conflicts: # docs/userGuide/syntax/siteNavigationMenus.mbdf
* 'master' of https://github.com/MarkBind/markbind: 2.12.0 Update outdated test files Update vue-strap version to v2.0.1-markbind.37 Fix refactor to processDynamicResources (MarkBind#1092) Implement lazy page building for markbind serve (MarkBind#1038) Add warnings for conflicting/deprecated component attribs (MarkBind#1057) Allow changing parameter properties (MarkBind#1075) Custom timezone for built-in timestamp (MarkBind#1073) Fix reload inconsistency when updating frontmatter (MarkBind#1068) Implement an api to ignore content in certain tags (MarkBind#1047) Enable AppVeyor CI (MarkBind#1040) Add heading and line highlighting to code blocks (MarkBind#1034) Add dividers and fix bug in siteNav (MarkBind#1063) Fixed navbar no longer covers modals (MarkBind#1070) Add copy code-block plugin (MarkBind#1043) Render plugins on dynamic resources (MarkBind#1051) Documentation for Implement no-* attributes for <box> (MarkBind#1042) Migrate to bootstrap-vue popovers (MarkBind#1033) Refactor preprocess and url processing functions (MarkBind#1026) Add pageNav to Using Plugins Page (MarkBind#1062)
The parser class houses a large number of functions. This can be daunting for newer developers to the project, and decreases maintainability of the code. Let’s start by modularising the preprocess and url processing functions into separate files. Let’s also enhance some in-code documentation for these functions. Some of these functions can also be abstracted into smaller units of functionality, increasing the maintainability of the code.
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Other, please explain:
Part of #810
What is the rationale for this request?
Another step to modularising parser functions, enhancing code maintainability and readability.
What changes did you make? (Give an overview)
_preprocess
and move related functions to a separate file,componentPreprocessor
componentPreprocessor
andparser
), stateless url processing functions toutils/urls
Provide some example code that this change will affect:
Is there anything you'd like reviewers to focus on?
Directory structure of the refactor
Of note is that
componentPreprocessor
andparser
is still rather coupled. (parser
is passed as a parameter to the entry point incomponentPreprocessor
)parser
should depend oncomponentPreprocessor
, and not the other way around at all if possible.componentPreprocessor
a class which would subsume required properties from the mainparser
. This was not feasible at the moment however, as many otherparser
functions have 'side effects' onparser
's instance variables. It would be counterproductive to add code to synchronize the variables between the two.Testing instructions:
npm run test
should passProposed commit message: (wrap lines at 72 characters)
Refactor preprocess and url processing functions
The parser class houses a large number of functions.
This can be daunting for newer developers to the project, and decreases
maintainability of the code.
Let’s start by modularising the preprocess and url processing functions
into separate files.
Let’s also enhance some in-code documentation for these functions.
Some of these functions can also be abstracted into smaller units of
functionality, increasing the maintainability of the code.