forked from jupyter/nbviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
101 lines (76 loc) · 2.52 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import json
import shutil
import tempfile
import invoke
from notebook import DEFAULT_STATIC_FILES_PATH
APP_ROOT = os.path.dirname(__file__)
NPM_BIN = os.path.join(APP_ROOT, "node_modules", ".bin")
@invoke.task
def test():
invoke.run("nosetests -v")
@invoke.task
def bower():
invoke.run(
"cd {}/nbviewer/static &&".format(APP_ROOT) +
" {}/bower install".format(NPM_BIN) +
" --config.interactive=false --allow-root"
)
@invoke.task
def less(debug=False):
if debug:
extra = "--source-map"
else:
extra = " --clean-css='--s1 --advanced --compatibility=ie8'"
tmpl = (
"cd {}/nbviewer/static/less ".format(APP_ROOT) +
" && {}/lessc".format(NPM_BIN) +
" {1} "
" --include-path={2}"
" --autoprefix='> 1%'"
" {0}.less ../build/{0}.css"
)
args = (extra, DEFAULT_STATIC_FILES_PATH)
[
invoke.run(tmpl.format(less_file, *args))
for less_file in ["styles", "notebook", "slides"]
]
@invoke.task
def screenshots(root="http://localhost:5000/", dest="./screenshots"):
dest = os.path.abspath(dest)
script = """
root = "{root}"
urls = ({{name, url}} for name, url of {{
home: ""
dir: "github/ipython/ipython/tree/3.x/examples/"
user: "github/ipython/"
gists: "gist/fperez/"
notebook: "github/ipython/ipython/blob/3.x/examples/Notebook/Notebook%20Basics.ipynb"}})
screens = ({{name, w, h}} for name, [w, h] of {{
smartphone_portrait: [320, 480]
smartphone_landscape: [480, 320]
tablet_portrait: [768, 1024]
tablet_landscape: [1024, 768]
desktop_standard: [1280, 1024]
desktop_1080p: [1920, 1080]
}})
casper.start root
casper.each screens, (_, screen) ->
@then ->
@viewport screen.w, screen.h, ->
_.each urls, (_, page) ->
@thenOpen root + page.url, ->
@wait 1000
@then ->
@echo "#{{page.name}} #{{screen.name}}"
@capture "{dest}/#{{page.name}}-#{{screen.name}}.png"
casper.run()
""".format(root=root, dest=dest)
tmpdir = tempfile.mkdtemp()
tmpfile = os.path.join(tmpdir, "screenshots.coffee")
with open(tmpfile, "w+") as f:
f.write(script)
invoke.run("casperjs test {script}".format(script=tmpfile))
shutil.rmtree(tmpdir)