Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added url_for to src of the css, fonts and javascripts - for #33 #38

Open
wants to merge 3 commits into
base: suburl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
reload(sys)
sys.setdefaultencoding('utf-8')

from flask import Flask, request, render_template, jsonify, Response, send_file
from flask import Flask, request, render_template, url_for, jsonify, Response, send_file
import os
import os.path
import subprocess
Expand All @@ -27,9 +27,54 @@
PANDOC_EXTENSIONS = ['pdf', 'docx', 'epub', 'html']
DOCVERTER_URL = 'http://c.docverter.com/convert'
PDFLATEX_EXISTS = distutils.spawn.find_executable("pdflatex") != None
STATIC_URL_PATH = '/markx/static' # flask default

app = Flask(__name__, static_url_path=STATIC_URL_PATH)
app = Flask(__name__)

class ReverseProxied(object):
'''Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.

In nginx:
location /myprefix {
proxy_pass http://192.168.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /myprefix;
}

In Apache2:
<Location /markx>
ProxyPass http://192.168.0.1:5000
ProxyPassReverse http://192.168.0.1:5000
RequestHeader set X-Script-Name /markx
</Location>

:param app: the WSGI application
'''
def __init__(self, app):
self.app = app

def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]

scheme = environ.get('HTTP_X_SCHEME', '')
if scheme:
environ['wsgi.url_scheme'] = scheme
return self.app(environ, start_response)

app.wsgi_app = ReverseProxied(app.wsgi_app)
def get_url_for(filename, **values):
return url_for('static', filename=filename, **values)
app.jinja_env.globals['static'] = get_url_for

app.config.from_object(__name__)
print " * Overriding deafult configuration with config.py file"
app.config.from_pyfile('config.py', silent=True)
Expand Down
2 changes: 1 addition & 1 deletion static/css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ body
}

.wmd-button > span {
background-image: url("/static/img/wmd-buttons.png");
background-image: url('../img/wmd-buttons.png');
background-repeat: no-repeat;
background-position: 0px 0px;
width: 20px;
Expand Down
10 changes: 5 additions & 5 deletions static/css/fonts.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@font-face {
font-family: 'icomoon';
src:url('/static/fonts/icomoon.eot');
src:url('/static/fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('/static/fonts/icomoon.woff') format('woff'),
url('/static/fonts/icomoon.ttf') format('truetype'),
url('/static/fonts/icomoon.svg#icomoon') format('svg');
src:url('../fonts/icomoon.eot');
src:url('../fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('../fonts/icomoon.woff') format('woff'),
url('../fonts/icomoon.ttf') format('truetype'),
url('../fonts/icomoon.svg#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
Expand Down
42 changes: 21 additions & 21 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
<meta name="keywords" content="">
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="icon" type="image/ico" href="/static/img/favicon.ico">
<link rel="icon" type="image/ico" href="{{ static('img/favicon.ico') }}">

<!-- Le style -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/static/css/style.css" rel="stylesheet">
<link href="/static/css/editor.css" rel="stylesheet">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/fonts.css" rel="stylesheet">
<link href="/static/css/codemirror.css" rel="stylesheet">
<link href="/static/css/codemirror-elegant.css" rel="stylesheet">
<link href="{{ static('css/style.css') }}" rel="stylesheet">
<link href="{{ static('css/editor.css') }}" rel="stylesheet">
<link href="{{ static('css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ static('css/fonts.css') }}" rel="stylesheet">
<link href="{{ static('css/codemirror.css') }}" rel="stylesheet">
<link href="{{ static('css/codemirror-elegant.css') }}" rel="stylesheet">

<!-- google code prettifier http://code.google.com/p/google-code-prettify/ -->
<script type="text/javascript" src="/static/js/prettify.js"></script>
<link href="/static/css/prettify/tomorrow-night-light.css" rel="stylesheet" id="prettify-style">
<script type="text/javascript" src="{{ static('js/prettify.js') }}"></script>
<link href="{{ static('css/prettify/tomorrow-night-light.css') }}" rel="stylesheet" id="prettify-style">

<!-- MathJax -->
<script type="text/x-mathjax-config">
Expand All @@ -34,22 +34,22 @@
}
});
</script>
<script type="text/javascript" src="/static/js/mathjax/MathJax.js?config=TeX-AMS_HTML">
<script type="text/javascript" src="{{ static('js/mathjax/MathJax.js', config='TeX-AMS_HTML') }}">
<!--http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"-->
</script>

<!-- Le JS -->
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="/static/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="/static/js/underscore-min.js"></script>
<script type="text/javascript" src="/static/js/base64.js"></script>
<script type="text/javascript" src="/static/js/github.js"></script>
<script type="text/javascript" src="/static/js/BibTex.js"></script>
<script type="text/javascript" src="/static/js/codemirror.js"></script>
<script type="text/javascript" src="/static/js/codemirror-markdown.js"></script>
<script type="text/javascript" src="/static/js/markx.js"></script>
<script type="text/javascript" src="{{ static('js/jquery.min.js') }}"></script>
<script type="text/javascript" src="{{ static('js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="{{ static('js/Markdown.Converter.js') }}"></script>
<script type="text/javascript" src="{{ static('js/Markdown.Sanitizer.js') }}"></script>
<script type="text/javascript" src="{{ static('js/underscore-min.js') }}"></script>
<script type="text/javascript" src="{{ static('js/base64.js') }}"></script>
<script type="text/javascript" src="{{ static('js/github.js') }}"></script>
<script type="text/javascript" src="{{ static('js/BibTex.js') }}"></script>
<script type="text/javascript" src="{{ static('js/codemirror.js') }}"></script>
<script type="text/javascript" src="{{ static('js/codemirror-markdown.js') }}"></script>
<script type="text/javascript" src="{{ static('js/markx.js') }}"></script>

{% block head %}
{% endblock head %}
Expand Down
4 changes: 2 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="row-fluid">
<div class="span12" style="line-height: 40px;">
<a class="brand" href="/" rel="tooltip" title="Karl Heinrich Marx, 1818 – 1883">
<img class="img-rounded" src="{{ url_for('static', filename='img/karl-marx-160x40.png') }}">
<img class="img-rounded" src="{{ static('img/karl-marx-160x40.png') }}">
</a>
<div class="btn-toolbar" id="general-toolbar">
<button href="#modal-github-signin" id="btn-github-signin-show" role="button" class="btn" data-toggle="modal" rel="tooltip" title="Sign in to GitHub">
Expand Down Expand Up @@ -345,4 +345,4 @@
</script>
{% endif %}

{%endblock footer %}
{%endblock footer %}