コード例 #1
0
ファイル: pad.py プロジェクト: JamesLinus/crypsr_client
 def bootstrap(self, template, jslibs, css, **kwargs):
     """
         Bootstraps an application template. Returns a cubictemp Template
         instance.
     """
     kwargs["css"] = css
     kwargs["jslibs"] = jslibs
     bootstrap = cubictemp.Template(template)
     bootstrap = unicode(bootstrap(**kwargs))
     return cubictemp.Template(unicode(bootstrap))
コード例 #2
0
    def test_unicode(self):
        s = unicode(cubictemp.Template(u"\ue2e2foo"))
        assert s == u"\ue2e2foo"

        s = cubictemp.Template("@!foo!@")
        assert unicode(s(foo=u"\ue2e2"))

        s = cubictemp.Template(u"""
                <!--(for i in uc)-->
                    @!i!@
                <!--(end)-->
            """)
        assert unicode(s(uc=[u"\ue2e2"]))
コード例 #3
0
 def test_complexIterable(self):
     s = """
         <!--(for i in [1, 2, 3, "flibble", range(10)])-->
             @!i!@
         <!--(end)-->
     """
     s = unicode(cubictemp.Template(s))
     assert "[0, 1, 2, 3, 4" in s
コード例 #4
0
 def test_blockspacing(self):
     s = """
         <!--(block|strip|dummyproc)-->
             one
         <!--(end)-->
     """
     t = cubictemp.Template(s, strip=string.strip)
     assert unicode(t(dummyproc=dummyproc)).strip() == "::one::"
コード例 #5
0
 def test_processorchain(self):
     s = """
         <!--(block|strip|dummyproc|dummyproc2)-->
             one
         <!--(end)-->
     """
     t = cubictemp.Template(s, strip=string.strip, dummyproc2=dummyproc2)
     assert unicode(t(dummyproc=dummyproc)).strip() == "**::one::**"
コード例 #6
0
 def test_format_execution(self):
     s = """
         <!--(block foo)-->
             @!bar!@
         <!--(end)-->
         @!foo!@
     """
     libpry.raises("line 3", unicode, cubictemp.Template(s))
コード例 #7
0
 def test_inlineproc(self):
     s = """
         <!--(block | strip | dummyproc)-->
             one
         <!--(end)-->
     """
     t = cubictemp.Template(s, strip=string.strip)
     assert "::one::" in unicode(t(dummyproc=dummyproc))
コード例 #8
0
 def test_namespace_follow(self):
     s = """
         <!--(block one)-->
             one
         <!--(end)-->
         @!one!@
     """
     t = cubictemp.Template(s)
     assert t().strip() == "one"
コード例 #9
0
 def test_lines(self):
     s = """
         :<!--(block foo)-->
             one
         :<!--(end)-->
     """
     t = cubictemp.Template(s)
     s = t()
     assert ":<!" in unicode(s)
コード例 #10
0
 def test_namespace_simplenest(self):
     s = """
         <!--(block one)-->
             @!two!@
             @!three!@
         <!--(end)-->
         @!one(three="bar")!@
     """
     t = cubictemp.Template(s)
     assert "foo" in unicode(t(two="foo"))
コード例 #11
0
    def test_block_following_whitespace(self):
        s = """
            <!--(block|dummyproc)-->
                one
            <!--(end)-->


            test
        """
        t = cubictemp.Template(s, strip=string.strip)
        assert "\n\n" in unicode(t(dummyproc=dummyproc))
コード例 #12
0
    def test_init(self):
        c = cubictemp.Template(self.s).block
        assert len(c) == 4
        assert not c[0].txt.strip()
        assert not c[1].txt.strip()
        assert c[2].expr == "foo"
        assert c[3].txt.strip() == "one"

        assert c.ns["foo"]
        nest = c.ns["foo"].ns["foo"]
        assert len(nest) == 1

        assert nest[0].iterable == "[1, 2, 3]"
        assert nest[0][1].expr == "tag"
コード例 #13
0
 def test_namespace_follow(self):
     s = """
         <!--(block one)-->
             one
         <!--(end)-->
         @!one!@
         <!--(block one)-->
             two
         <!--(end)-->
         @!one!@
     """
     t = unicode(cubictemp.Template(s))
     assert "one" in t
     assert "two" in t
コード例 #14
0
 def test_namespace_nest(self):
     s = """
         <!--(block one)-->
             foo
         <!--(end)-->
         <!--(block one)-->
             <!--(block two)-->
                 @!one!@
             <!--(end)-->
             @!two!@
         <!--(end)-->
         @!one!@
         <!--(block one)-->
             bar
         <!--(end)-->
         @!one!@
     """
     t = unicode(cubictemp.Template(s))
     assert "foo" in t
     assert "bar" in t
コード例 #15
0
 def test_bench(self):
     t = cubictemp.Template(tmpl)
     str(t)
コード例 #16
0
 def setUp(self):
     self.s = cubictemp.Template("text")
コード例 #17
0
ファイル: test_template.py プロジェクト: stjordanis/cubictemp
 def test_simple(self):
     test = "@!1!@"
     ct = cubictemp.Template(test)
     assert unicode(ct) == "1"
コード例 #18
0
 def test_call(self):
     s = cubictemp.Template(self.s)(tag="voing")
     assert "voing" in unicode(s)
コード例 #19
0
 def setUp(self):
     self.s = cubictemp.Template("text")
     self.t = cubictemp.TemplateError("foo", 0, self.s)
コード例 #20
0
ファイル: test_template.py プロジェクト: stjordanis/cubictemp
 def test_simple2(self):
     test = "@!a!@"
     ns = {"a": 1}
     ct = cubictemp.Template(test, **ns)
     assert unicode(ct) == "1"
コード例 #21
0
 def test_namespace_err(self):
     s = """
         @!one!@
     """
     t = cubictemp.Template(s)
     libpry.raises("not defined", unicode, t)