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.py
config.sls config.sls
realms/static/vendor realms/static/vendor
realms/static/assets/*

View file

@ -11,6 +11,6 @@
"components-font-awesome": "~3.2.1", "components-font-awesome": "~3.2.1",
"showdown": "~0.3.1", "showdown": "~0.3.1",
"keymaster": "madrobby/keymaster", "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: if status_code >= 400:
app.register_error_handler(status_code, error_handler) app.register_error_handler(status_code, error_handler)
assets = Environment() from realms.lib.assets import assets, register
assets.init_app(app) assets.init_app(app)
assets.app = app
app.jinja_env.globals['bundles'] = assets
js = Bundle( register(
Bundle('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',
'vendor/handlebars/handlebars.js', 'vendor/handlebars/handlebars.js',
'vendor/showdown/src/showdown.js', 'vendor/showdown/src/showdown.js',
'vendor/marked/lib/marked.js',
'vendor/showdown/src/extensions/table.js', 'vendor/showdown/src/extensions/table.js',
'js/wmd.js', 'js/wmd.js',
filters='closure_js'), 'js/html-sanitizer-minified.js', # don't minify
'js/html-sanitizer-minified.js',
'vendor/highlightjs/highlight.pack.js', 'vendor/highlightjs/highlight.pack.js',
Bundle('js/main.js', filters='closure_js'), 'js/main.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)
@app.before_request @app.before_request
def check_subdomain(): 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 , autoInterval
, profile = , profile =
{ {
theme: 'ace/theme/idle_fingers' theme: 'ace/theme/idle_fingers', currentMd: '', autosave: {
, currentMd: '' enabled: true, interval: 3000 // might be too aggressive; don't want to block UI for large saves.
, autosave: }, current_filename: $pagename.val()
{
enabled: true
, interval: 3000 // might be too aggressive; don't want to block UI for large saves.
}
, current_filename : $pagename.val()
}; };
// Feature detect ish // Feature detect ish
@ -64,7 +59,12 @@ $(function(){
function hasLocalStorage() { function hasLocalStorage() {
// http://mathiasbynens.be/notes/localstorage-pattern // http://mathiasbynens.be/notes/localstorage-pattern
var storage; var storage;
try{ if(localStorage.getItem) {storage = localStorage} }catch(e){} try {
if (localStorage.getItem) {
storage = localStorage
}
} catch (e) {
}
return storage; return storage;
} }
@ -111,7 +111,9 @@ $(function(){
* @param {String} The property to test * @param {String} The property to test
* @return {Boolean} * @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 * A generic CSS / DOM property test; if a browser supports
@ -157,15 +159,11 @@ $(function(){
* *
* @return {String} * @return {String}
*/ */
function normalizeTransitionEnd() function normalizeTransitionEnd() {
{
var transEndEventNames = var transEndEventNames =
{ {
'WebkitTransition' : 'webkitTransitionEnd' 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd', 'msTransition': 'msTransitionEnd' // maybe?
, 'MozTransition' : 'transitionend'
, 'OTransition' : 'oTransitionEnd'
, 'msTransition' : 'msTransitionEnd' // maybe?
, 'transition': 'transitionend' , 'transition': 'transitionend'
}; };
@ -173,7 +171,6 @@ $(function(){
} }
/** /**
* Get current filename from contenteditable field. * Get current filename from contenteditable field.
* *
@ -238,7 +235,9 @@ $(function(){
*/ */
function init() { function init() {
if( !hasLocalStorage() ) { sadPanda() } if (!hasLocalStorage()) {
sadPanda()
}
else { else {
// Attach to jQuery support object for later use. // Attach to jQuery support object for later use.
@ -345,7 +344,8 @@ $(function(){
// Let's turn off autosave // Let's turn off autosave
profile.autosave.enabled = false profile.autosave.enabled = false
// Delete the property altogether --> need ; for JSHint bug. // Delete the property altogether --> need ; for JSHint bug.
; delete localStorage.profile; ;
delete localStorage.profile;
// Now reload the page to start fresh // Now reload the page to start fresh
window.location.reload(); window.location.reload();
} }
@ -353,7 +353,9 @@ $(function(){
function changeTheme(e) { function changeTheme(e) {
// check for same theme // check for same theme
var $target = $(e.target); var $target = $(e.target);
if( $target.attr('data-value') === profile.theme) { return; } if ($target.attr('data-value') === profile.theme) {
return;
}
else { else {
// add/remove class // add/remove class
$theme.find('li > a.selected').removeClass('selected'); $theme.find('li > a.selected').removeClass('selected');
@ -386,7 +388,6 @@ $(function(){
var unmd = editor.getSession().getValue() var unmd = editor.getSession().getValue()
, md = MDR.convert(unmd, true); , md = MDR.convert(unmd, true);
$preview $preview
.html('') // unnecessary? .html('') // unnecessary?
.html(md); .html(md);

View file

@ -5,7 +5,7 @@ hljs.initHighlightingOnLoad();
MDR = { MDR = {
doc: null, doc: null,
callback: WMD.convert, callback: WMD.convert,
sanitize: null, // Override sanitize: true, // Override
convert: function(md, sanitize){ convert: function(md, sanitize){
if (this.sanitize !== null) { if (this.sanitize !== null) {
sanitize = this.sanitize; sanitize = this.sanitize;
@ -14,7 +14,13 @@ MDR = {
var html = this.doc.html; var html = this.doc.html;
if (sanitize) { if (sanitize) {
// Causes some problems with inline styles // 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); html = this.hook(html);
return html; return html;

View file

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

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>
</div> </div>
{% assets "js_common" %} {% for bundle in bundles %}
{% assets bundle %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script> <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% endassets %}
{% endfor %}
{% block js %}{% endblock %} {% block js %}{% endblock %}
</body> </body>
</html> </html>

View file

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

View file

@ -18,18 +18,27 @@ bower:
- require: - require:
- pkg.installed: common-pkgs - pkg.installed: common-pkgs
realms-repo: uglify-js:
git.latest: npm.installed:
- unless: test -e /vagrant - user: root
- name: git@github.com:scragg0x/realms.git - require:
- target: /home/deploy - pkg.installed: common-pkgs
- rev: master
- user: deploy
- identity: /home/deploy/.ssh/id_rsa
/home/deploy/virtualenvs/realms: create_virtualenv:
virtualenv.managed: virtualenv.managed:
- name: /home/deploy/virtualenvs/realms
- requirements: /home/deploy/realms/requirements.txt - requirements: /home/deploy/realms/requirements.txt
- cwd: /home/deploy/realms - 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: /etc/supervisor/conf.d/realms.conf:
file.managed: file.managed:
- source: salt://supervisor/supervisord.conf - 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] [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