def test_set_properties(self):
        code = CodeTemplate()
        code.properties  = [{"name": "test",
                             "label": "test",
                             "value": "test",
                             "type": "test"}]

        code.set_properties({"out": "SET"})
        code.set_properties({"test": "SET"})
        assert code.properties[0]["value"] == "SET"
Exemple #2
0
    def create_code_template(self):
        code_template = CodeTemplate()
        code_template.name = "webaudio"
        code_template.type = "Test"
        code_template.language = "Test"
        code_template.command = "python\n"
        code_template.description = "Javascript / webaudio code template"

        code_template.code_parts = [
            "onload", "function", "declaration", "execution", "html"
        ]
        code_template.properties = [{
            "name": "title",
            "label": "Title",
            "value": "Title",
            "type": MOSAICODE_STRING
        }]

        code_template.files["index.html"] = r"""
<html>
    <head>
        <meta http-equiv="Cache-Control" content="no-store" />
        <!-- $author$ $license$ -->
        <title>$prop[title]$</title>
        <link rel="stylesheet" type="text/css" href="theme.css">
        <script src="functions.js"></script>
        <script>
        $single_code[function]$
        function loadme(){
        $single_code[onload]$
        return;
        }
        var context = new (window.AudioContext || window.webkitAudioContext)();
        //declaration block
        $code[declaration]$

        //execution
        $code[execution]$

        //connections
        $connections$
        </script>
    </head>

    <body onload='loadme();'>
        $code[html]$
    </body>
</html>
"""

        code_template.files["theme.css"] = r"""
/*
Developed by: $author$
*/
html, body {
  background: #ffeead;
  color: #ff6f69;
}
h1, p {
  color: #ff6f69;
}
#navbar a {
  color: #ff6f69;
}
.item {
  background: #ffcc5c;
}
button {
  background: #ff6f69;
  color: #ffcc5c;
}
"""

        code_template.files["functions.js"] = r"""
/*
Developed by: $author$
*/
$single_code[function]$
"""
        System.add_code_template(code_template)
        return code_template