worked on assets bundling, added admin field
This commit is contained in:
parent
0dead5176a
commit
ad401da4f1
|
@ -9,7 +9,7 @@ add-apt-repository -y ppa:chris-lea/node.js
|
|||
apt-get update
|
||||
apt-get install -y python build-essential git libpcre3-dev python-software-properties \
|
||||
python-pip python-virtualenv python-dev pkg-config curl libxml2-dev libxslt1-dev zlib1g-dev \
|
||||
libffi-dev nodejs screen
|
||||
libffi-dev nodejs screen node-cleancss
|
||||
|
||||
# Default cache is memoization
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class Application(Flask):
|
|||
|
||||
|
||||
class Assets(Environment):
|
||||
default_filters = {'js': 'jsmin', 'css': 'cssmin'}
|
||||
default_filters = {'js': 'rjsmin', 'css': 'cleancss'}
|
||||
default_output = {'js': 'assets/%(version)s.js', 'css': 'assets/%(version)s.css'}
|
||||
|
||||
def register(self, name, *args, **kwargs):
|
||||
|
@ -96,7 +96,7 @@ class Assets(Environment):
|
|||
filters = kwargs.get('filters', self.default_filters[ext])
|
||||
output = kwargs.get('output', self.default_output[ext])
|
||||
|
||||
super(Assets, self).register(name, Bundle(*args, filters=filters, output=output))
|
||||
return super(Assets, self).register(name, Bundle(*args, filters=filters, output=output))
|
||||
|
||||
|
||||
class RegexConverter(BaseConverter):
|
||||
|
@ -123,7 +123,7 @@ def error_handler(e):
|
|||
else:
|
||||
status_code = httplib.INTERNAL_SERVER_ERROR
|
||||
message = None
|
||||
tb = traceback.format_exc() if current_user.staff else None
|
||||
tb = traceback.format_exc() if current_user.admin else None
|
||||
|
||||
if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']:
|
||||
response = {
|
||||
|
@ -154,7 +154,7 @@ def create_app():
|
|||
|
||||
@app.before_request
|
||||
def init_g():
|
||||
g.assets = ['main']
|
||||
g.assets = dict(css=['main.css'], js=['main.js'])
|
||||
|
||||
@app.template_filter('datetime')
|
||||
def _jinja2_filter_datetime(ts):
|
||||
|
@ -182,8 +182,8 @@ login_manager.login_view = 'auth.login'
|
|||
db = SQLAlchemy(app)
|
||||
cache = Cache(app)
|
||||
|
||||
assets = Environment(app)
|
||||
assets.register('main',
|
||||
assets = Assets(app)
|
||||
assets.register('main.js',
|
||||
'vendor/jquery/jquery.js',
|
||||
'vendor/components-underscore/underscore.js',
|
||||
'vendor/components-bootstrap/js/bootstrap.js',
|
||||
|
@ -196,8 +196,15 @@ assets.register('main',
|
|||
'vendor/parsleyjs/dist/parsley.js',
|
||||
'js/main.js')
|
||||
|
||||
assets.register('main.css',
|
||||
'css/bootstrap/flatly.css',
|
||||
'css/font-awesome.min.css',
|
||||
'vendor/highlightjs/styles/github.css',
|
||||
'css/style.css')
|
||||
|
||||
app.discover()
|
||||
|
||||
# Should be called explicitly during install?
|
||||
db.create_all()
|
||||
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ ENV = 'DEV'
|
|||
|
||||
DEBUG = True
|
||||
ASSETS_DEBUG = True
|
||||
|
||||
SQLALCHEMY_ECHO = True
|
||||
|
||||
PORT = 80
|
||||
PORT = 5000
|
||||
BASE_URL = 'http://realms.dev'
|
||||
SITE_TITLE = "Realms"
|
||||
|
||||
DB_URI = 'sqlite:///%s/wiki.db' % USER_HOME
|
||||
|
||||
|
@ -27,6 +27,8 @@ CACHE_REDIS_PORT = 6379
|
|||
CACHE_REDIS_DB = '0'
|
||||
"""
|
||||
|
||||
# Get ReCaptcha Keys for your domain here:
|
||||
# https://www.google.com/recaptcha/admin#whyrecaptcha
|
||||
RECAPTCHA_ENABLE = False
|
||||
RECAPTCHA_USE_SSL = False
|
||||
RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao"
|
||||
|
|
|
@ -38,6 +38,7 @@ def load_token(token):
|
|||
class AnonUser(AnonymousUserMixin):
|
||||
username = 'Anon'
|
||||
email = ''
|
||||
admin = False
|
||||
|
||||
|
||||
class User(Model, UserMixin):
|
||||
|
@ -46,6 +47,7 @@ class User(Model, UserMixin):
|
|||
username = db.Column(db.String, unique=True)
|
||||
email = db.Column(db.String, unique=True)
|
||||
password = db.Column(db.String)
|
||||
admin = False
|
||||
|
||||
hidden_fields = ['password']
|
||||
readonly_fields = ['email', 'password']
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from realms import assets
|
||||
|
||||
assets.register('editor',
|
||||
assets.register('editor.js',
|
||||
'js/ace/ace.js',
|
||||
'js/ace/mode-markdown.js',
|
||||
'vendor/keymaster/keymaster.js',
|
||||
|
|
|
@ -62,7 +62,7 @@ def edit(name):
|
|||
if data:
|
||||
name = remove_ext(data['name'])
|
||||
content = data['data']
|
||||
g.assets.append('editor')
|
||||
g.assets['js'].append('editor.js')
|
||||
return render_template('wiki/edit.html', name=name, content=content)
|
||||
else:
|
||||
return redirect(url_for('wiki.create', name=cname))
|
||||
|
@ -90,7 +90,7 @@ def create(name):
|
|||
# Page exists, edit instead
|
||||
return redirect(url_for('wiki.edit', name=cname))
|
||||
|
||||
g.assets.append('editor')
|
||||
g.assets['js'].append('editor.js')
|
||||
return render_template('wiki/edit.html', name=cname, content="")
|
||||
|
||||
|
||||
|
|
|
@ -41,9 +41,11 @@ WMD.convert = function(content, options) {
|
|||
};
|
||||
|
||||
|
||||
function gsub(str, re, fn, /*optional*/newstr) {
|
||||
function gsub(str, regex, fn, /*optional*/newstr) {
|
||||
newstr = newstr || '';
|
||||
var re = new RegExp(regex);
|
||||
var match = re.exec(str);
|
||||
var remaining;
|
||||
if (match) {
|
||||
newstr += str.slice(0, match.index);
|
||||
newstr += fn.apply(null, match);
|
||||
|
@ -51,7 +53,7 @@ function gsub(str, re, fn, /*optional*/newstr) {
|
|||
return gsub(remaining, re, fn, newstr);
|
||||
}
|
||||
return newstr + str;
|
||||
};
|
||||
}
|
||||
|
||||
WMD.showdown = new Showdown.converter({extensions: ['table']});
|
||||
WMD.processor = WMD.showdown.makeHtml;
|
||||
|
@ -61,7 +63,7 @@ WMD.preprocessors = {
|
|||
underscores: function (doc) {
|
||||
// prevent foo_bar_baz from ending up with an italic word in the middle
|
||||
doc.markdown = gsub(doc.markdown,
|
||||
/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/, function (match) {
|
||||
"/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/", function (match) {
|
||||
var count = 0;
|
||||
for (var i = 0; i < match.length; i++) {
|
||||
if (match[i] == '_') count++;
|
||||
|
@ -83,7 +85,7 @@ WMD.preprocessors = {
|
|||
while (lines.length) {
|
||||
var match = /^(\S+):\s+(.*)$/.exec(lines[0]);
|
||||
if (match) {
|
||||
var key = match[1];
|
||||
key = match[1];
|
||||
doc.metadata[key] = match[2];
|
||||
lines.shift();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@
|
|||
|
||||
<title>Realms</title>
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.ico') }}">
|
||||
<link href="{{ url_for('static', filename='css/bootstrap/flatly.css') }}" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='vendor/highlightjs/styles/github.css') }}" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
|
||||
|
||||
{% for bundle in g.assets['css'] %}
|
||||
{% assets bundle %}
|
||||
<link type="text/javascript" href="{{ ASSET_URL }}" rel="stylesheet">
|
||||
{% endassets %}
|
||||
{% endfor %}
|
||||
{% block css %}{% endblock %}
|
||||
|
||||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
|
@ -32,7 +34,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="/">Realms</a>
|
||||
<a class="navbar-brand" href="/">{{ config.SITE_TITLE }}</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse navbar-inverse-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
|
@ -86,7 +88,7 @@
|
|||
{% block body %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
{% for bundle in g.assets %}
|
||||
{% for bundle in g.assets['js'] %}
|
||||
{% assets bundle %}
|
||||
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
|
||||
{% endassets %}
|
||||
|
|
Loading…
Reference in a new issue