Esempio n. 1
0
    def render(self, references={}, extendwith={}):
        """Generate a data dict from this template and any it references.

        :param references: this is a dict of string to template mappings.

        This is used to resolve references to other templates. If this is empty
        self.references will be used instead.


        :param extendwith: This is the template to render and then add to this one.

        This will use the rendered dict's update(). This template will overwrite
        any common keys in the rendered extendwith.


        :returns: This returns a 'rendered' dict.

        All references  will have been replaced with the value the point at.

        """
        return utils.render(
            self.content.items(),
            int_refs=self.references,
            ext_refs=references,
            extendwith=extendwith,
        )
Esempio n. 2
0
    def render(self, references={}, extendwith={}):
        """Generate a data dict from this template and any it references.

        :param references: this is a dict of string to template mappings.

        This is used to resolve references to other templates. If this is empty
        self.references will be used instead.


        :param extendwith: This is the template to render and then add to this one.

        This will use the rendered dict's update(). This template will overwrite
        any common keys in the rendered extendwith.


        :returns: This returns a 'rendered' dict.

        All references  will have been replaced with the value the point at.

        """
        return utils.render(
            self.content.items(),
            int_refs=self.references,
            ext_refs=references,
            extendwith=extendwith,
        )
    def testRender(self):
        """Test the utils module render which is used by the Template class.
        """
        common = dict(keep='yes', buffer=4096)

        test1 = Template(
            'test1',
            dict(keep='yes', buffer='data.$.buffer', hostname='bob'),
            references={
                'data':common,
            }
        )

        test2 = Template(
            'test2',
            dict(buffer='test1.$.buffer', hostname='bob', keep='common.$.keep'),
            references={
                'test1':test1,
            }
        )

        # 'Render' test2 into a dict using the internal utils function:
        result = utils.render(
            test2.content.items(),
            int_refs=test2.references,
            ext_refs={'common':common}
        )

        correct = dict(
            buffer=4096,
            hostname='bob',
            keep='yes'
        )

        # aid visual debug:
        err_msg = """result != correct
result:
%s

correct:
%s
        """ % (pprint.pformat(result), pprint.pformat(correct))

        self.assertEquals(result, correct, err_msg)
    def testRender(self):
        """Test the utils module render which is used by the Template class.
        """
        common = dict(keep='yes', buffer=4096)

        test1 = Template('test1',
                         dict(keep='yes',
                              buffer='data.$.buffer',
                              hostname='bob'),
                         references={
                             'data': common,
                         })

        test2 = Template('test2',
                         dict(buffer='test1.$.buffer',
                              hostname='bob',
                              keep='common.$.keep'),
                         references={
                             'test1': test1,
                         })

        # 'Render' test2 into a dict using the internal utils function:
        result = utils.render(test2.content.items(),
                              int_refs=test2.references,
                              ext_refs={'common': common})

        correct = dict(buffer=4096, hostname='bob', keep='yes')

        # aid visual debug:
        err_msg = """result != correct
result:
%s

correct:
%s
        """ % (pprint.pformat(result), pprint.pformat(correct))

        self.assertEquals(result, correct, err_msg)