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