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

feat(core): render service #4467

Merged
merged 31 commits into from
Mar 11, 2021
Merged

feat(core): render service #4467

merged 31 commits into from
Mar 11, 2021

Conversation

samuelmasse
Copy link
Contributor

@samuelmasse samuelmasse commented Feb 3, 2021

This is a very simple interface meant to simplify the creation of payloads for builtin types.

const content = bp.render.text({ en: 'hello {{user.name}}', fr: 'salut {{user.name}}' })
// content.text : { en: 'hello {{user.name}}', fr: 'salut {{user.name}}' }
const translated = bp.render.translate(content, 'fr')
// translated.text : 'salut {{user.name}}'
const templated = bp.render.template(translated, { user: { name: 'bob' } })
// templated.text : 'salut bob'

You can also create a pipeline to avoid having to render, translate and template multiple payloads. You provide a language and a context and .translate and .template get automatically called

const render = bp.render.pipeline('fr', { user: { name: 'bob', age: 43, pin: 3030 } })
const text1 = render.text({ en: 'hello {{user.name}}', fr: 'salut {{user.name}}' })
// text1.text : salut bob
const text2 = render.text({ en: 'age : {{user.age}}', fr: 'âge : {{user.age}}' })
// text2.text : âge 43
const text3 = render.text('PIN : {{user.pin}}')
// text3.text : PIN 3030

It does not support the old way of storing translations with $en and $fr. I'm not sure what the state of that is, but preferably we would get rid of that and only use nested translations.

I'm also not sure how well this works alongside bp.cms. I made this to programmatically create payloads, so if someone decides to use the cms and this interface interchangeably, it probably won't work very well.

This also does not support custom content type renderers. I put a middleware in the cms for now. Basically any payload that doesn't have the new rendered property set to true gets rendered by its channel renderer. It's an hackish solution that's temporarily in place until content type renderers are removed/changed. I plan on reimplementing content type renderers as extensions to channels, and having our own builtin content types be processed with their default payload in all of our channels (so no renderers for them).

Typing indicators are also a problem. We'll need to adjust our channels so that all payloads can include typings indicators

@samuelmasse samuelmasse marked this pull request as draft February 3, 2021 20:24
@samuelmasse samuelmasse requested a review from EFF February 3, 2021 20:25
@samuelmasse samuelmasse marked this pull request as ready for review February 5, 2021 18:14
@samuelmasse samuelmasse requested a review from EFF March 11, 2021 21:26
@EFF EFF merged commit 1a6e953 into master Mar 11, 2021
@samuelmasse samuelmasse deleted the sm-ez-cms branch March 11, 2021 22:20
@EFF EFF mentioned this pull request Mar 15, 2021
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.

None yet

3 participants