Skip to content
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

(647) Support embed codes in inline preview #9635

Merged

Conversation

pezholio
Copy link
Contributor

@pezholio pezholio commented Nov 20, 2024

https://trello.com/c/cbXSET85/647-investigate-inline-preview-in-whitehall

This updates the inline Govspeak preview within Whitehall to support embed codes. As we have the luxury of Whitehall being within the confines of Whitehall, it's fairly easy for us to use the content_block_tools gem to parse the Govspeak, pull out the references, fetch the content blocks and then replace the embed code with the rendered blocks.

Screenshots

Raw Govspeak

image

Preview

image

This fits better with the pattern we’ve established that makes Minitest
a bit more Rspec-like
This will make it easier to get a representation of a particular edition
@pezholio pezholio force-pushed the content-modelling/647-show-embed-codes-in-inline-preview branch from 61ebdcc to 6feae72 Compare November 20, 2024 17:22
end

def content_blocks
@content_blocks ||= ContentBlockManager::ContentBlock::Edition.joins(:document).where(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query would return all published Editions (of which there could be many per Document because we don't have a superseded workflow) but I think we would only want the latest_edition scope?
I'm wondering if the render should belong to the Document, as the embed code isn't going to change throughout its lifecycle, so we will always only be referring to the live content right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise when you update an edition the changes wouldn't propagate to other content blocks, or am I misunderstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point on the latest edition scope. I did consider having it on the document, but I thought we might want to render draft blocks too (for example, when doing the in-app preview)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to render draft blocks too (for example, when doing the in-app preview)

ah yeah that's true... I guess as long as this service and the API only ever returns the live one then it will be ok, would be worth adding a Document with a couple of Editions in the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tweaked it so we have a current_versions scope now, which ensures we're only querying the latest published editions.

This ensures we’re only querying editions that are the most current
published version
@pezholio pezholio force-pushed the content-modelling/647-show-embed-codes-in-inline-preview branch from 6feae72 to f5cfede Compare November 21, 2024 13:09
Although this will be used in Whitehall proper, it makes sense to have
this namespaced under the ContentBlockManager
This updates `govspeak_to_admin_html` to call the new service on any
generated HTML, so embed codes are transformed in the live preview.
@pezholio pezholio force-pushed the content-modelling/647-show-embed-codes-in-inline-preview branch from f5cfede to 50acb8b Compare November 21, 2024 13:20
@pezholio
Copy link
Contributor Author

@pezholio pezholio merged commit 17a27f4 into main Nov 21, 2024
19 checks passed
@pezholio pezholio deleted the content-modelling/647-show-embed-codes-in-inline-preview branch November 21, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants