-
Notifications
You must be signed in to change notification settings - Fork 142
Allow live reloading for plugin defined sources #955
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
Conversation
src/Page.js
Outdated
| if (plugin.getSources) { | ||
| const sources = _.castArray( | ||
| plugin.getSources(content, this.pluginsContext[pluginName] || {}, | ||
| this.frontMatter, this.getPluginConfig())); |
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.
Why _.castArray? getSources should return an array.
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.
So that a single source file could be returned as well,
should I enforce returning an array instead?
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.
Yes, since getSources is plural.
5dd6389 to
720648b
Compare
|
Updated |
yamgent
left a comment
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.
Seems good implementation-wise, comments are mostly about wordings:
docs/userGuide/usingPlugins.md
Outdated
| const $ = cheerio.load(content, { xmlMode: true }); | ||
|
|
||
| return $('puml').map((i, tag) => tag.attribs.src).get(); | ||
| }, |
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 indentation of the method body is off. Only the comment line was in the correct indentation
docs/userGuide/usingPlugins.md
Outdated
| During the `preRender` and `postRender` stages however, plugins may do custom processing using some other | ||
| source file types, as parsed from the raw Markdown, typically requiring rebuilding the site. | ||
|
|
||
| Hence, to add custom source files to watch, MarkBind allows defining an additional method in the plugin. |
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.
Hence, to add custom source files to watch, MarkBind allows defining an additional method in the plugin. implement the ``getSources`` method:
Prefer being more direct in documentations so that it is easier for the reader to process.
docs/userGuide/usingPlugins.md
Outdated
|
|
||
| Hence, to add custom source files to watch, MarkBind allows defining an additional method in the plugin. | ||
| - `getSources(content, pluginContext, frontMatter, config)`: Called before the `preRender` function to retrieve an array of source file paths to watch. | ||
| - `content`: The raw Markdown of any Markdown file (`.md`, `.mbd`, etc.). |
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.
any -> the current? The use of "any" makes it seems like this call is not tied to any pages.
docs/userGuide/usingPlugins.md
Outdated
| source file types, as parsed from the raw Markdown, typically requiring rebuilding the site. | ||
|
|
||
| Hence, to add custom source files to watch, MarkBind allows defining an additional method in the plugin. | ||
| - `getSources(content, pluginContext, frontMatter, config)`: Called before the `preRender` function to retrieve an array of source file paths to watch. |
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.
Returns an array of source file paths to watch. Called before a Markdown file'spreRender function is called.
src/Page.js
Outdated
| }; | ||
|
|
||
| /** | ||
| * Collect page sources provided by plugins |
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.
Seems a bit wrong to say "page sources", since puml files are not really pages? Maybe "file sources"?
|
Hi, thanks for looking through it! I've updated the relavant lines. On another note, I noticed that Was this an intentional decision to hide some of the implementation details? If not, I could update it as well. |
It was probably an oversight. Feel free to add it in. |
|
Updated, will squash if its fine! |
Actually, it was intentionally undocumented by @jamos-tay as of #714 (comment):
|
Thanks for the heads up! Since @jamos-tay ended up going with the approach @marvinchin suggested, there isn't too much to document though. Regarding the original concern for the change ( passing the entire What's the take on this? 😮 |
The concern isn't that it is tedious to document. Rather, ideally, plugins should purely process content rather than use variables from and depend on the (filesystem-aware) implementation of Markbind CLI. |
|
Noted on the intended usage of plugins. Thanks! Reverted the 'documentation updates' and squashed |
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Documentation update
• [x] Enhancement to an existing feature
Resolves #913
What is the rationale for this request?
To allow plugins to define their own source file types and corresponding
source files that will be watched and updated by the live preview appropriately.
What changes did you make? (Give an overview)
getSourcesgetSources: Allows plugins to return an array of source file paths to watchPage.prototype.preRender,Page.prototype.getSourcesrunsgetSourcesall plugins just beforepreRender.Provide some example code that this change will affect:
Is there anything you'd like reviewers to focus on?
Whether a callback style solution would be better ( a 5th parameter to
preRender / postRenderthat contains callbacks plugins can use ), since in the long run one may find plugins requiring more and more functionality.Testing instructions:
I added a
<puml>tag, and an<include>tag ( including testPlantUML.md )to the test site. Changing any of the source files ( e.g.
activity.puml) shouldcause the affected pages to reload when serving the page.
Proposed commit message: (wrap lines at 72 characters)
Allow live reloading for plugin defined sources
This allows plugins to define a custom list of source files and file
types for the page to be watched, allowing live reload to rebuild
the affected page.