예제 #1
0
def create(index="index.html", ngmodules=None, minify=True, locator=current):
    """
    Creates wutu app
    :param index: html file for index page
    :param minify: Do we want to minify generated JavaScripts (should be False for debug purposes)
    :param locator: function which tells where to find templates
    :return:
    """
    app = CustomFlask(__name__)
    api = Api(app)
    app.jinja_loader = jinja2.FileSystemLoader(locator())
    api.jsstream = create_stream()
    create_base(api.jsstream, ngmodules)

    @app.route("/")
    def index_page():
        """
        Endpoint for base page
        :return:
        """
        try:
            return render_template(index)
        except IOError:
            return "Failed to render template {0}, error: Not found".format(
                index)

    @lru_cache()
    @app.route("/wutu.js")
    def wutu_js():
        if minify:
            from jsmin import jsmin
            jsdata = jsmin(get_data(api.jsstream))
        else:
            from jsbeautifier import beautify
            jsdata = beautify(get_data(api.jsstream))
        return Response(jsdata, mimetype="text/javascript")

    app.api = api
    return app
예제 #2
0
파일: app.py 프로젝트: zaibacu/wutu
def create(index="index.html", ngmodules=None, minify=True, locator=current):
    """
    Creates wutu app
    :param index: html file for index page
    :param minify: Do we want to minify generated JavaScripts (should be False for debug purposes)
    :param locator: function which tells where to find templates
    :return:
    """
    app = CustomFlask(__name__)
    api = Api(app)
    app.jinja_loader = jinja2.FileSystemLoader(locator())
    api.jsstream = create_stream()
    create_base(api.jsstream, ngmodules)

    @app.route("/")
    def index_page():
        """
        Endpoint for base page
        :return:
        """
        try:
            return render_template(index)
        except IOError:
            return "Failed to render template {0}, error: Not found".format(index)

    @lru_cache()
    @app.route("/wutu.js")
    def wutu_js():
        if minify:
            from jsmin import jsmin
            jsdata = jsmin(get_data(api.jsstream))
        else:
            from jsbeautifier import beautify
            jsdata = beautify(get_data(api.jsstream))
        return Response(jsdata, mimetype="text/javascript")

    app.api = api
    return app
예제 #3
0
 def __init__(self):
     self.log = get_logger("api_mock")
     self.resources = {}
     self.jsstream = create_stream()
예제 #4
0
def main():
    mod = Module()
    mod.__name__ = "test_module"
    stream = create_stream()
    for i in range(0, 1000):
        handle_creation(mod, stream)
예제 #5
0
파일: test_util.py 프로젝트: zaibacu/wutu
 def __init__(self):
     self.log = get_logger("api_mock")
     self.resources = {}
     self.jsstream = create_stream()
예제 #6
0
def main():
    mod = Module()
    mod.__name__ = "test_module"
    stream = create_stream()
    for i in range(0, 1000):
        handle_creation(mod, stream)