This commit is contained in:
Matthew Scragg 2014-02-06 21:40:58 -06:00
parent 904d83ea3c
commit d0777e2b85
15 changed files with 164 additions and 1363 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@
config.py
config.sls
realms/static/vendor
realms/static/assets/*

View file

@ -11,6 +11,6 @@
"components-font-awesome": "~3.2.1",
"showdown": "~0.3.1",
"keymaster": "madrobby/keymaster",
"ace": "~1.0.0"
"ace": "~1.1.0"
}
}

View file

@ -224,33 +224,25 @@ for status_code in httplib.responses:
if status_code >= 400:
app.register_error_handler(status_code, error_handler)
assets = Environment()
from realms.lib.assets import assets, register
assets.init_app(app)
assets.app = app
app.jinja_env.globals['bundles'] = assets
js = Bundle(
Bundle('vendor/jquery/jquery.js',
register(
'vendor/jquery/jquery.js',
'vendor/components-underscore/underscore.js',
'vendor/components-bootstrap/js/bootstrap.js',
'vendor/handlebars/handlebars.js',
'vendor/showdown/src/showdown.js',
'vendor/marked/lib/marked.js',
'vendor/showdown/src/extensions/table.js',
'js/wmd.js',
filters='closure_js'),
'js/html-sanitizer-minified.js',
'js/html-sanitizer-minified.js', # don't minify
'vendor/highlightjs/highlight.pack.js',
Bundle('js/main.js', filters='closure_js'),
output='packed-common.js')
assets.register('js_common', js)
js = Bundle('js/ace/ace.js',
'js/ace/mode-markdown.js',
'vendor/keymaster/keymaster.js',
'js/dillinger.js',
filters='closure_js', output='packed-editor.js')
assets.register('js_editor', js)
'js/main.js'
)
@app.before_request
def check_subdomain():

10
realms/lib/assets.py Normal file
View file

@ -0,0 +1,10 @@
from flask.ext.assets import Bundle, Environment
assets = Environment()
def register(*files):
assets.debug = True
filters = 'uglifyjs'
output = 'assets/%(version)s.js'
assets.add(Bundle(*files, filters=filters, output=output))

View file

@ -0,0 +1,8 @@
from realms.lib.assets import register
register(
'js/ace/ace.js',
'js/ace/mode-markdown.js',
'vendor/keymaster/keymaster.js',
'js/dillinger.js'
)

View file

@ -13,14 +13,9 @@ $(function(){
, autoInterval
, profile =
{
theme: 'ace/theme/idle_fingers'
, currentMd: ''
, autosave:
{
enabled: true
, interval: 3000 // might be too aggressive; don't want to block UI for large saves.
}
, current_filename : $pagename.val()
theme: 'ace/theme/idle_fingers', currentMd: '', autosave: {
enabled: true, interval: 3000 // might be too aggressive; don't want to block UI for large saves.
}, current_filename: $pagename.val()
};
// Feature detect ish
@ -64,7 +59,12 @@ $(function(){
function hasLocalStorage() {
// http://mathiasbynens.be/notes/localstorage-pattern
var storage;
try{ if(localStorage.getItem) {storage = localStorage} }catch(e){}
try {
if (localStorage.getItem) {
storage = localStorage
}
} catch (e) {
}
return storage;
}
@ -111,7 +111,9 @@ $(function(){
* @param {String} The property to test
* @return {Boolean}
*/
function prefixed(prop){ return testPropsAll(prop, 'pfx') }
function prefixed(prop) {
return testPropsAll(prop, 'pfx')
}
/**
* A generic CSS / DOM property test; if a browser supports
@ -157,15 +159,11 @@ $(function(){
*
* @return {String}
*/
function normalizeTransitionEnd()
{
function normalizeTransitionEnd() {
var transEndEventNames =
{
'WebkitTransition' : 'webkitTransitionEnd'
, 'MozTransition' : 'transitionend'
, 'OTransition' : 'oTransitionEnd'
, 'msTransition' : 'msTransitionEnd' // maybe?
'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd', 'msTransition': 'msTransitionEnd' // maybe?
, 'transition': 'transitionend'
};
@ -173,7 +171,6 @@ $(function(){
}
/**
* Get current filename from contenteditable field.
*
@ -238,7 +235,9 @@ $(function(){
*/
function init() {
if( !hasLocalStorage() ) { sadPanda() }
if (!hasLocalStorage()) {
sadPanda()
}
else {
// Attach to jQuery support object for later use.
@ -345,7 +344,8 @@ $(function(){
// Let's turn off autosave
profile.autosave.enabled = false
// Delete the property altogether --> need ; for JSHint bug.
; delete localStorage.profile;
;
delete localStorage.profile;
// Now reload the page to start fresh
window.location.reload();
}
@ -353,7 +353,9 @@ $(function(){
function changeTheme(e) {
// check for same theme
var $target = $(e.target);
if( $target.attr('data-value') === profile.theme) { return; }
if ($target.attr('data-value') === profile.theme) {
return;
}
else {
// add/remove class
$theme.find('li > a.selected').removeClass('selected');
@ -386,7 +388,6 @@ $(function(){
var unmd = editor.getSession().getValue()
, md = MDR.convert(unmd, true);
$preview
.html('') // unnecessary?
.html(md);

View file

@ -5,7 +5,7 @@ hljs.initHighlightingOnLoad();
MDR = {
doc: null,
callback: WMD.convert,
sanitize: null, // Override
sanitize: true, // Override
convert: function(md, sanitize){
if (this.sanitize !== null) {
sanitize = this.sanitize;
@ -14,7 +14,13 @@ MDR = {
var html = this.doc.html;
if (sanitize) {
// Causes some problems with inline styles
html = html_sanitize(html);
html = html_sanitize(html, function(url) {
if(/^https?:\/\//.test(url)) {
return url
}
}, function(id){
return id;
});
}
html = this.hook(html);
return html;

View file

@ -51,7 +51,8 @@ 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;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -97,9 +97,11 @@
</div>
</div>
{% assets "js_common" %}
{% for bundle in bundles %}
{% assets bundle %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
{% endfor %}
{% block js %}{% endblock %}
</body>
</html>

View file

@ -1,14 +1,10 @@
{% extends 'layout.html' %}
{% block js %}
{% assets "js_editor" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
<script>
$(function(){
$("#start-togetherjs").click(function(){
$(this).prop('disabled', true).html("Loading");
});
MDR.sanitize = false;
});
TogetherJSConfig_toolName = "Collaboration";
TogetherJSConfig_suppressJoinConfirmation = true;

View file

@ -18,18 +18,27 @@ bower:
- require:
- pkg.installed: common-pkgs
realms-repo:
git.latest:
- unless: test -e /vagrant
- name: git@github.com:scragg0x/realms.git
- target: /home/deploy
- rev: master
- user: deploy
- identity: /home/deploy/.ssh/id_rsa
uglify-js:
npm.installed:
- user: root
- require:
- pkg.installed: common-pkgs
/home/deploy/virtualenvs/realms:
create_virtualenv:
virtualenv.managed:
- name: /home/deploy/virtualenvs/realms
- requirements: /home/deploy/realms/requirements.txt
- cwd: /home/deploy/realms
- user: deploy
- user: root
vagrant_ownership:
cmd.run:
- name: chown -R vagrant.vagrant /home/deploy
- onlyif: test -d /vagrant
- user: root
deploy_ownership:
cmd.run:
- name: chown -R vagrant.vagrant /home/deploy
- unless: test -d /vagrant
- user: root

View file

@ -1,10 +1,3 @@
/etc/supervisor/conf.d/realms.conf:
file.managed:
- source: salt://supervisor/supervisord.conf
supervisor-run:
cmd.run:
- unless: test -e /tmp/supervisord.pid
- name: /usr/local/bin/supervisord
- require:
- file.managed: /etc/supervisor/conf.d/realms.conf

View file

@ -1,2 +1,3 @@
[program:realms]
command=/home/deploy/virtualenvs/realms/bin/python /home/deploy/realms/manage.py server
user=deploy
command=/home/deploy/realms/virtualenvs/realms/bin/python /home/deploy/realms/manage.py server