Document MJML theme tokens for GrapesJS Builder#345
Document MJML theme tokens for GrapesJS Builder#345promptless-for-oss wants to merge 11 commits into
Conversation
Document the new grapesjs-mjmlThemeTokens plugin introduced in Mautic 7 that enables theme token support for MJML email templates. Includes: - How to define theme tokens using mj-class in mj-head - Default token mappings for mj-text, mj-button, mj-section - Plugin configuration options for custom integrations - Utility functions (extractMjHeadContent, createHeadInjectingMjmlParser) - Custom event documentation (mjml-theme-tokens:content:ready)
| MJML theme tokens | ||
| ***************** | ||
|
|
||
| From Mautic 7, the GrapesJS Builder supports MJML theme tokens. You can define reusable style classes in the ``<mj-head>`` section of your MJML Email templates using ``<mj-class>`` elements. When users drop new components into the Email Builder, Mautic automatically applies the matching theme tokens, keeping styling consistent across the Email. |
There was a problem hiding this comment.
Added MJML theme tokens section based on the new grapesjs-mjmlThemeTokens plugin introduced in PR #16042. Plugin source at plugins/GrapesJsBuilderBundle/Assets/library/js/plugins/grapesjs-mjmlThemeTokens/index.js.
Source: mautic/mautic#16042
|
|
||
| **Default token mappings** | ||
|
|
||
| The plugin maps component types to default theme tokens: |
There was a problem hiding this comment.
Default token mappings (t-body, t-btn t-btn-primary, t-section t-surface-1) taken from the defaults configuration object in index.js:3-20.
| Utility functions | ||
| ================= | ||
|
|
||
| The plugin exports utility functions that developers can use when building custom integrations. |
There was a problem hiding this comment.
Utility functions extractMjHeadContent and createHeadInjectingMjmlParser documented from plugins/GrapesJsBuilderBundle/Assets/library/js/plugins/grapesjs-mjmlThemeTokens/utils.js.
Source: mautic/mautic#16042
adiati98
left a comment
There was a problem hiding this comment.
@promptless-for-oss please address the suggestions.
Apply reviewer's requested changes: - Wrap headings containing "Theme tokens" in vale off/on - Capitalize Plugin, Component(s), User, Theme tokens per Mautic style
Address review feedback to specify that the JavaScript event listener code should be placed in a custom GrapesJS Plugin, with a reference to the GrapesJS Builder Plugins section below.
|
Thanks for the feedback @escopecz! I've updated the documentation to clarify where to place the event listener code. The "Custom events" section now explains that this JavaScript code belongs inside a custom GrapesJS Plugin, with a cross-reference to the "GrapesJS Builder Plugins" section for guidance on creating plugins. |
patrykgruszka
left a comment
There was a problem hiding this comment.
I would suggest to add only these sections:
- MJML Theme tokens
- Defining Theme tokens
- How the Theme tokens Plugin works
To remove (not useful and I'm not sure if it's correct):
- Utility functions
- Custom events
| **Plugin configuration options** | ||
|
|
||
| Developers creating custom Plugins can configure the Theme tokens behavior: | ||
|
|
||
| .. code-block:: javascript | ||
|
|
||
| { | ||
| // Provide mj-head inner content (preferred) or full original MJML | ||
| headContent: '', | ||
| originalMjml: '', | ||
|
|
||
| // Default token mapping for newly dropped components | ||
| defaults: { | ||
| text: 't-body', | ||
| button: 't-btn t-btn-primary', | ||
| section: 't-section t-surface-1', | ||
| }, | ||
|
|
||
| // Types to auto-apply defaults to | ||
| applyDefaultsToTypes: ['mj-text', 'mj-button', 'mj-section'], | ||
| } |
There was a problem hiding this comment.
This is part of core implementation, not configurable. Lets remove this section.
| **Plugin configuration options** | |
| Developers creating custom Plugins can configure the Theme tokens behavior: | |
| .. code-block:: javascript | |
| { | |
| // Provide mj-head inner content (preferred) or full original MJML | |
| headContent: '', | |
| originalMjml: '', | |
| // Default token mapping for newly dropped components | |
| defaults: { | |
| text: 't-body', | |
| button: 't-btn t-btn-primary', | |
| section: 't-section t-surface-1', | |
| }, | |
| // Types to auto-apply defaults to | |
| applyDefaultsToTypes: ['mj-text', 'mj-button', 'mj-section'], | |
| } |
Remove implementation details that are part of core Mautic code: - Plugin configuration options - Utility functions section - Custom events section Keep only user-relevant sections: MJML Theme tokens overview, Defining Theme tokens, and how the Plugin works at a high level.
|
Thanks for the review feedback @patrykgruszka! I've updated the documentation to address your comments: Removed sections:
Kept sections:
The documentation now focuses only on what developers need to use the feature. Please take another look when you have a chance. |
This section documented internal core implementation details (plugin internals, default token mappings) rather than developer-configurable content. Per reviewer feedback.
|
Thanks for the additional feedback @patrykgruszka! I've removed the "How the Theme tokens Plugin works" section as requested — it was documenting internal core implementation rather than developer-configurable content. The documentation now contains only:
Please let me know if there's anything else that needs adjustment. |
patrykgruszka
left a comment
There was a problem hiding this comment.
Based on the reference guidelines provided, the docs update contains two critical errors in the MJML code block.
Here are the discrepancies:
- Self-closing tags are used: The diff uses self-closing tags (e.g.,
<mj-class name="t-body" ... />). Section 7 of the guidelines explicitly forbids this, stating: "Self-closing syntax (e.g.<mj-class ... />) causes parsing issues. Always use explicit open/close pairs." - Missing
<mj-attributes>tag: In the diff, the<mj-class>elements are placed directly inside<mj-head>. In MJML, they must be wrapped inside an<mj-attributes>block.
Suggested Correction
You need to update the reStructuredText code snippet to fix the MJML structure.
Click to expand the corrected diff snippet
@@ -43,6 +43,74 @@ The GrapesJS Builder doesn't require any special HTML syntax to edit content in
</mj-body>
</mjml>
+.. vale off
+
+MJML Theme tokens
+*****************
+
+.. vale on
+
+From Mautic 7, the GrapesJS Builder supports MJML Theme tokens. You can define reusable style classes in the ``<mj-head>`` section of your MJML Email templates using ``<mj-class>`` elements inside an ``<mj-attributes>`` block. When Users drop new Components into the Email Builder, Mautic automatically applies the matching Theme tokens, keeping styling consistent across the Email.
+
+.. vale off
+
+Defining Theme tokens
+=====================
+
+.. vale on
+
+Define Theme tokens in the ``<mj-head>`` section of your MJML template using ``<mj-class>`` elements wrapped in ``<mj-attributes>``. Each class specifies CSS properties that apply to Components using it. Note that self-closing tags can cause parsing issues; always use explicit open/close pairs.
+
+.. code-block:: html
+
+ <mjml>
+ <mj-head>
+ <mj-attributes>
+ <mj-class name="t-body" color="#333333" font-family="Arial, sans-serif"></mj-class>
+ <mj-class name="t-btn" background-color="#007bff" color="#ffffff"></mj-class>
+ <mj-class name="t-btn-primary" border-radius="4px"></mj-class>
+ <mj-class name="t-section" padding="20px"></mj-class>
+ <mj-class name="t-surface-1" background-color="#f8f9fa"></mj-class>
+ </mj-attributes>
+ </mj-head>
+ <mj-body>
+ <mj-section mj-class="t-section t-surface-1">
+ <mj-column>
+ <mj-text mj-class="t-body">Welcome to our newsletter</mj-text>
+ <mj-button mj-class="t-btn t-btn-primary" href="#">Click here</mj-button>
+ </mj-column>
+ </mj-section>
+ </mj-body>
+ </mjml>
+
+The builder parses these ``<mj-class>`` definitions and applies them to matching component types automatically.
+
+.. vale off
+
+How the Theme tokens Plugin works
+=================================
+
+.. vale on
+
+The ``grapesjs-mjmlThemeTokens`` Plugin provides automatic Theme token handling.
+
+**Default token mappings**
+
+The Plugin maps Component types to default Theme tokens:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Component type
+ - Default token
+ * - ``mj-text``
+ - ``t-body``
+ * - ``mj-button``
+ - ``t-btn t-btn-primary``
+ * - ``mj-section``
+ - ``t-section t-surface-1``
+
+When a User drops a new Component, the Plugin checks if the tokens exist in the template's ``<mj-head>``. If they do, it automatically applies them via the ``mj-class`` attribute.
+
GrapesJS Builder Plugins
************************Summary of changes made to the diff:
- Added the
<mj-attributes>opening and closing tags. - Replaced all
/>self-closing<mj-class>tags with></mj-class>. - Updated the introductory text to specify that
<mj-class>must go inside<mj-attributes>, and added a warning regarding self-closing tags.
Address reviewer feedback: - Wrap mj-class elements inside mj-attributes block - Replace self-closing tags with explicit open/close pairs - Update prose to document required mj-attributes wrapper - Add warning about self-closing syntax causing parsing issues
|
Thanks for catching those MJML syntax errors @patrykgruszka! I've fixed both issues:
Please take another look when you have a chance. |
Open this suggestion in Promptless to view citations and reasoning process
Add documentation for the new MJML theme tokens feature that enables developers to define reusable style classes in email templates using mj-class definitions and automatic token application to new components.
Trigger Events
Tip: Adjust how proactive or focused Promptless is in Agent Settings ⚙️