MCPcopy
hub / github.com/mjmlio/mjml / renderChildren

Method renderChildren

packages/mjml-core/src/createComponent.js:201–261  ·  view source on GitHub ↗
(children, options = {})

Source from the content-addressed store, hash-verified

199 }
200
201 renderChildren(children, options = {}) {
202 const {
203 props = {},
204 renderer = (component) => component.render(),
205 attributes = {},
206 rawXML = false,
207 } = options
208
209 children = children || this.props.children
210
211 if (rawXML) {
212 return children
213 .map((child) => {
214 child.attributes = { ...attributes, ...child.attributes }
215 return jsonToXML(child)
216 })
217 .join('\n')
218 }
219
220 const sibling = children.length
221
222 const rawComponents = filter(this.context.components, (c) =>
223 c.isRawElement(),
224 )
225 const nonRawSiblings = children.filter(
226 (child) => !find(rawComponents, (c) => c.getTagName() === child.tagName),
227 ).length
228
229 let output = ''
230 let index = 0
231
232 forEach(children, (children) => {
233 const component = initComponent({
234 name: children.tagName,
235 initialDatas: {
236 ...children,
237 attributes: {
238 ...attributes,
239 ...children.attributes,
240 },
241 context: this.getChildContext(),
242 props: {
243 ...props,
244 first: index === 0,
245 index,
246 last: index + 1 === sibling,
247 sibling,
248 nonRawSiblings,
249 },
250 },
251 })
252
253 if (component !== null) {
254 output += renderer(component)
255 }
256
257 index++ // eslint-disable-line no-plusplus
258 })

Callers 15

renderColumnMethod · 0.80
renderWrappedChildrenMethod · 0.80
renderMethod · 0.80
renderWrappedChildrenMethod · 0.80
renderContentMethod · 0.80
generateRadiosMethod · 0.80
generateThumbnailsMethod · 0.80
generateImagesMethod · 0.80
renderFallbackMethod · 0.80
handleMissingChildrenMethod · 0.80
renderMethod · 0.80
renderMethod · 0.80

Calls 6

jsonToXMLFunction · 0.85
initComponentFunction · 0.85
isRawElementMethod · 0.80
renderMethod · 0.45
getTagNameMethod · 0.45
getChildContextMethod · 0.45

Tested by

no test coverage detected