예제 #1
0
 def __init__(self, *args, **kwargs):
     self.attributes = {}
     self.children = []
     self.parent = None
     self.document = None
     cors = kwargs.pop("cors", False)
     bulma = kwargs.pop(
         "bulma",
         "https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css")
     fa = kwargs.pop(
         "fa", "https://use.fontawesome.com/releases/v5.3.1/js/all.js")
     axios = kwargs.pop("axios",
                        "https://unpkg.com/[email protected]/dist/axios.min.js")
     jquery = kwargs.pop(
         "jquery", "https://code.jquery.com/jquery-3.3.1.slim.min.js")
     jquery_verify = kwargs.pop(
         "jquery_verify",
         "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
     )
     corsargs = {}
     verify_args = {}
     if cors:
         corsargs = {"crossorigin": cors}
     if jquery_verify:
         verify_args = {"integrity": jquery_verify}
     initargs = [
         t.link(rel='stylesheet', href=bulma),
         t.script(defer=True, src=fa),
         t.script(src=axios, **corsargs),
         t.script(src=jquery, **corsargs, **verify_args),
         cccp.CreateReplaceHtmlFunc(),
         cccp.CreateAppendHtmlFunc(),
         cccp.CreatePrependHtmlFunc(),
     ] + list(args)
     super(init, self).__init__(*initargs, **kwargs)
예제 #2
0
def home():
    return t.html(
        [
            t.head(
                [
                    cccp.REQUIRED,
                    cccp.BOOTSTRAP,
                    cccp.CreateReplaceHtmlFunc(),
                    cccp.CreateAppendHtmlFunc(),
                    cccp.CreatePrependHtmlFunc(),
                ]
            ),
            t.body(
                [
                    t.h1("Hello, CCCP!"),
                    t.div(id="pageContent"),
                    t.button(
                        "go to blog",
                        onClick=cccp.replaceHtml(
                            "http://127.0.0.1:9999/page/1", "pageContent"
                        ),
                    ),
                ]
            ),
        ]
    ).render()
예제 #3
0
 def test_init_render_no_cors_no_verify(self):
     self.maxDiff = None
     init = bulmate.init(bulma="a",
                         fa="b",
                         axios="c",
                         jquery="d",
                         jquery_verify=False)
     self.assertEqual(
         init.render(indent='').strip(), "\n".join([
             '<link href="a" rel="stylesheet">',
             '<script defer="defer" src="b"></script>',
             '<script src="c"></script>',
             '<script src="d"></script>',
             cccp.CreateReplaceHtmlFunc().render(),
             cccp.CreateAppendHtmlFunc().render(),
             cccp.CreatePrependHtmlFunc().render(),
         ]))
예제 #4
0
 def test_init_render_cors(self):
     self.maxDiff = None
     init = bulmate.init(cors="z",
                         bulma="a",
                         fa="b",
                         axios="c",
                         indent=0,
                         jquery="d",
                         jquery_verify="e")
     self.assertEqual(
         init.render(indent='').strip(), "\n".join([
             '<link href="a" rel="stylesheet">',
             '<script defer="defer" src="b"></script>',
             '<script crossorigin="z" src="c"></script>',
             '<script crossorigin="z" integrity="e" src="d"></script>',
             cccp.CreateReplaceHtmlFunc().render(),
             cccp.CreateAppendHtmlFunc().render(),
             cccp.CreatePrependHtmlFunc().render(),
         ]))