from Translator import *
import Object, ValueList
class SSSConstantRule(Object.SSSObject):
def __init__(self, rule = ''):
self._name = '' #I moved these to make them instance variables,
self._valueList = None #rather than class variables
super(SSSConstantRule, self).__init__()
if (rule):
self._parse(rule)
def _parse(self, sourceText):
sourceText = sourceText.strip()
#matches = preg_match(r'@constant', sourceText)
if '@constant' in sourceText:
#this pretty little mess of code is custom hacked
#because the previous re wasn't working...
self._name = sourceText[sourceText.find('@constant '):sourceText.find(':')].replace('@constant', '').strip()
self._valueList = ValueList.SSSValueList(sourceText[sourceText.find(':')+1:sourceText.find(';')].strip(), self)
self._declareConstant()
def _declareConstant(self):
if (self.parentStyleSheet):
self.parentStyleSheet.declareConstant(self._name, self.value)
def get_value(self):
return self._valueList.cssText
value = property(get_value)
def get_cssText(self):
return self.__str__()
cssText = property(get_cssText, _parse)
def get_type(self):
return Object.SSSObject.CONSTANT_RULE
type = property(get_type)
def __str__(self):
string = "constant " + self._name + ": " + self._valueList.cssText
if (self.parentStyleSheet):
return self.parentStyleSheet.createCommentText(string) + "\n\n"
return string