Skip to content

Commit 3fde00c

Browse files
committed
Switch passing mjml via argument to via stdin
Alternate fix to bug #25
1 parent e77c5bc commit 3fde00c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

bin/mjml.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import mjml2html from 'mjml'
2+
import { text } from "node:stream/consumers";
23

34
const args = JSON.parse(atob(process.argv.slice(2)));
45

5-
const mjml = args[0];
6+
let mjml = args[0];
67
const options = args[1];
78

9+
if ('-' === mjml) {
10+
mjml = atob(await text(process.stdin));
11+
}
12+
813
let result = ''
914

1015
try {

src/Mjml.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ protected function getSideCarResult(array $arguments): string
208208

209209
protected function getLocalResult(array $arguments): string
210210
{
211+
$mjmlTemplate = $arguments[0];
212+
$arguments[0] = '-';
213+
211214
$process = new Process(
212215
$this->getCommand($arguments),
213216
$this->workingDirectory,
214217
);
218+
$process->setInput(base64_encode($mjmlTemplate));
215219

216220
$process->run();
217221

tests/MjmlTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@
108108
['<mjml><mj-body><mj-wrapper></mj-wrapper></mj-body></mjml>', true],
109109
]);
110110

111+
it('can render large mjml content', function () {
112+
$mjml = '<mjml><mj-body>'.
113+
implode('', array_pad([], 10_000, '<mj-wrapper>filler</mj-wrapper>'))
114+
.'</mj-body></mjml>';
115+
$result = Mjml::new()->convert($mjml);
116+
117+
expect($result)
118+
->toBeInstanceOf(MjmlResult::class)
119+
->html()->toBeString()
120+
->errors()->toHaveCount(0)
121+
->hasErrors()->toBeFalse();
122+
});
123+
111124
function mjmlSnippet(): string
112125
{
113126
return <<<'MJML'

0 commit comments

Comments
 (0)