Skip to content

Commit f022c64

Browse files
committed
rename _render_mjml to _to_mjml
1 parent 8615bb5 commit f022c64

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

emailer_lib/ingress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def mjml_to_intermediate_email(
6464
# Handle MJMLTag objects by preprocessing images
6565
if isinstance(mjml_content, MJMLTag):
6666
processed_mjml, inline_attachments = _process_mjml_images(mjml_content)
67-
mjml_markup = processed_mjml._render_mjml()
67+
mjml_markup = processed_mjml._to_mjml()
6868
else:
6969
# String-based MJML, no preprocessing needed
7070
warnings.warn("MJMLTag not detected; treating input as plaintext MJML markup", UserWarning)

emailer_lib/mjml/_core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ def __init__(
126126
# if self.content is not None:
127127
# self.children = []
128128

129-
def _render_mjml(self, indent: int = 0, eol: str = "\n") -> str:
129+
def _to_mjml(self, indent: int = 0, eol: str = "\n") -> str:
130130
"""
131131
Render MJMLTag and its children to MJML markup.
132132
Ported from htmltools Tag rendering logic.
133133
134-
Note: BytesIO/bytes in image src attributes are not supported by _render_mjml().
134+
Note: BytesIO/bytes in image src attributes are not supported by _to_mjml().
135135
Pass the MJMLTag directly to mjml_to_intermediate_email() instead.
136136
"""
137137

@@ -150,7 +150,7 @@ def _flatten(children):
150150
if isinstance(src_value, (bytes, BytesIO)):
151151
raise ValueError(
152152
"Cannot render MJML with BytesIO/bytes in image src attribute. "
153-
"Pass the MJMLTag object directly to mjml_to_intermediate_email() instead of calling _render_mjml() first. "
153+
"Pass the MJMLTag object directly to mjml_to_intermediate_email() instead of calling _to_mjml() first. "
154154
"Example: i_email = mjml_to_intermediate_email(doc)"
155155
)
156156

@@ -167,7 +167,7 @@ def _flatten(children):
167167
child_strs = []
168168
for child in _flatten(self.children):
169169
if isinstance(child, MJMLTag):
170-
child_strs.append(child._render_mjml(indent + 2, eol))
170+
child_strs.append(child._to_mjml(indent + 2, eol))
171171
else:
172172
child_strs.append(str(child))
173173
if child_strs:
@@ -202,7 +202,7 @@ def to_html(self, **mjml2html_kwargs) -> str:
202202
in <mjml><mj-body>...</mj-body></mjml> with a warning.
203203
204204
Note: This method embeds all images as inline data URIs in the HTML.
205-
For email sending with separate attachments, use mjml_to_intermediate_email() instead.
205+
For email composition with inline attachments, use mjml_to_intermediate_email() instead.
206206
207207
Parameters
208208
----------
@@ -216,7 +216,7 @@ def to_html(self, **mjml2html_kwargs) -> str:
216216
"""
217217
if self.tagName == "mjml":
218218
# Already a complete MJML document
219-
mjml_markup = self._render_mjml()
219+
mjml_markup = self._to_mjml()
220220
elif self.tagName == "mj-body":
221221
# Wrap only in mjml tag
222222
warnings.warn(
@@ -227,7 +227,7 @@ def to_html(self, **mjml2html_kwargs) -> str:
227227
stacklevel=2,
228228
)
229229
wrapped = MJMLTag("mjml", self)
230-
mjml_markup = wrapped._render_mjml()
230+
mjml_markup = wrapped._to_mjml()
231231
else:
232232
# Warn and wrap in mjml/mj-body
233233
warnings.warn(
@@ -239,6 +239,6 @@ def to_html(self, **mjml2html_kwargs) -> str:
239239
)
240240
# Wrap in mjml and mj-body
241241
wrapped = MJMLTag("mjml", MJMLTag("mj-body", self))
242-
mjml_markup = wrapped._render_mjml()
242+
mjml_markup = wrapped._to_mjml()
243243

244244
return mjml2html(mjml_markup, **mjml2html_kwargs)

emailer_lib/mjml/tests/test_core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,41 @@ def test_tag_with_dict_attributes():
3838

3939
def test_tag_filters_none_children():
4040
tag = MJMLTag("mj-column", MJMLTag("mj-text", content="Text"), None)
41-
mjml_content = tag._render_mjml()
41+
mjml_content = tag._to_mjml()
4242

4343
# None should not appear in output
4444
assert mjml_content.count("<mj-text>") == 1
4545

4646

4747
def test_render_empty_tag():
4848
tag = MJMLTag("mj-spacer")
49-
mjml_content = tag._render_mjml()
49+
mjml_content = tag._to_mjml()
5050
assert mjml_content == "<mj-spacer></mj-spacer>"
5151

5252

5353
def test_render_with_attributes():
5454
tag = MJMLTag("mj-spacer", attributes={"height": "20px"})
55-
mjml_content = tag._render_mjml()
55+
mjml_content = tag._to_mjml()
5656
assert mjml_content == '<mj-spacer height="20px"></mj-spacer>'
5757

5858

5959
def test_render_with_custom_indent():
6060
tag = MJMLTag("mj-text", content="Hello")
61-
mjml_content = tag._render_mjml(indent=4)
61+
mjml_content = tag._to_mjml(indent=4)
6262
assert mjml_content.startswith(" <mj-text>")
6363

6464

6565
def test_render_with_custom_eol():
6666
tag = MJMLTag("mj-text", content="Hello")
67-
mjml_content = tag._render_mjml(eol="\r\n")
67+
mjml_content = tag._to_mjml(eol="\r\n")
6868
assert "\r\n" in mjml_content
6969

7070

7171
def test_render_nested_tags():
7272
tag = MJMLTag(
7373
"mj-section", MJMLTag("mj-column", MJMLTag("mj-text", content="Nested"))
7474
)
75-
mjml_content = tag._render_mjml()
75+
mjml_content = tag._to_mjml()
7676

7777
assert "<mj-section>" in mjml_content
7878
assert "<mj-column>" in mjml_content
@@ -83,7 +83,7 @@ def test_render_nested_tags():
8383
def test_render_with_string_and_tag_children():
8484
child_tag = MJMLTag("mj-text", content="Tagged")
8585
tag = MJMLTag("mj-column", "Plain text", child_tag, "More text")
86-
mjml_content = tag._render_mjml()
86+
mjml_content = tag._to_mjml()
8787

8888
assert "Plain text" in mjml_content
8989
assert "<mj-text>" in mjml_content
@@ -169,34 +169,34 @@ def test_children_sequence_flattening():
169169
assert tag.children[1] == child2
170170
assert tag.children[2] == child3
171171

172-
mjml_content = tag._render_mjml()
172+
mjml_content = tag._to_mjml()
173173

174174
assert mjml_content.count("<mj-text>") == 3
175175
assert "Text 1" in mjml_content
176176
assert "Text 2" in mjml_content
177177
assert "Text 3" in mjml_content
178178

179179

180-
def test_render_mjml_raises_on_bytesio_in_image_src():
180+
def test_to_mjml_raises_on_bytesio_in_image_src():
181181
image_data = BytesIO(b"fake image data")
182182
image_tag = MJMLTag(
183183
"mj-image",
184184
attributes={"src": image_data, "alt": "Test"}
185185
)
186186

187187
with pytest.raises(ValueError, match="Cannot render MJML with BytesIO/bytes"):
188-
image_tag._render_mjml()
188+
image_tag._to_mjml()
189189

190190

191-
def test_render_mjml_raises_on_bytes_in_image_src():
191+
def test_to_mjml_raises_on_bytes_in_image_src():
192192
image_data = b"fake image data"
193193
image_tag = MJMLTag(
194194
"mj-image",
195195
attributes={"src": image_data, "alt": "Test"}
196196
)
197197

198198
with pytest.raises(ValueError, match="Cannot render MJML with BytesIO/bytes"):
199-
image_tag._render_mjml()
199+
image_tag._to_mjml()
200200

201201

202202
def test_tagattr_dict_stores_bytesio():

emailer_lib/mjml/tests/test_tags.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_container_tag_accepts_children():
3939
assert len(sec.children) == 1
4040
assert sec.children[0].tagName == "mj-column"
4141

42-
mjml_content = sec._render_mjml()
42+
mjml_content = sec._to_mjml()
4343
assert "<mj-section>" in mjml_content
4444
assert "<mj-column>" in mjml_content
4545
assert "<mj-text>" in mjml_content
@@ -53,7 +53,7 @@ def test_container_tag_accepts_attributes():
5353
assert sec.attrs["background-color"] == "#fff"
5454
assert sec.attrs["padding"] == "20px"
5555

56-
mjml_content = sec._render_mjml()
56+
mjml_content = sec._to_mjml()
5757
assert '<mj-section background-color="#fff" padding="20px">' in mjml_content
5858

5959

@@ -66,7 +66,7 @@ def test_container_tag_accepts_children_and_attrs():
6666
assert len(sec.children) == 2
6767
assert sec.attrs["background-color"] == "#f0f0f0"
6868

69-
mjml_content = sec._render_mjml()
69+
mjml_content = sec._to_mjml()
7070
assert 'background-color="#f0f0f0"' in mjml_content
7171
assert "Col 1" in mjml_content
7272
assert "Col 2" in mjml_content
@@ -79,7 +79,7 @@ def test_leaf_tag_accepts_content():
7979
assert txt.tagName == "mj-text"
8080
assert txt.content == "Hello World"
8181

82-
mjml_content = txt._render_mjml()
82+
mjml_content = txt._to_mjml()
8383
assert mjml_content == "<mj-text>\nHello World\n</mj-text>"
8484

8585

@@ -89,7 +89,7 @@ def test_leaf_tag_accepts_attributes():
8989
assert txt.attrs["color"] == "red"
9090
assert txt.attrs["font-size"] == "16px"
9191

92-
mjml_content = txt._render_mjml()
92+
mjml_content = txt._to_mjml()
9393
assert 'color="red"' in mjml_content
9494
assert 'font-size="16px"' in mjml_content
9595
assert "Hello" in mjml_content
@@ -108,7 +108,7 @@ def test_button_is_leaf_tag():
108108
assert btn.content == "Click Me"
109109
assert btn.attrs["href"] == "https://example.com"
110110

111-
mjml_content = btn._render_mjml()
111+
mjml_content = btn._to_mjml()
112112
assert 'href="https://example.com"' in mjml_content
113113
assert "Click Me" in mjml_content
114114
assert "<mj-button" in mjml_content
@@ -158,7 +158,7 @@ def test_raw_tag():
158158
assert r.tagName == "mj-raw"
159159
assert r.content == "<div>Custom HTML</div>"
160160

161-
mjml_content = r._render_mjml()
161+
mjml_content = r._to_mjml()
162162
assert mjml_content == "<mj-raw>\n<div>Custom HTML</div>\n</mj-raw>"
163163

164164

@@ -167,7 +167,7 @@ def test_table_tag():
167167
assert tbl.tagName == "mj-table"
168168
assert "<table>" in tbl.content
169169

170-
mjml_content = tbl._render_mjml()
170+
mjml_content = tbl._to_mjml()
171171
assert "<mj-table>" in mjml_content
172172
assert "<table><tr><td>Cell</td></tr></table>" in mjml_content
173173

@@ -195,7 +195,7 @@ def test_image_tag():
195195
assert img.attrs["src"] == "https://example.com/image.jpg"
196196
assert img.attrs["alt"] == "Test Image"
197197

198-
mjml_content = img._render_mjml()
198+
mjml_content = img._to_mjml()
199199
assert 'src="https://example.com/image.jpg"' in mjml_content
200200
assert 'alt="Test Image"' in mjml_content
201201
assert "<mj-image" in mjml_content
@@ -214,7 +214,7 @@ def test_attributes_container_with_mj_all_and_classes():
214214
assert attrs.children[1].tagName == "mj-class"
215215
assert attrs.children[2].tagName == "mj-class"
216216

217-
mjml_content = attrs._render_mjml()
217+
mjml_content = attrs._to_mjml()
218218
assert "<mj-attributes>" in mjml_content
219219
assert "<mj-all" in mjml_content
220220
assert 'font-family="Arial"' in mjml_content
@@ -226,7 +226,7 @@ def test_component_with_mj_class_attribute():
226226
txt = text(attributes={"mj-class": "blue big"}, content="Hello World!")
227227
assert txt.attrs["mj-class"] == "blue big"
228228

229-
mjml_content = txt._render_mjml()
229+
mjml_content = txt._to_mjml()
230230
assert 'mj-class="blue big"' in mjml_content
231231
assert "Hello World!" in mjml_content
232232

@@ -258,7 +258,7 @@ def test_full_document_with_attributes():
258258
assert attrs_tag.tagName == "mj-attributes"
259259
assert len(attrs_tag.children) == 4
260260

261-
mjml_content = doc._render_mjml()
261+
mjml_content = doc._to_mjml()
262262
assert "<mj-attributes>" in mjml_content
263263
assert '<mj-text padding="0"' in mjml_content
264264
assert 'name="blue"' in mjml_content

emailer_lib/tests/test_ingress.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_mjml_to_intermediate_email_with_bytesio():
186186
assert result.inline_attachments[cid_filename] != ""
187187

188188

189-
def test_mjml_render_mjml_with_bytesio_raises_error():
189+
def test_mjml_to_mjml_with_bytesio_raises_error():
190190
from io import BytesIO
191191
from emailer_lib.mjml import mjml, body, section, column, image
192192

@@ -207,9 +207,9 @@ def test_mjml_render_mjml_with_bytesio_raises_error():
207207
)
208208
)
209209

210-
# Calling _render_mjml() should raise an error with a helpful message
210+
# Calling _to_mjml() should raise an error with a helpful message
211211
with pytest.raises(ValueError, match="Cannot render MJML with BytesIO/bytes"):
212-
mjml_tag._render_mjml()
212+
mjml_tag._to_mjml()
213213

214214
# But passing the tag directly to mjml_to_intermediate_email should work
215215
result = mjml_to_intermediate_email(mjml_tag)

0 commit comments

Comments
 (0)