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
docx 'remove' helper #1064
Comments
hi, sorry for the delay, we were busy releasing jsreport 3.12.0
it looks good to me, though i would call it
exactly, that is what is going to make it more useful, it is called subexpressions
so far in general, it looks like you got it right, so go ahead with that implementation. the helpers you mention should allow you to do it more easily
yes, you need to add a new preprocess module there, for the logic try to come up with something, at least a simple logic, the nested docxRm calls sounds a bit complex honestly, perhaps it helps if you explain how the nested docxRm calls are useful. generally i think that in this step you need to mark the xml tag that should be removed, then in a postprocess step you should find those marked elements and remove them with string replace (just like we do with other cases, check some of the postprocess modules like
the exact place will depend on other things, usually the transformations (
yes, this sounds good. |
Hello!
I'm interested in implementing a 'remove' built-in helper for the
docx
recipe, similar to Carbone's drop formatter.A typical use of this tag in carbone's templating language looks like:
which means "if data property 'text' is empty, drop the paragraph"
Besides paragraphs the tag can also remove rows, tables, images, charts, and shapes.
Personally, I find removing paragraphs, rows and tables to have the most utility. Rows and tables, in particular, since you can group template content into border-less tables and conditionally drop those to remove chunks of content. This results in much cleaner templates, versus handling content variations with {{#if ...}}...{{/if}} conditional helpers.
The Carbone implementation doesn't have the ability to drop sections or whole pages, which I think would be very useful, but that's getting ahead of myself. To start, I'd just like to implement dropping paragraph, row and table elements.
I'm assuming this functionality isn't possible through user-space handlebar helpers (if that's not the case, let me know!)
Assuming handlebars is the engine, a JsReport implementation of this could look like:
it would also be useful if value could be determined by a helper rather than a data property, but I'm not sure how the syntax for that should look
I'm assuming the basic algorithm is:
There's probably more to it than that, of course. I'm guessing I'd use the utility functions getClosestEl and clearEl for this.
I've only just started looking into the JsReport code to figure out how to do this, but right now I'm assuming I would do the following:
packages/jsreport-docx/lib/preprocess/remove.js
preprocess.js
. Assuming it would need to be called first (before bookmark(...)):docxRm
function topackages/jsreport-docx/static/helpers.js
, something like:Any guidance or insight would be appreciated. I'm working on this in my free time so there's no rush.
The text was updated successfully, but these errors were encountered: