From 1067123c62f7869e51167e920f67427ab62bf91c Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Wed, 15 May 2024 08:59:22 +0200 Subject: [PATCH 1/5] chore: add ci tooling Signed-off-by: Fred Carlsen --- .github/workflows/code-analysis.yaml | 37 ++++++++++++++++++++++++++++ composer.json | 18 ++++++++++++++ ecs.php | 14 +++++++++++ phpstan.neon | 6 +++++ 4 files changed, 75 insertions(+) create mode 100644 .github/workflows/code-analysis.yaml create mode 100644 ecs.php create mode 100644 phpstan.neon diff --git a/.github/workflows/code-analysis.yaml b/.github/workflows/code-analysis.yaml new file mode 100644 index 0000000..a07f0f4 --- /dev/null +++ b/.github/workflows/code-analysis.yaml @@ -0,0 +1,37 @@ +name: Code Analysis + +on: + pull_request: + workflow_dispatch: +permissions: + contents: read +jobs: + code_analysis: + strategy: + fail-fast: false + matrix: + actions: + - name: 'PHPStan' + run: composer phpstan + - name: 'Coding Standards' + run: composer check-cs + name: ${{ matrix.actions.name }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + - name: Setup PHP + id: setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip' + ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M + tools: composer:v2 + - name: Install Composer dependencies + run: composer install --no-interaction --no-ansi --no-progress + - run: ${{ matrix.actions.run }} \ No newline at end of file diff --git a/composer.json b/composer.json index b2edaad..3c2025f 100644 --- a/composer.json +++ b/composer.json @@ -25,11 +25,29 @@ "craftcms/cms": "^4.0.0-beta.1", "mikehaertl/php-shellcommand": "^1.4" }, + "require-dev": { + "craftcms/ecs": "dev-main", + "craftcms/phpstan": "dev-main", + "craftcms/rector": "dev-main" + }, "autoload": { "psr-4": { "superbig\\mjml\\": "src/" } }, + "scripts": { + "phpstan": "phpstan --ansi --memory-limit=1G", + "check-cs": "ecs check --ansi", + "fix-cs": "ecs check --fix --ansi" + }, + "config": { + "allow-plugins": { + "craftcms/plugin-installer": true, + "yiisoft/yii2-composer": true + }, + "optimize-autoloader": true, + "sort-packages": true + }, "extra": { "name": "MJML", "handle": "mjml", diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..7b09884 --- /dev/null +++ b/ecs.php @@ -0,0 +1,14 @@ +paths([ + __DIR__ . '/src', + __FILE__, + ]); + + $ecsConfig->parallel(); + $ecsConfig->sets([SetList::CRAFT_CMS_4]); +}; \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..8bc0882 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +includes: + - %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon +parameters: + level: 5 + paths: + - src \ No newline at end of file From 0b965a9a8fb3d3c1f3c90540b7b48f15afab283d Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Wed, 15 May 2024 09:02:44 +0200 Subject: [PATCH 2/5] chore: formatting Signed-off-by: Fred Carlsen --- ecs.php | 2 +- src/MJML.php | 16 +++++++--------- src/config.php | 8 ++++---- src/models/MJMLModel.php | 2 +- src/models/Settings.php | 4 ++-- src/services/MJMLService.php | 9 ++++----- src/translations/en/mjml.php | 2 +- src/twigextensions/MJMLTwigExtension.php | 2 -- src/variables/MJMLVariable.php | 1 - 9 files changed, 20 insertions(+), 26 deletions(-) diff --git a/ecs.php b/ecs.php index 7b09884..b5fe0ae 100644 --- a/ecs.php +++ b/ecs.php @@ -11,4 +11,4 @@ $ecsConfig->parallel(); $ecsConfig->sets([SetList::CRAFT_CMS_4]); -}; \ No newline at end of file +}; diff --git a/src/MJML.php b/src/MJML.php index bd8b130..64f79ea 100644 --- a/src/MJML.php +++ b/src/MJML.php @@ -10,18 +10,16 @@ namespace superbig\mjml; -use superbig\mjml\services\MJMLService; -use superbig\mjml\variables\MJMLVariable; -use superbig\mjml\twigextensions\MJMLTwigExtension; -use superbig\mjml\models\Settings; - use Craft; use craft\base\Plugin; -use craft\services\Plugins; -use craft\events\PluginEvent; -use craft\web\UrlManager; -use craft\web\twig\variables\CraftVariable; use craft\events\RegisterUrlRulesEvent; +use craft\web\twig\variables\CraftVariable; + +use craft\web\UrlManager; +use superbig\mjml\models\Settings; +use superbig\mjml\services\MJMLService; +use superbig\mjml\twigextensions\MJMLTwigExtension; +use superbig\mjml\variables\MJMLVariable; use yii\base\Event; diff --git a/src/config.php b/src/config.php index 483ea75..3ecd7e7 100644 --- a/src/config.php +++ b/src/config.php @@ -24,16 +24,16 @@ return [ // The path to where the your version of Node is located, i.e. `/usr/local/bin/node` - 'nodePath' => '', + 'nodePath' => '', // The path to where the MJML cli installed with npm is located, i.e. `/usr/local/bin/mjml` - 'mjmlCliPath' => '', + 'mjmlCliPath' => '', // cli config args, e.g. `--config.minify true`', - 'mjmlCliConfigArgs' => '', + 'mjmlCliConfigArgs' => '', // The app id received by email - 'appId' => '', + 'appId' => '', // Enter the secret key received by email 'secretKey' => '', diff --git a/src/models/MJMLModel.php b/src/models/MJMLModel.php index 69462cb..57f3edc 100644 --- a/src/models/MJMLModel.php +++ b/src/models/MJMLModel.php @@ -10,8 +10,8 @@ namespace superbig\mjml\models; -use craft\helpers\Template; use craft\base\Model; +use craft\helpers\Template; /** * @author Superbig diff --git a/src/models/Settings.php b/src/models/Settings.php index 5f8ee25..0308120 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -10,10 +10,10 @@ namespace superbig\mjml\models; -use superbig\mjml\MJML; - use Craft; + use craft\base\Model; +use superbig\mjml\MJML; /** * @author Superbig diff --git a/src/services/MJMLService.php b/src/services/MJMLService.php index 29cfa8e..32beeca 100644 --- a/src/services/MJMLService.php +++ b/src/services/MJMLService.php @@ -10,17 +10,16 @@ namespace superbig\mjml\services; +use Craft; +use craft\base\Component; use craft\helpers\FileHelper; use craft\helpers\Json; -use craft\helpers\Template; use craft\web\View; use GuzzleHttp\Client; -use mikehaertl\shellcommand\Command; -use superbig\mjml\MJML; -use Craft; -use craft\base\Component; +use mikehaertl\shellcommand\Command; use superbig\mjml\exceptions\MJMLException; +use superbig\mjml\MJML; use superbig\mjml\models\MJMLModel; /** diff --git a/src/translations/en/mjml.php b/src/translations/en/mjml.php index af66803..6228132 100644 --- a/src/translations/en/mjml.php +++ b/src/translations/en/mjml.php @@ -14,6 +14,6 @@ * @since 1.0.0 */ return [ - 'MJML plugin loaded' => 'MJML plugin loaded', + 'MJML plugin loaded' => 'MJML plugin loaded', 'Error rendering MJML: {error}' => 'Error rendering MJML: {error}', ]; diff --git a/src/twigextensions/MJMLTwigExtension.php b/src/twigextensions/MJMLTwigExtension.php index be12935..e3daecc 100644 --- a/src/twigextensions/MJMLTwigExtension.php +++ b/src/twigextensions/MJMLTwigExtension.php @@ -12,8 +12,6 @@ use superbig\mjml\MJML; -use Craft; - /** * @author Superbig * @package MJML diff --git a/src/variables/MJMLVariable.php b/src/variables/MJMLVariable.php index 63813a1..dc64e20 100644 --- a/src/variables/MJMLVariable.php +++ b/src/variables/MJMLVariable.php @@ -13,7 +13,6 @@ use craft\helpers\Template; use superbig\mjml\MJML; -use Craft; use superbig\mjml\models\MJMLModel; /** From 44ec51ee707031c39d6312cc2981e6484faaa31b Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Wed, 15 May 2024 11:02:21 +0200 Subject: [PATCH 3/5] chore: fixes Signed-off-by: Fred Carlsen --- src/MJML.php | 23 ++++++------ src/models/MJMLModel.php | 25 +++---------- src/models/Settings.php | 46 ++++++------------------ src/twigextensions/MJMLTwigExtension.php | 41 ++++++--------------- src/variables/MJMLVariable.php | 17 ++------- 5 files changed, 37 insertions(+), 115 deletions(-) diff --git a/src/MJML.php b/src/MJML.php index 64f79ea..a089273 100644 --- a/src/MJML.php +++ b/src/MJML.php @@ -21,7 +21,11 @@ use superbig\mjml\twigextensions\MJMLTwigExtension; use superbig\mjml\variables\MJMLVariable; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\Error\SyntaxError; use yii\base\Event; +use yii\base\Exception; /** * Class MJML @@ -35,14 +39,7 @@ */ class MJML extends Plugin { - /** - * @var MJML - */ - public static $plugin; - - /** - * @var string - */ + public static MJML $plugin; public string $schemaVersion = '1.0.0'; /** @@ -87,18 +84,18 @@ function(Event $event) { ); } - /** - * @inheritdoc - */ protected function createSettingsModel(): ?\craft\base\Model { return new Settings(); } /** - * @inheritdoc + * @throws SyntaxError + * @throws Exception + * @throws RuntimeError + * @throws LoaderError */ - protected function settingsHtml(): ?string + protected function settingsHtml(): string { return Craft::$app->view->renderTemplate( 'mjml/settings', diff --git a/src/models/MJMLModel.php b/src/models/MJMLModel.php index 57f3edc..a598f7a 100644 --- a/src/models/MJMLModel.php +++ b/src/models/MJMLModel.php @@ -20,28 +20,11 @@ */ class MJMLModel extends Model { - // Public Properties - // ========================================================================= + public string $html; + public string $mjml; + public string $mjmlVersion; - /** - * @var string - */ - public $html; - - /** - * @var string - */ - public $mjml; - - /** - * @var string - */ - public $mjmlVersion; - - // Public Methods - // ========================================================================= - - public function output() + public function output(): \Twig\Markup { return Template::raw($this->html); } diff --git a/src/models/Settings.php b/src/models/Settings.php index 0308120..2277da6 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -22,38 +22,12 @@ */ class Settings extends Model { - // Public Properties - // ========================================================================= - - /** - * @var string - */ - public $nodePath = ''; - - /** - * @var string - */ - public $mjmlCliPath = ''; - - /** - * @var string - */ - public $mjmlCliConfigArgs = ''; - - /** - * @var string - */ - public $mjmlCliIncludesPath = ''; - - /** - * @var string - */ - public $appId = ''; - - /** - * @var string - */ - public $secretKey = ''; + public string $nodePath = ''; + public string $mjmlCliPath = ''; + public string $mjmlCliConfigArgs = ''; + public string $mjmlCliIncludesPath = ''; + public string $appId = ''; + public string $secretKey = ''; public function init(): void { @@ -62,9 +36,11 @@ public function init(): void parent::init(); } - /** - * @inheritdoc - */ + public function behaviors() + { + + } + public function rules(): array { return [ diff --git a/src/twigextensions/MJMLTwigExtension.php b/src/twigextensions/MJMLTwigExtension.php index e3daecc..0858ab1 100644 --- a/src/twigextensions/MJMLTwigExtension.php +++ b/src/twigextensions/MJMLTwigExtension.php @@ -11,51 +11,36 @@ namespace superbig\mjml\twigextensions; use superbig\mjml\MJML; +use Twig\Extension\AbstractExtension; +use Twig\TwigFilter; /** * @author Superbig * @package MJML * @since 1.0.0 */ -class MJMLTwigExtension extends \Twig\Extension\AbstractExtension +class MJMLTwigExtension extends AbstractExtension { - // Public Methods - // ========================================================================= - - /** - * @inheritdoc - */ - public function getName() + public function getName(): string { return 'MJML'; } - /** - * @inheritdoc - */ - public function getFilters() + public function getFilters(): array { return [ - new \Twig\TwigFilter('mjml', [$this, 'mjml']), - new \Twig\TwigFilter('mjmlCli', [$this, 'mjmlCli']), + new TwigFilter('mjml', [$this, 'mjml']), + new TwigFilter('mjmlCli', [$this, 'mjmlCli']), ]; } - /** - * @inheritdoc - */ - public function getFunctions() + public function getFunctions(): array { return [ ]; } - /** - * @param null $html - * - * @return string - */ - public function mjml($html = null) + public function mjml($html = null): ?string { $result = MJML::$plugin->mjmlService->parse($html); @@ -66,13 +51,7 @@ public function mjml($html = null) return $result->output(); } - /** - * @param null $html - * - * @return string - * @throws \yii\base\ErrorException - */ - public function mjmlCli($html = null) + public function mjmlCli($html = null): ?string { $result = MJML::$plugin->mjmlService->parseCli($html); diff --git a/src/variables/MJMLVariable.php b/src/variables/MJMLVariable.php index dc64e20..e12f860 100644 --- a/src/variables/MJMLVariable.php +++ b/src/variables/MJMLVariable.php @@ -22,25 +22,12 @@ */ class MJMLVariable { - // Public Methods - // ========================================================================= - - /** - * @param null|string $html - * - * @return MJMLModel|null - */ - public function parse($html = null) + public function parse(string $html = null): ?MJMLModel { return MJML::$plugin->mjmlService->parse($html); } - /** - * @param string $template - * - * @return MJMLModel|null - */ - public function include(string $template = '', $variables = null, $renderMethod = 'cli') + public function include(string $template = '', $variables = null, $renderMethod = 'cli'): \Twig\Markup { return Template::raw(MJML::$plugin->mjmlService->include($template, $variables, $renderMethod)); } From a786de13667dacda7b6cc4975dcba2712990a49e Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Sun, 26 May 2024 13:01:03 +0200 Subject: [PATCH 4/5] chore: code + settings fixes fixes #12 Signed-off-by: Fred Carlsen --- src/models/MJMLModel.php | 12 +++++- src/models/Settings.php | 34 ++++++++++++++--- src/services/MJMLService.php | 43 ++++++++++++---------- src/templates/settings.twig | 47 ++++++++++++++++-------- src/twigextensions/MJMLTwigExtension.php | 10 ++++- src/variables/MJMLVariable.php | 6 ++- 6 files changed, 106 insertions(+), 46 deletions(-) diff --git a/src/models/MJMLModel.php b/src/models/MJMLModel.php index a598f7a..578e5b7 100644 --- a/src/models/MJMLModel.php +++ b/src/models/MJMLModel.php @@ -22,17 +22,25 @@ class MJMLModel extends Model { public string $html; public string $mjml; - public string $mjmlVersion; public function output(): \Twig\Markup { return Template::raw($this->html); } + /** + * @param array{html: string, mjml: string} $results + * @return MJMLModel + */ + public static function create(array $results): MJMLModel + { + return new self($results); + } + /** * @inheritdoc */ - public function rules(): array + public function defineRules(): array { return [ [['html', 'mjml'], 'string'], diff --git a/src/models/Settings.php b/src/models/Settings.php index 2277da6..cc18d96 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -13,7 +13,7 @@ use Craft; use craft\base\Model; -use superbig\mjml\MJML; +use craft\behaviors\EnvAttributeParserBehavior; /** * @author Superbig @@ -36,16 +36,40 @@ public function init(): void parent::init(); } - public function behaviors() + public function defineBehaviors(): array { - + return [ + 'parser' => [ + 'class' => EnvAttributeParserBehavior::class, + 'attributes' => [ + 'nodePath', + 'mjmlCliPath', + 'mjmlCliConfigArgs', + 'mjmlCliIncludesPath', + 'appId', + 'secretKey', + ], + ], + ]; } - public function rules(): array + public function defineRules(): array { return [ [['appId', 'secretKey', 'mjmlCliPath', 'nodePath', 'mjmlCliConfigArgs'], 'string'], - [['appId', 'secretKey'], 'required'], + [['appId', 'secretKey'], 'required', 'when' => fn(Settings $model) => !empty($model->appId) || !empty($model->secretKey)], + [['mjmlCliPath', 'nodePath'], 'required', 'when' => fn(Settings $model) => !empty($model->mjmlCliPath) || !empty($model->nodePath)], + ]; + } + + public function attributeLabels() + { + return [ + 'appId' => Craft::t('mjml', 'API App ID'), + 'secretKey' => Craft::t('mjml', 'API Secret Key'), + 'mjmlCliPath' => Craft::t('mjml', 'MJML Cli Path'), + 'nodePath' => Craft::t('mjml', 'Node.js Path'), + 'mjmlCliConfigArgs' => Craft::t('mjml', 'MJML Cli Config Arguments'), ]; } } diff --git a/src/services/MJMLService.php b/src/services/MJMLService.php index 32beeca..1edff75 100644 --- a/src/services/MJMLService.php +++ b/src/services/MJMLService.php @@ -12,6 +12,7 @@ use Craft; use craft\base\Component; +use craft\helpers\App; use craft\helpers\FileHelper; use craft\helpers\Json; use craft\web\View; @@ -21,6 +22,8 @@ use superbig\mjml\exceptions\MJMLException; use superbig\mjml\MJML; use superbig\mjml\models\MJMLModel; +use yii\base\ErrorException; +use yii\base\Exception; /** * @author Superbig @@ -29,21 +32,13 @@ */ class MJMLService extends Component { - // Public Methods - // ========================================================================= - - /** - * @param $html - * - * @return null|MJMLModel - */ - public function parse($html) + public function parse(string $html): ?MJMLModel { $settings = MJML::$plugin->getSettings(); $hash = md5($html); $client = new Client([ 'base_uri' => 'https://api.mjml.io/v1/', - 'auth' => [$settings->appId, $settings->secretKey], + 'auth' => [App::parseEnv($settings->appId), App::parseEnv($settings->secretKey)], ]); try { @@ -57,7 +52,7 @@ public function parse($html) return Json::decodeIfJson((string)$request->getBody()); }); - return new MJMLModel([ + return MJMLModel::create([ 'html' => $response['html'], 'mjml' => $response['mjml'], ]); @@ -84,7 +79,13 @@ public function include(string $template = '', $variables = [], $renderMethod = } $html = file_get_contents($templatePath); + + if (empty($html)) { + throw new MJMLException('Could not render template ' . $template . ' : The template was empty'); + } + $hash = md5($html); + /** @var MJMLModel|null $output */ $output = Craft::$app->getCache()->getOrSet("mjml-{$hash}-{$renderMethod}", function() use ($html, $renderMethod) { return $renderMethod === 'cli' ? $this->parseCli($html) : $this->parse($html); @@ -101,21 +102,25 @@ public function include(string $template = '', $variables = [], $renderMethod = } /** - * @param null $html + * @param string|null $html * * @return MJMLModel|null - * @throws \yii\base\ErrorException + * @throws ErrorException + * @throws Exception */ - public function parseCli($html = null) + public function parseCli(?string $html = null): ?MJMLModel { $settings = MJML::$plugin->getSettings(); - $configArgs = "{$settings->mjmlCliConfigArgs}"; + $configArgs = App::parseEnv($settings->mjmlCliConfigArgs); - if (!empty($settings->mjmlCliIncludesPath)) { - $configArgs = "{$configArgs} --config.filePath {$settings->mjmlCliIncludesPath}"; + $mjmlCliIncludesPath = App::parseEnv($settings->mjmlCliIncludesPath); + if (!empty($mjmlCliIncludesPath)) { + $configArgs = "{$configArgs} --config.filePath {$mjmlCliIncludesPath}"; } - $mjmlPath = "{$settings->nodePath} {$settings->mjmlCliPath}"; + $nodePath = App::parseEnv($settings->nodePath); + $mjmlCliPath = App::parseEnv($settings->mjmlCliPath); + $mjmlPath = "{$nodePath} {$mjmlCliPath}"; $hash = md5($html); $tempPath = Craft::$app->getPath()->getTempPath() . "/mjml/mjml-{$hash}.html"; $tempOutputPath = Craft::$app->getPath()->getTempPath() . "/mjml/mjml-output-{$hash}.html"; @@ -146,7 +151,7 @@ public function parseCli($html = null) return null; } - return new MJMLModel([ + return MJMLModel::create([ 'html' => $output, 'mjml' => $html, ]); diff --git a/src/templates/settings.twig b/src/templates/settings.twig index 69fc0f3..024e9a6 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -17,44 +17,59 @@

MJML API

-{{ forms.textField({ +{{ forms.autosuggestField({ label: 'API App ID', instructions: 'Enter the app id received by email', id: 'appId', name: 'appId', - value: settings['appId']}) + value: settings['appId'] ?? null, + suggestEnvVars: true, + errors: settings.getErrors('appId'), +}) }} -{{ forms.textField({ +{{ forms.autosuggestField({ label: 'API Secret Key', instructions: 'Enter the secret key received by email', id: 'secretKey', name: 'secretKey', - value: settings['secretKey']}) + value: settings['secretKey'] ?? null, + suggestEnvVars: true, + errors: settings.getErrors('secretKey'), +}) }}

MJML local CLI

-{{ forms.textField({ - label: 'Node path', - instructions: 'Enter the path to where the your version of Node is located, i.e. `/usr/local/bin/node`', +{{ forms.autosuggestField({ + label: 'Node.js Path', + instructions: 'Enter the path to where the your version of Node.js is located, i.e. `/usr/local/bin/node`', id: 'nodePath', name: 'nodePath', - value: settings['nodePath']}) + suggestEnvVars: true, + errors: settings.getErrors('nodePath'), + value: settings.nodePath, +}) }} -{{ forms.textField({ - label: 'MJML cli path', - instructions: 'Enter the path to where the MJML cli installed with npm is located, i.e. `/usr/local/bin/mjml`', +{{ forms.autosuggestField({ + label: 'MJML CLI PAth', + instructions: 'Enter the path to where the MJML CLI installed with npm is located, i.e. `/usr/local/bin/mjml`', id: 'mjmlCliPath', name: 'mjmlCliPath', - value: settings['mjmlCliPath']}) + suggestEnvVars: true, + errors: settings.getErrors('mjmlCliPath'), + value: settings.mjmlCliPath, +}) }} -{{ forms.textField({ - label: 'MJML cli config args', - instructions: 'Enter the (optional) cli config args, e.g. `--config.minify true`', +{{ forms.autosuggestField({ + label: 'MJML CLI Config Arguments', + instructions: 'Enter the (optional) MJML CLI config arguments, e.g. `--config.minify true`', id: 'mjmlCliConfigArgs', name: 'mjmlCliConfigArgs', - value: settings['mjmlCliConfigArgs']}) + suggestEnvVars: true, + errors: settings.getErrors('mjmlCliConfigArgs'), + value: settings['mjmlCliConfigArgs'] ?? null, +}) }} diff --git a/src/twigextensions/MJMLTwigExtension.php b/src/twigextensions/MJMLTwigExtension.php index 0858ab1..8f400a6 100644 --- a/src/twigextensions/MJMLTwigExtension.php +++ b/src/twigextensions/MJMLTwigExtension.php @@ -13,6 +13,8 @@ use superbig\mjml\MJML; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; +use yii\base\ErrorException; +use yii\base\Exception; /** * @author Superbig @@ -40,7 +42,7 @@ public function getFunctions(): array ]; } - public function mjml($html = null): ?string + public function mjml($html = null): ?\Twig\Markup { $result = MJML::$plugin->mjmlService->parse($html); @@ -51,7 +53,11 @@ public function mjml($html = null): ?string return $result->output(); } - public function mjmlCli($html = null): ?string + /** + * @throws ErrorException + * @throws Exception + */ + public function mjmlCli($html = null): ?\Twig\Markup { $result = MJML::$plugin->mjmlService->parseCli($html); diff --git a/src/variables/MJMLVariable.php b/src/variables/MJMLVariable.php index e12f860..4756cd2 100644 --- a/src/variables/MJMLVariable.php +++ b/src/variables/MJMLVariable.php @@ -14,6 +14,7 @@ use superbig\mjml\MJML; use superbig\mjml\models\MJMLModel; +use yii\base\Exception; /** * @author Superbig @@ -33,12 +34,13 @@ public function include(string $template = '', $variables = null, $renderMethod } /** - * @param null $html + * @param string|null $html * * @return MJMLModel|null * @throws \yii\base\ErrorException + * @throws Exception */ - public function parseCli($html = null) + public function parseCli($html = null): ?MJMLModel { return MJML::$plugin->mjmlService->parseCli($html); } From d487f46029e3be6fd5636f81128b2a6a6d0ed63c Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Sun, 26 May 2024 13:04:24 +0200 Subject: [PATCH 5/5] 2.0.1 Signed-off-by: Fred Carlsen --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79b834e..45bde52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 2.0.1 - 2024-05-26 +### Fixed +- Fixed issues with saving settings + ## 2.0.0 ### Added - Initial Craft CMS 4 release diff --git a/composer.json b/composer.json index 3c2025f..008d887 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "superbig/craft-mjml", "description": "Render Twig emails with MJML, the only framework that makes responsive email easy.", "type": "craft-plugin", - "version": "2.0.0", + "version": "2.0.1", "keywords": [ "craft", "cms",