-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add live preview capabilities - Better error handling - Garbage collect before creating new preview - Fix live preview logic - Update README
- Loading branch information
Showing
24 changed files
with
616 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
language: python | ||
cache: pip | ||
|
||
# Use container-based infrastructure | ||
dist: xenial | ||
sudo: false | ||
|
||
matrix: | ||
include: | ||
- env: TOXENV=py37-django22-wagtail25 | ||
python: 3.7 | ||
- env: TOXENV=py36-django21-wagtail24 | ||
python: 3.6 | ||
- env: TOXENV=py36-django21-wagtail23 | ||
python: 3.6 | ||
- env: TOXENV=py35-django20-wagtail24 | ||
python: 3.5 | ||
- env: TOXENV=py35-django20-wagtail23 | ||
python: 3.5 | ||
- env: TOXENV=py35-django20-wagtail22 | ||
python: 3.5 | ||
- env: TOXENV=py35-django20-wagtail21 | ||
python: 3.5 | ||
- env: TOXENV=py35-django20-wagtail20 | ||
python: 3.5 | ||
|
||
allow_failures: | ||
- env: TOXENV=py37-djangomaster-wagtail25 | ||
|
||
install: | ||
- pip install wheel flake8 isort | ||
- pip install -e .[testing] | ||
|
||
before_script: | ||
- TESTDIR=$(pwd) | ||
|
||
script: | ||
- flake8 wagtail_headless_preview | ||
- isort --check-only --diff --recursive wagtail_headless_preview | ||
- cd wagtail_headless_preview/tests/client | ||
- nohup python3 -m http.server 8020 > /dev/null 2>&1 & | ||
- cd $TESTDIR | ||
- tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import warnings | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
os.environ['DJANGO_SETTINGS_MODULE'] = 'wagtail_headless_preview.tests.settings' | ||
|
||
|
||
def runtests(): | ||
# Don't ignore DeprecationWarnings | ||
only_wagtail_headless_preview = r'^wagtail_headless_preview(\.|$)' | ||
warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtail_headless_preview) | ||
warnings.filterwarnings('default', category=PendingDeprecationWarning, module=only_wagtail_headless_preview) | ||
|
||
args = sys.argv[1:] | ||
argv = sys.argv[:1] + ['test'] + args | ||
try: | ||
execute_from_command_line(argv) | ||
finally: | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
runtests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[bdist_wheel] | ||
universal = 1 | ||
|
||
[metadata] | ||
description-file = README.md | ||
|
||
[flake8] | ||
max-line-length=120 | ||
exclude=migrations | ||
|
||
[isort] | ||
known_first_party = wagtail_headless_preview | ||
known_django = django | ||
known_wagtail = wagtail | ||
skip = migrations | ||
sections = FUTURE, STDLIB, DJANGO, THIRDPARTY, FIRSTPARTY, LOCALFOLDER | ||
default_section = THIRDPARTY | ||
multi_line_output = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[tox] | ||
skipsdist = True | ||
|
||
envlist = | ||
py{35,36}-django{20,21}-wagtail{20,21,22,23,24} | ||
py37-django{22,master}-wagtail25 | ||
|
||
[testenv] | ||
install_command = pip install -e ".[testing]" -U {opts} {packages} | ||
commands = | ||
python runtests.py | ||
|
||
basepython = | ||
py35: python3.5 | ||
py36: python3.6 | ||
py37: python3.7 | ||
|
||
deps = | ||
django200: django>=2.0,<2.1 | ||
django21: Django>=2.1,<2.2 | ||
django22: Django>=2.2,<2.3 | ||
djangomaster: git+https://github.com/django/django.git@master#egg=Django | ||
wagtail20: wagtail>=2.0,<2.1 | ||
wagtail21: wagtail>=2.1,<2.2 | ||
wagtail22: wagtail>=2.2,<2.3 | ||
wagtail23: wagtail>=2.3,<2.4 | ||
wagtail24: wagtail>=2.4,<2.5 | ||
wagtail25: wagtail>=2.5,<2.6 | ||
|
||
[testenv:flake8] | ||
deps=flake8>3.7 | ||
commands=flake8 wagtail_headless_preview | ||
|
||
[flake8] | ||
ignore = D100,D101,D102,D103,D105,D200,D202,D204,D205,D209,D400,D401,E303,E501,W503,N805,N806 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.dispatch import Signal | ||
|
||
preview_update = Signal(providing_args=["token"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$(document).ready(() => { | ||
let $previewButton = $('.action-preview'); | ||
// Make existing Wagtail code send form data to backend on KeyUp | ||
$previewButton.attr('data-auto-update', "true"); | ||
|
||
// Trigger preview save on key up | ||
let $form = $('#page-edit-form'); | ||
let previewUrl = $previewButton.data('action'); | ||
let triggerPreviewDataTimeout = -1; | ||
let autoUpdatePreviewDataTimeout = -1; | ||
|
||
const triggerPreviewUpdate = () => { | ||
return $.ajax({ | ||
url: `${previewUrl}?live_preview=true`, | ||
method: 'GET', | ||
data: new FormData($form[0]), | ||
processData: false, | ||
contentType: false | ||
}) | ||
}; | ||
|
||
const setPreviewData = () => { | ||
return $.ajax({ | ||
url: previewUrl, | ||
method: 'POST', | ||
data: new FormData($form[0]), | ||
processData: false, | ||
contentType: false | ||
}); | ||
}; | ||
|
||
$previewButton.one('click', function () { | ||
if ($previewButton.data('auto-update')) { | ||
$form.on('click change keyup DOMSubtreeModified', function () { | ||
clearTimeout(triggerPreviewDataTimeout); | ||
triggerPreviewDataTimeout = setTimeout(triggerPreviewUpdate, 500); | ||
|
||
clearTimeout(autoUpdatePreviewDataTimeout); | ||
autoUpdatePreviewDataTimeout = setTimeout(setPreviewData, 300); | ||
}).trigger('change'); | ||
} | ||
}) | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Headless preview</title> | ||
<script> | ||
function go() { | ||
var querystring = window.location.search.replace(/^\?/, ''); | ||
var params = {}; | ||
querystring.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { | ||
params[decodeURIComponent(key)] = decodeURIComponent(value); | ||
}); | ||
|
||
var apiUrl = 'http://localhost:8000/api/v2/page_preview/1/?content_type=' + encodeURIComponent(params['content_type']) + '&token=' + encodeURIComponent(params['token']) + '&format=json'; | ||
fetch(apiUrl).then(function(response) { | ||
response.text().then(function(text) { | ||
document.body.innerText = text; | ||
}); | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body onload="go()"></body> | ||
</html> |
Oops, something went wrong.