@@ -1779,6 +1779,10 @@ class CSSToExcelConverter(object):
1779
1779
CSS declarations understood to be the containing scope for the
1780
1780
CSS processed by :meth:`__call__`.
1781
1781
"""
1782
+ # NB: Most of the methods here could be classmethods, as only __init__
1783
+ # and __call__ make use of instance attributes. We leave them as
1784
+ # instancemethods so that users can easily experiment with extensions
1785
+ # without monkey-patching.
1782
1786
1783
1787
def __init__ (self , inherited = None ):
1784
1788
if inherited is not None :
@@ -1799,7 +1803,7 @@ def __call__(self, declarations_str):
1799
1803
e.g. "font-weight: bold; background: blue"
1800
1804
"""
1801
1805
# TODO: memoize?
1802
- properties = self .compute_css (declarations_str )
1806
+ properties = self .compute_css (declarations_str , self . inherited )
1803
1807
return self .build_xlstyle (properties )
1804
1808
1805
1809
def build_xlstyle (self , props ):
@@ -2000,9 +2004,8 @@ def font_size_to_pt(self, val, em_pt=None):
2000
2004
val *= mul
2001
2005
return val
2002
2006
2003
- @classmethod
2004
- def compute_css (cls , declarations_str , inherited = None ):
2005
- props = dict (cls .atomize (cls .parse (declarations_str )))
2007
+ def compute_css (self , declarations_str , inherited = None ):
2008
+ props = dict (self .atomize (self .parse (declarations_str )))
2006
2009
if inherited is None :
2007
2010
inherited = {}
2008
2011
@@ -2032,12 +2035,11 @@ def compute_css(cls, declarations_str, inherited=None):
2032
2035
# 4. TODO: resolve other relative styles (e.g. ?)
2033
2036
return props
2034
2037
2035
- @classmethod
2036
- def atomize (cls , declarations ):
2038
+ def atomize (self , declarations ):
2037
2039
for prop , value in declarations :
2038
2040
attr = 'expand_' + prop .replace ('-' , '_' )
2039
2041
try :
2040
- expand = getattr (cls , attr )
2042
+ expand = getattr (self , attr )
2041
2043
except AttributeError :
2042
2044
yield prop , value
2043
2045
else :
@@ -2053,16 +2055,15 @@ def atomize(cls, declarations):
2053
2055
DIRECTIONS = ('top' , 'right' , 'bottom' , 'left' )
2054
2056
2055
2057
def _direction_expander (prop_fmt ):
2056
- @classmethod
2057
- def expand (cls , prop , value ):
2058
+ def expand (self , prop , value ):
2058
2059
tokens = value .split ()
2059
2060
try :
2060
- mapping = cls .DIRECTION_SHORTHANDS [len (tokens )]
2061
+ mapping = self .DIRECTION_SHORTHANDS [len (tokens )]
2061
2062
except KeyError :
2062
2063
warnings .warn ('Could not expand "%s: %s"' % (prop , value ),
2063
2064
CSSParseWarning )
2064
2065
return
2065
- for key , idx in zip (cls .DIRECTIONS , mapping ):
2066
+ for key , idx in zip (self .DIRECTIONS , mapping ):
2066
2067
yield prop_fmt % key , tokens [idx ]
2067
2068
2068
2069
return expand
@@ -2073,8 +2074,7 @@ def expand(cls, prop, value):
2073
2074
expand_margin = _direction_expander ('margin-%s' )
2074
2075
expand_padding = _direction_expander ('padding-%s' )
2075
2076
2076
- @classmethod
2077
- def parse (cls , declarations_str ):
2077
+ def parse (self , declarations_str ):
2078
2078
"""Generates (prop, value) pairs from declarations
2079
2079
2080
2080
In a future version may generate parsed tokens from tinycss/tinycss2
0 commit comments