Skip to content

Commit

Permalink
Keyword argument for custom constant mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Oct 26, 2016
1 parent 1c34162 commit 12f429e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions components/style/properties/data.py
Expand Up @@ -18,7 +18,7 @@ def to_camel_case(ident):

class Keyword(object):
def __init__(self, name, values, gecko_constant_prefix=None,
gecko_enum_prefix=None,
gecko_enum_prefix=None, custom_consts=None,
extra_gecko_values=None, extra_servo_values=None):
self.name = name
self.values = values.split()
Expand All @@ -29,6 +29,7 @@ def __init__(self, name, values, gecko_constant_prefix=None,
self.gecko_enum_prefix = gecko_enum_prefix
self.extra_gecko_values = (extra_gecko_values or "").split()
self.extra_servo_values = (extra_servo_values or "").split()
self.consts_map = {} if custom_consts is None else custom_consts

def gecko_values(self):
return self.values + self.extra_gecko_values
Expand All @@ -45,12 +46,15 @@ def values_for(self, product):
raise Exception("Bad product: " + product)

def gecko_constant(self, value):
moz_stripped = value.replace("-moz-", '')
parts = moz_stripped.split('-')
if self.gecko_enum_prefix:
parts = value.replace("-moz-", "").split("-")
parts = [p.title() for p in parts]
return self.gecko_enum_prefix + "::" + "".join(parts)
else:
return self.gecko_constant_prefix + "_" + value.replace("-moz-", "").replace("-", "_").upper()
mapped = self.consts_map.get(value)
suffix = mapped if mapped else moz_stripped.replace("-", "_")
return self.gecko_constant_prefix + "_" + suffix.upper()

def needs_cast(self):
return self.gecko_enum_prefix is None
Expand Down
1 change: 1 addition & 0 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -312,6 +312,7 @@
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
'gecko_constant_prefix', 'gecko_enum_prefix',
'extra_gecko_values', 'extra_servo_values',
'custom_consts',
]}
%>

Expand Down

0 comments on commit 12f429e

Please sign in to comment.