コード例 #1
0
ファイル: language.py プロジェクト: JsonChiu/publicservice
    def _add_define(self, variable, expression):
        name = utils.py_attr('with')
        define = "%s=%s; " % (variable, expression)

        if name in self.attrib:
            self.attrib[name] += define
        else:
            self.attrib[name] = define
コード例 #2
0
ファイル: language.py プロジェクト: JsonChiu/publicservice
    def update(self):
        # Step 1: Convert py:choose, py:when, py:otherwise into
        # tal:define, tal:condition
        stream = self.stream
        choose_expression = self._pull_attribute(utils.py_attr('choose'))
        if choose_expression is not None:
            choose_variable = stream.new_var()
            
            if choose_expression:
                self._add_define(choose_variable, choose_expression)
                
            # select all elements that have the "py:when" controller,
            # unless a "py:choose" expression sits in-between
            elements = get_elements_with_attribute_unless_in_between(
                self, config.PY_NS, "when", "choose")

            variables = []
            for element in elements:
                expression = element._pull_attribute(utils.py_attr('when'))
                variable = stream.new_var()
                variables.append(variable)

                # add definition to ancestor
                self._add_define(variable, expression)

                # add condition to element
                if choose_expression:
                    expression = "%s == %s" % (
                        choose_variable, variable)
                else:
                    expression = "%s" % variable

                element.attrib[utils.py_attr('if')] = expression

            # process any "py:otherwise"-controllers
            elements = get_elements_with_attribute_unless_in_between(
                self, config.PY_NS, "otherwise", "choose")

            for element in elements:
                if choose_expression:
                    expression = "%s not in %s" % (
                        choose_variable, repr(tuple(variables)))
                else:
                    expression = "not(%s)" % " or ".join(variables)

                element.attrib[utils.py_attr('if')] = expression
コード例 #3
0
    def _add_define(self, variable, expression):
        name = utils.py_attr('with')
        define = "%s=%s; " % (variable, expression)

        if name in self.attrib:
            self.attrib[name] += define
        else:
            self.attrib[name] = define
コード例 #4
0
    def update(self):
        # Step 1: Convert py:choose, py:when, py:otherwise into
        # tal:define, tal:condition
        stream = self.stream
        choose_expression = self._pull_attribute(utils.py_attr('choose'))
        if choose_expression is not None:
            choose_variable = stream.new_var()

            if choose_expression:
                self._add_define(choose_variable, choose_expression)

            # select all elements that have the "py:when" controller,
            # unless a "py:choose" expression sits in-between
            elements = get_elements_with_attribute_unless_in_between(
                self, config.PY_NS, "when", "choose")

            variables = []
            for element in elements:
                expression = element._pull_attribute(utils.py_attr('when'))
                variable = stream.new_var()
                variables.append(variable)

                # add definition to ancestor
                self._add_define(variable, expression)

                # add condition to element
                if choose_expression:
                    expression = "%s == %s" % (choose_variable, variable)
                else:
                    expression = "%s" % variable

                element.attrib[utils.py_attr('if')] = expression

            # process any "py:otherwise"-controllers
            elements = get_elements_with_attribute_unless_in_between(
                self, config.PY_NS, "otherwise", "choose")

            for element in elements:
                if choose_expression:
                    expression = "%s not in %s" % (choose_variable,
                                                   repr(tuple(variables)))
                else:
                    expression = "not(%s)" % " or ".join(variables)

                element.attrib[utils.py_attr('if')] = expression
コード例 #5
0
class XHTMLElement(GenshiElement):
    """XHTML namespace element."""

    py_if = utils.attribute(utils.py_attr('if'), lambda p: p.expression)
    py_for = utils.attribute(utils.py_attr('for'), lambda p: p.definition)
    py_with = utils.attribute(utils.py_attr('with'),
                              lambda p: expressions.translator.definitions)
    py_choose = utils.attribute(utils.py_attr('choose'),
                                lambda p: p.expression)
    py_when = utils.attribute(utils.py_attr('when'), lambda p: p.expression)
    py_otherwise = utils.attribute(utils.py_attr('otherwise'),
                                   lambda p: p.expression)
    py_match = utils.attribute(utils.py_attr('match'))
    py_once = utils.attribute(utils.py_attr('once'), default='false')
    py_def = utils.attribute(utils.py_attr('def'), lambda p: p.method)
    py_attrs = utils.attribute(utils.py_attr('attrs'), lambda p: p.expression)
    py_content = utils.attribute(utils.py_attr('content'), lambda p: p.output)
    py_replace = utils.attribute(utils.py_attr('replace'), lambda p: p.output)
    py_strip = utils.attribute(utils.py_attr('strip'), lambda p: p.expression)
    meta_translator = etree.Annotation(utils.meta_attr('translator'))
    meta_interpolation = utils.attribute(utils.meta_attr('interpolation'),
                                         default='true',
                                         recursive=True)
    meta_interpolation_escaping = utils.attribute(
        utils.meta_attr('interpolation-escaping'),
        default='true',
        recursive=True)
    i18n_translate = utils.attribute(utils.i18n_attr('translate'))
    i18n_attributes = utils.attribute(utils.i18n_attr('attributes'),
                                      lambda p: p.mapping)
    i18n_domain = utils.attribute(utils.i18n_attr('domain'))
    i18n_name = utils.attribute(utils.i18n_attr('name'))