Ejemplo n.º 1
0
def compile_mapcss():
    """ Compile the MapCSS provided in POST request to JavaScript, and send it in response """
    stylecontent = request.form['css']
    stylename = request.form['name']
    compiled_style = mapcss_converter.render_js(stylename,stylecontent)
    
    if compiled_style:
        return compiled_style
    else:
        return 'alert("Malformed MapCSS")' #response gets eval()d on client side
Ejemplo n.º 2
0
def send_style():
    """ Send the style - compiled or not - as an attachment """
    if request.form['format'] == 'css': #don't compile, just send file with proper headers
        response_body = request.form['css']
        response_type = 'text/css'
        response_extension = 'mapcss'
    else: #compile style to JS
        try:
            request_body = request.form['css']
            response_body = mapcss_converter.render_js(request.form['name'],request_body)
            response_type = 'text/javascript'
            response_extension = 'js'
        except:
            abort(400)
    response = make_response(response_body)
    response.headers['Content-Disposition'] = 'attachment; filename=%s.%s' % (request.form['name'], response_extension) #force the browser to download result
    return response