google-docs-mustaches
google-docs-mustaches copied to clipboard
Question / Suggested Changes
Hey @Errorname, great library, well done!
We just started using your library at work and while digging around in the code I noticed two things which I wanted to bring up here.
Duplicate generated Updates
The first one is just a tiny optimisation even though I'm not even sure if it will change anything at all. I just found it interesting that the Google Docs Merge Api mentions that https://developers.google.com/docs/api/reference/rest/v1/documents/request#replacealltextrequest
ReplaceAllTextRequest Replaces all instances of text matching a criteria with replace text
yet if my template has 3 times the same placeholder, let's say {{ user }}
, this library creates 3 different ReplaceAllTextRequest
updates. This might not seem as much but for my template it meant that instead of 18 distinct updates the library generated 73 updates.
And here now my question: Is there any particular reason to do this? Because I think it would not have any downsides if the duplicates would be filtered out.
Enable multi Stage merging
The other thing is kind of a feature request. I currently want to have a multi stage merge process: I have one document with lots of placeholders. In the first iteration I want to merge half of the placeholders and save it. The other half of the placeholders should stay as it is, because after some time I want to go ahead and merge in the remaining placeholders into the document.
This is currently not possible as the library fetches all the placeholders and replaces the placeholder with an empty string is no value is provided. My suggestion would be to implement a property in the Mustache
config object let's say forceReplaceAll
(I'm not quite satisfied with the naming but you get the idea) which can be true
by default but when its false
the library replaces the placeholders with the placeholder variable (so nothing changes) when no replace value is given.
Let me know what you think about it. If you don't have the time right now, I also would be happy to open PR's for that myself. I really like this project and would love to see it grow and contribute to it, myself.
Hi @8BitJonny ! Thanks for your interest in google-docs-mustaches 🙏
It's been a while since I worked on it, and I've been meaning to rewrite part of code too!
Duplicate generated Updates
That's actually a good question: in my own usage of the library, I did not have placeholders present multiple times in a document, so I didn't think about it.
Enable multi Stage merging
That's a good feature request, it's definitely something that the library could easily do.
As said at the beginning of this message, I want to rewrite a part of the library (in a large part because of #25 that creates bugs when using multiple images placeholders). I'll take the next few days to think about the new code architecture, then upgrade dependencies, and start the rewrite. Once I'm happy with the structure of the code, I'll be more than happy to have contributions to improve it, as well as feedbacks on its usage 🙂
I'll keep this issue open and let know you once the new iteration of google-docs-mustaches is ready!
Sounds great @Errorname 👍 Can't wait to contribute to this awesome project
Hello @Errorname. How do I use this? I have not been able to successfully execute the basic code. I keep receiving an error that says that Mustaches is not a constructor, which I believe is due to the access token not being actually gotten.
@Codetopher The best way to get help is to open an issue yourself in this repo, and then to give us more details.
Go here: https://github.com/Errorname/google-docs-mustaches/issues/new/choose to create a new issue. Write into the issue which node version you are using, which version of this plugin you are using, show us the code that produces your error and then I'm sure we will be able to help you.