예제 #1
0
def test_inlineJS():
    """inline Javascript flattening"""
    js = """
        if (x=1) {
            y=2;
        }
    """
    template = T.html[
        T.body[
            T.inlineJS(js)
        ]
    ]
    output = flatten(template)
    assert output == ('<html><body>\n<script type="text/javascript">\n//<![CDATA[\n'
                      '%s\n//]]></script>\n</body></html>' % js)
예제 #2
0
파일: html.py 프로젝트: rudykocur/pyeve
    def render(self, request, url):
        """
        :type url: werkzeug.routing.MapAdapter
        """

        ifLogged = lambda fun: fun if self.isLogged else ''

        layout = (
            T.html(lang='en')[
                T.head[
                    T.meta(charset='utf-8'),
                    T.meta(content='IE=Edge', **{'http-equiv': "X-UA-Compatible"}),
                    T.meta(name='viewport', content='width=device-width, initial-scale=1'),

                    T.title['PyEve WSGI App'],

                    T.link(href='/static/css/bootstrap.min.css', rel='stylesheet')
                ],

                T.body[
                    T.div(class_="container-fluid")[
                        T.h1['PyEve'],
                        invisible(render=ifLogged(self.renderNavbar), data=(url, None)),
                        T.div(class_='row')[
                            T.div(class_='col-sm-3')[
                                invisible(render=ifLogged(self.renderModuleNav), data=(url, None))
                            ],
                            T.div(class_='col-sm-9')[
                                self.content
                            ]
                        ],
                    ],

                    T.script(src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'),
                    T.script(src='/static/js/bootstrap.js'),
                    T.inlineJS("""
                        $(document).ready(function() {
                            $(document.body).tooltip({
                                selector: ".withTooltip"
                            })
                        })
                    """)
                ]
            ]
        )

        return Response(flatten(layout), mimetype='text/html')