feat(chem): re-align Chem/OLE insertion onto upstream v0.4.3#10
Merged
Conversation
Proof-of-concept realigning ComPlat's custom Chem/OLE feature (embedded ChemDraw object + preview image via `$$expr:start`/`:end` merge fields) with senny/sablon v0.4.3, whose HTML converter, template pipeline and field-handler/DOM systems were rewritten since the v0.0.19 fork point. Rather than the fork's hand-rolled rels/zip manipulation, this uses the new extension points, mirroring upstream's native image support: - ChemHandler < FieldHandler, registered via `register_field_handler :chem` - ChemBlock < Block, scanning start/body/end nodes like the native ImageBlock and rewriting the placeholder VML (v:imagedata/v:shape/ o:OLEObject) ids consistently - Statement::Chem#evaluate(env) (new signature) adds the preview image via the DOM model's add_media and the OLE payload to word/embeddings with an oleObject relationship + content type - Sablon::Chem/Ole/Image kept as public value objects so the chemotion_ELN API (Chem.create/Ole/Image) is preserved Adds a self-contained chem_template.docx fixture (built by test/support/build_chem_fixture.rb) and chem_test.rb covering the full render: embeddings/media parts, relationships, content type, rewritten references and field removal. Full suite green (207 runs, 0 failures).
…loop 886f0bf re-ported the Chem/OLE ($$field) feature onto upstream v0.4.3 but dropped the fork's standalone @field image handling in favour of upstream's native Statement::Image/ImageBlock. Those expect a Content::Image-like value (rid_by_file, local_rid, EMU width/height), so the retained ELN-facing Sablon::Image::Definition value object raised NoMethodError when fed through an @field merge field (the report status icon and spectrum attachments). Duck-type Image::Definition onto that contract: a memoized rid_by_file, a local_rid alias over the existing rid slot (kept consistent with the chem preview path), and width/height that expose the stored pixel dimensions in EMU. Pixels are scaled by PX_TO_EMU = 3000 to preserve the legacy fork's image sizing so existing reports do not reflow (an intentional dpi-compat constant, not the OOXML-canonical 9525). Tests: image_bridge_test renders Image::Definition objects through the native @field path (incl. a loop) and asserts every embed resolves and px->EMU scaling applies. chem_test gains a loop case inserting three chem objects, asserting distinct embeddings/media, a declared OLE content type, fully resolved references and unique v:shape ids - the inconsistent rewriting that made MS Word report unreadable content. Full suite green (210 runs).
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Re-aligns ComPlat's custom Chem/OLE insertion feature with the upstream
v0.4.3release.realign-v0.4.3has been rebased onto the currentv0.4.3-xtip (which now carries the release-branch CI workflow), so this PR's checks run
against the latest base.
v0.4.3-xtracks the pristine upstreamv0.4.3tag plus our CI workflow. ThisPR adds the feature on top so we can cut a custom release (e.g.
v0.4.3-1) from it.What's in here
Two commits on top of
v0.4.3-x:Re-port Chem/OLE insertion onto upstream v0.4.3 architecture — realigns the
embedded ChemDraw object + preview image (
$$expr:start/:endmerge fields)with upstream's rewritten HTML converter, template pipeline and field-handler/DOM
systems, using the new extension points instead of the fork's hand-rolled
rels/zip manipulation:
ChemHandler < FieldHandler, registered viaregister_field_handler :chemChemBlock < Block, scanning start/body/end nodes like the nativeImageBlockand rewriting placeholder VML (
v:imagedata/v:shape/o:OLEObject) ids consistentlyStatement::Chem#evaluate(env)adds the preview via the DOM model'sadd_mediaand the OLE payload to
word/embeddingswith an oleObject relationship + content typeSablon::Chem/Ole/Imagekept as public value objects so the chemotion_ELNAPI (
Chem.create/Ole/Image) is preservedBridge Image::Definition to native image insertion; cover multi-chem loop —
duck-types the retained
Image::Definitionvalue object onto upstream'sContent::Imagecontract (rid_by_file,local_rid, EMUwidth/height) so@fieldimage merges (report status icon, spectrum attachments) work through thenative path. Pixels scaled by
PX_TO_EMU = 3000to preserve legacy fork sizing.Tests
chem_test.rb— full render of the Chem/OLE feature plus a loop case insertingthree chem objects (distinct embeddings, unique
v:shapeids)image_bridge_test.rb— rendersImage::Definitionthrough the native@fieldpath (incl. a loop), asserting embeds resolve and px→EMU scaling applies
.docxfixtures built bytest/support/build_chem_fixture.rbFull suite green (210 runs).