diff --git a/mjml/core/api.py b/mjml/core/api.py index a8e65ab..41182f9 100644 --- a/mjml/core/api.py +++ b/mjml/core/api.py @@ -1,5 +1,7 @@ -from ..lib import AttrDict, merge_dicts +from dotmap import DotMap + +from ..lib import merge_dicts from .registry import components @@ -30,7 +32,7 @@ def __init__(self, *, attributes=None, children=(), content='', context=None, self.context = context self.tagName = tagName - self.props = AttrDict(merge_dicts(props, {'children': children, 'content': content})) + self.props = DotMap(merge_dicts(props, {'children': children, 'content': content})) # upstream also checks "self.allowed_attrs" self.attrs = merge_dicts( diff --git a/mjml/elements/_base.py b/mjml/elements/_base.py index e636dd0..c00aac7 100644 --- a/mjml/elements/_base.py +++ b/mjml/elements/_base.py @@ -1,9 +1,11 @@ +from dotmap import DotMap + from ..core import Component, initComponent from ..core.registry import components from ..helpers import * -from ..lib import AttrDict, merge_dicts +from ..lib import merge_dicts __all__ = [ @@ -39,7 +41,7 @@ def getBoxWidths(self): paddings = get_padding('right') + get_padding('left') borders = self.getShorthandBorderValue('right') + self.getShorthandBorderValue('left') - return AttrDict({ + return DotMap({ 'totalWidth': parsedWidth, 'borders' : borders, 'paddings' : paddings, diff --git a/mjml/elements/mj_section.py b/mjml/elements/mj_section.py index 7212e65..03473d8 100644 --- a/mjml/elements/mj_section.py +++ b/mjml/elements/mj_section.py @@ -3,8 +3,10 @@ from collections import namedtuple from decimal import Decimal +from dotmap import DotMap + from ..helpers import parse_percentage, strip_unit, suffixCssClasses -from ..lib import AttrDict, merge_dicts +from ..lib import merge_dicts from ._base import BodyComponent @@ -188,7 +190,7 @@ def renderSimple(self): def getBackgroundPosition(self): pos = self.parseBackgroundPosition() - return AttrDict({ + return DotMap({ 'posX': self.getAttribute('background-position-x') or pos.x, 'posY': self.getAttribute('background-position-y') or pos.y, }) diff --git a/mjml/lib/__init__.py b/mjml/lib/__init__.py index aad7725..209aa4c 100644 --- a/mjml/lib/__init__.py +++ b/mjml/lib/__init__.py @@ -1,3 +1,2 @@ -from .attribute_dict import * from .dict_merger import * diff --git a/mjml/lib/attribute_dict.py b/mjml/lib/attribute_dict.py deleted file mode 100644 index f15d96b..0000000 --- a/mjml/lib/attribute_dict.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: UTF-8 -*- - -# License: Public Domain -# Authors: Felix Schwarz -# -# Version 1.2 -# -# 1.2 (2018-02-16) -# - split tests into separate file -# - add ".copy()" method -# -# 1.1 (08.09.2015) -# - set items via attributes -# -# 1.0 (06.02.2010) -# - initial release - - -__all__ = ['AttrDict'] - -class AttrDict(dict): - def copy(self): - return AttrDict(self) - - def __getattr__(self, name): - if name not in self: - class_name = self.__class__.__name__ - raise AttributeError("'%s' object has no attribute '%s'" % (class_name, name)) - return self[name] - - def __setattr__(self, name, value): - if name not in self: - class_name = self.__class__.__name__ - raise AttributeError("'%s' object has no attribute '%s'" % (class_name, name)) - self[name] = value diff --git a/mjml/mjml2html.py b/mjml/mjml2html.py index 437b75e..8c542b6 100644 --- a/mjml/mjml2html.py +++ b/mjml/mjml2html.py @@ -3,11 +3,12 @@ from typing import List, Optional from bs4 import BeautifulSoup +from dotmap import DotMap from .core import initComponent from .core.registry import register_components, register_core_components from .helpers import json_to_xml, mergeOutlookConditionnals, omit, skeleton_str as default_skeleton -from .lib import AttrDict, merge_dicts +from .lib import merge_dicts def ignore_empty(values): @@ -52,7 +53,7 @@ def mjml_to_html(xml_fp_or_json, skeleton=None, template_dir=None, } # LATER: ability to override fonts via **options - globalDatas = AttrDict({ + globalDatas = DotMap({ 'backgroundColor' : None, 'breakpoint' : '480px', 'classes' : {}, @@ -173,7 +174,7 @@ def addComponentHeadSyle(headStyle): def setBackgroundColor(color): globalDatas.backgroundColor = color - bodyHelpers = AttrDict( + bodyHelpers = DotMap( addHeadStyle = addHeadStyle, addMediaQuery = addMediaQuery, addComponentHeadSyle = addComponentHeadSyle, @@ -199,7 +200,7 @@ def _head_data_add(attr, *params): assert len(param_values) == 1, 'shortcut in implementation' current_attr_value[param_key] = param_values[0] - headHelpers = AttrDict( + headHelpers = DotMap( add = _head_data_add, ) globalDatas.headRaw = processing(mjHead, headHelpers) @@ -241,7 +242,7 @@ def _head_data_add(attr, *params): content = mergeOutlookConditionnals(content) - return AttrDict({ + return DotMap({ 'html': content, 'errors': errors, }) diff --git a/setup.cfg b/setup.cfg index e77a6bd..e8c847b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,9 +40,10 @@ zip_safe = true include_package_data = true install_requires = - beautifulsoup4 - docopt - jinja2 + beautifulsoup4 + dotmap + docopt + jinja2 scripts = mjml/scripts/mjml-html-compare