Esempio n. 1
0
def load_html(name, secondName, lastName, secondLastName, addressCity,
              document, documentCity, dia, mes, ano, hora, requerimiento,
              visibility, contrato, entityName, entityDocument,
              chambersCommerce):
    # Si el requerimiento es 1 sólo pinta los datos en html
    if requerimiento == 1:
        loader = moody.make_loader('static')
        html = loader.render(contrato,
                             name=name,
                             secondName=secondName,
                             lastName=lastName,
                             secondLastName=secondLastName,
                             addressCity=addressCity,
                             document=document,
                             documentCity=documentCity,
                             dia=dia,
                             mes=mes,
                             ano=ano,
                             hora=hora,
                             visibility=visibility,
                             entityName=entityName,
                             entityDocument=entityDocument,
                             chambersCommerce=chambersCommerce)
        return html

# Si el requerimiento es 2  llama a send_file para convertir el html a pdf con los datos rendereizados
    elif requerimiento == 2:
        loader = moody.make_loader('static')
        html = loader.render(contrato,
                             name=name,
                             secondName=secondName,
                             lastName=lastName,
                             secondLastName=secondLastName,
                             addressCity=addressCity,
                             document=document,
                             documentCity=documentCity,
                             dia=dia,
                             mes=mes,
                             ano=ano,
                             hora=hora,
                             visibility=visibility,
                             entityName=entityName,
                             entityDocument=entityDocument,
                             chambersCommerce=chambersCommerce)
        toPdf = send_file(html)
        return "Se envió html exitosamente..."
Esempio n. 2
0
    def render(self, javaPackage=None):
        templates_dir = resource_filename(__name__, "templates")
        loader = moody.make_loader(templates_dir)

        code = loader.render(self.template, package=javaPackage)

        linereduce = re.compile("^[ \t]*$", re.M)
        code = linereduce.sub("", code)
        code = re.sub("\n+", "\n", code)
        return code
Esempio n. 3
0
    def render(self, javaPackage=None):
        templates_dir = resource_filename(__name__, 'templates')
        loader = moody.make_loader(templates_dir)

        code = loader.render(self.template, package=javaPackage)

        linereduce = re.compile('^[ \t]*$', re.M)
        code = linereduce.sub('', code)
        code = re.sub('\n+', '\n', code)
        return code
Esempio n. 4
0
def main():
    print("Running benchmarks for moody-templates...")
    template_root = os.path.join(os.path.dirname(__file__), "templates")
    def benchmark(func):
        return min(timeit.repeat(func, repeat=3, number=1000))
    # Test the cached rendering.
    loader = moody.make_loader(template_root)
    def render_cached():
        loader.render("index.html", list_items = list(range(100)))
    render_cached()
    print("Cached rendering:   {time}".format(time=benchmark(render_cached)))
    # Test the uncached rendering.
    def render_uncached():
        loader._cache.clear()
        loader.render("index.html", list_items = list(range(100)))
    print("Uncached rendering: {time}".format(time=benchmark(render_uncached)))
Esempio n. 5
0
    def render(self, javaPackage=None):
        templates_dir = resource_filename(__name__, "templates")
        loader = moody.make_loader(templates_dir)
        self._prepare(self.grammar)
        LL1Nonterminals = [
            x for x in self.grammar.nonterminals if x not in map(lambda x: x.nonterminal, self.grammar.exprgrammars)
        ]

        code = loader.render(
            self.template,
            grammar=self.grammar,
            LL1Nonterminals=LL1Nonterminals,
            nonAbstractTerminals=self.grammar.getSimpleTerminals(),
            prefix=self.getPrefix(),
            package=javaPackage,
        )

        linereduce = re.compile("^[ \t]*$", re.M)
        code = linereduce.sub("", code)
        code = re.sub("\n+", "\n", code)
        return code
Esempio n. 6
0
    def render(self, javaPackage=None):
        templates_dir = resource_filename(__name__, 'templates')
        loader = moody.make_loader(templates_dir)
        self._prepare(self.grammar)
        LL1Nonterminals = [
            x for x in self.grammar.nonterminals
            if x not in map(lambda x: x.nonterminal, self.grammar.exprgrammars)
        ]

        code = loader.render(
            self.template,
            grammar=self.grammar,
            LL1Nonterminals=LL1Nonterminals,
            nonAbstractTerminals=self.grammar.getSimpleTerminals(),
            prefix=self.getPrefix(),
            package=javaPackage)

        linereduce = re.compile('^[ \t]*$', re.M)
        code = linereduce.sub('', code)
        code = re.sub('\n+', '\n', code)
        return code
 def testLoad(self):
     loader = moody.make_loader(*sys.path)
     with open(moody.__file__, "r") as expected:
         self.assertEqual(loader.render("moody/__init__.py"),
                          expected.read())
test_loader = moody.make_loader(
    MemorySource({
        "simple.html":
        "{{test}}",
        "include.txt":
        "{% include 'simple.txt' %}",
        "parent.txt":
        "Hello {% block name %}world{% endblock %}",
        "child.txt":
        "{% extends 'parent.txt' %}{% block name %}Dave {% block surname %}Hall{% endblock %}{% endblock %}",
        "grandchild.txt":
        "{% extends 'child.txt' %}{% block surname %}Foo{% endblock surname %}",
        "override.txt":
        "Bar",
        "inherit.txt":
        "{% extends __super__ %}{% block surname %}Foo{% endblock %}",
        "scoped_meta_parent.txt":
        "{% block name %}{{__name__}}{% endblock %}",
        "scoped_meta_child.txt":
        "{% extends 'scoped_meta_parent.txt' %}{% block name %}{% super %} {{__name__}}{% endblock %}",
        "scoped_meta_grandchild.txt":
        "{% extends 'scoped_meta_child.txt' %}{% block name %}{% super %} {{__name__}}{% endblock %}",
        "super_block_parent.txt":
        "{% block name %}Dave{% endblock %}",
        "super_block_child.txt":
        "{% extends 'super_block_parent.txt' %}{% block name %}{% super %} Hall{% endblock %}",
        "super_block_grandchild.txt":
        "{% extends 'super_block_child.txt' %}{% block name %}{% super %} the great{% endblock %}",
    }),
    MemorySource({
        "simple.txt":
        "{{test}}",
        "overide.txt":
        "Foo",
        "inherit.txt":
        "{% extends __super__ %}{% block name %}Dave {% block surname %}Hall{% endblock %}{% endblock %}",
    }),
    MemorySource({
        "inherit.txt": "Hello {% block name %}world{% endblock %}",
    }))
Esempio n. 9
0
 def testLoad(self):
     loader = moody.make_loader(*sys.path)
     with open(moody.__file__, "r") as expected:
         self.assertEqual(loader.render("moody/__init__.py"), expected.read())
Esempio n. 10
0
        self.assertEqual(template1.render(), "foo")
        self.assertEqual(template1.render(test="bar"), "bar")


test_loader = moody.make_loader(
    MemorySource({
        "simple.html": "{{test}}",
        "include.txt": "{% include 'simple.txt' %}",
        "parent.txt": "Hello {% block name %}world{% endblock %}",
        "child.txt": "{% extends 'parent.txt' %}{% block name %}Dave {% block surname %}Hall{% endblock %}{% endblock %}",
        "grandchild.txt": "{% extends 'child.txt' %}{% block surname %}Foo{% endblock surname %}",
        "override.txt": "Bar",
        "inherit.txt": "{% extends __super__ %}{% block surname %}Foo{% endblock %}",
        "scoped_meta_parent.txt": "{% block name %}{{__name__}}{% endblock %}",
        "scoped_meta_child.txt": "{% extends 'scoped_meta_parent.txt' %}{% block name %}{% super %} {{__name__}}{% endblock %}",
        "scoped_meta_grandchild.txt": "{% extends 'scoped_meta_child.txt' %}{% block name %}{% super %} {{__name__}}{% endblock %}",
        "super_block_parent.txt": "{% block name %}Dave{% endblock %}",
        "super_block_child.txt": "{% extends 'super_block_parent.txt' %}{% block name %}{% super %} Hall{% endblock %}",
        "super_block_grandchild.txt": "{% extends 'super_block_child.txt' %}{% block name %}{% super %} the great{% endblock %}",
    }), MemorySource({
        "simple.txt": "{{test}}",
        "overide.txt": "Foo",
        "inherit.txt": "{% extends __super__ %}{% block name %}Dave {% block surname %}Hall{% endblock %}{% endblock %}",
    }), MemorySource({
        "inherit.txt": "Hello {% block name %}world{% endblock %}",
    })
)


class TestLoader(unittest.TestCase):