Esempio n. 1
0
 def test_server_module(self):
     from wdom.server import _tornado
     server.set_server_type('tornado')
     self.assertTrue(isinstance(server.get_app(), _tornado.Application))
     try:
         from wdom.server import _aiohttp
         server.set_server_type('aiohttp')
         self.assertTrue(isinstance(server.get_app(), _aiohttp.Application))
     except ImportError:
         pass
Esempio n. 2
0
def main():
    # from tornado.ioloop import IOLoop
    # from tornado.platform.asyncio import AsyncIOMainLoop
    import asyncio
    from wdom.misc import install_asyncio
    install_asyncio()

    from wdom.server import start_server, get_app, stop_server
    # from wdom.server_aio import start_server, get_app, stop_server
    # from wdom.server_tornado import start_server, get_app, stop_server
    # from wdom.examples.markdown_simple import sample_page
    # from wdom.examples.rev_text import sample_page
    # from wdom.examples.data_binding import sample_page
    # from wdom.examples.todo import sample_page
    from wdom.examples.theming import sample_page
    # from wdom.themes import bootstrap3, mdl, skeleton, pure, semantic, kube, foundation, mui
    from wdom.themes import default
    page = sample_page(default)
    app = get_app(document=page)
    loop = asyncio.get_event_loop()
    server = start_server(app=app, loop=loop)

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        stop_server(server)
        loop.close()
Esempio n. 3
0
def main():
    AsyncIOMainLoop().install()

    doc = get_document()

    if not options.config.no_default_js:
        doc.add_jsfile(
            'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js')
        doc.add_jsfile('static/bootstrap.min.js')
    if not options.config.no_default_css:
        doc.add_cssfile('static/bootstrap.min.css')

    _user_static_dirs = set()
    for js in options.config.js_files:
        _user_static_dirs.add(path.dirname(js))
        doc.add_jsfile(js)
    for css in options.config.css_files:
        _user_static_dirs.add(path.dirname(css))
        doc.add_cssfile(css)

    # choices arg is better, but detecting error is not easy in livemark.vim
    if options.config.highlight_theme in STYLE_MAP:
        pygments_style = HtmlFormatter(
            style=options.config.highlight_theme).get_style_defs()
    else:
        pygments_style = HtmlFormatter('default').get_style_defs()
    doc.head.appendChild(Style(pygments_style))

    script = Script(parent=doc.body)
    script.innerHTML = '''
        function moveToElement(id) {
            var elm = document.getElementById(id)
            if (elm) {
                var x = window.scrollX
                var rect = elm.getBoundingClientRect()
                window.scrollTo(x, rect.top + window.scrollY)
                console.log(elm.textContent)
            }
        }
    '''
    mount_point = Div(parent=doc.body, class_='container')
    mount_point.appendChild(H2('LiveMark is running...'))
    app = get_app(doc)
    app.add_static_path('static', static_dir)
    for _d in _user_static_dirs:
        app.add_static_path(_d, _d)
    web_server = start_server(app, port=options.config.browser_port)

    loop = asyncio.get_event_loop()
    vim_server = Server(port=options.config.vim_port, loop=loop, doc=doc,
                        mount_point=mount_point)
    browser = webbrowser.get(options.config.browser)
    browser.open('http://localhost:{}'.format(options.config.browser_port))
    try:
        vim_server.start()
        loop.run_forever()
    except KeyboardInterrupt:
        vim_server.stop()
        web_server.stop()
Esempio n. 4
0
def main():
    import asyncio
    from wdom.server import start_server, get_app, stop_server

    doc = sample_page()
    app = get_app(document=doc)
    loop = asyncio.get_event_loop()
    server = start_server(app=app, loop=loop)
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        stop_server(server)
        loop.close()
Esempio n. 5
0
from wdom.server import get_app, start_server, stop_server
from wdom.document import get_document
from wdom.tag import Div, H1, Input


class MyElement(Div):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.h1 = H1(parent=self)
        self.h1.textContent = 'Hello, WDOM'
        self.input = Input(parent=self)
        self.input.addEventListener('input', self.update)

    def update(self, event):
        self.h1.textContent = event.target.value


if __name__ == '__main__':
    install_asyncio()  # only when using tornado

    document = get_document()
    document.body.appendChild(MyElement())

    app = get_app(document)
    loop = asyncio.get_event_loop()
    server = start_server(app, port=8888, loop=loop)
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        stop_server(server)
Esempio n. 6
0
def main():
    AsyncIOMainLoop().install()

    doc = get_document()

    if not options.config.no_default_js:
        doc.add_jsfile(
            'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'
        )
        doc.add_jsfile('static/bootstrap.min.js')
    if not options.config.no_default_css:
        doc.add_cssfile('static/bootstrap.min.css')

    _user_static_dirs = set()
    for js in options.config.js_files:
        _user_static_dirs.add(path.dirname(js))
        doc.add_jsfile(js)
    for css in options.config.css_files:
        _user_static_dirs.add(path.dirname(css))
        doc.add_cssfile(css)

    # choices arg is better, but detecting error is not easy in livemark.vim
    if options.config.highlight_theme in STYLE_MAP:
        pygments_style = HtmlFormatter(
            style=options.config.highlight_theme).get_style_defs()
    else:
        pygments_style = HtmlFormatter('default').get_style_defs()
    doc.head.appendChild(Style(pygments_style))

    script = Script(parent=doc.body)
    script.innerHTML = '''
        function moveToElement(id) {
            var elm = document.getElementById(id)
            if (elm) {
                var x = window.scrollX
                var rect = elm.getBoundingClientRect()
                window.scrollTo(x, rect.top + window.scrollY)
                console.log(elm.textContent)
            }
        }
    '''
    mount_point = Div(parent=doc.body, class_='container')
    mount_point.appendChild(H2('LiveMark is running...'))
    app = get_app(doc)
    app.add_static_path('static', static_dir)
    for _d in _user_static_dirs:
        app.add_static_path(_d, _d)
    web_server = start_server(app, port=options.config.browser_port)

    loop = asyncio.get_event_loop()
    vim_server = Server(port=options.config.vim_port,
                        loop=loop,
                        doc=doc,
                        mount_point=mount_point)
    browser = webbrowser.get(options.config.browser)
    browser.open('http://localhost:{}'.format(options.config.browser_port))
    try:
        vim_server.start()
        loop.run_forever()
    except KeyboardInterrupt:
        vim_server.stop()
        web_server.stop()