Skip to content

Commit

Permalink
Merge branch 'master' of github.com:andychu/webpipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed Feb 17, 2015
2 parents da8d851 + d8afe60 commit a0f0275
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ to-html() {
jsont doc/html.jsont > $out
}

# TODO: Get rid of bad dependencies:
#
# webpipe docs -> pin -> docopt
make-dict() {
local body_filename=$1
pin --title-tag=h1 $body_filename
Expand All @@ -33,6 +36,7 @@ build() {
local base_in=$(basename $in .md) # For now, get rid of subdirs
local body=_tmp/$base_in-body.html

mkdir -p --verbose $(dirname $out)
echo "Building $in -> $body -> $out"

markdown $in >$body
Expand Down
15 changes: 15 additions & 0 deletions doc/latch-help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Usage: latch [ rebuild | serve ]

NOTE: This interface is subject to change.

latch rebuild <shell command> <files...>
Whenever one of the files change, runs the command to rebuild them.

latch serve <dir>
Start latch server. Your static file should have the string
'<!-- INSERT LATCH JS -->' in it. This will be replaced by JavaScript which
does a hanging GET on a rebuild event.

latch help
Show this help.

45 changes: 40 additions & 5 deletions latch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@
# latch.sh
#
# Usage:
# ...
# ./latch.sh <function>
#
# To reload edit docs quickly, do:
#
# ./latch.sh rebuild <command> <files>...
#
# This rebuilds files in a loop.
#
# Then.
#
# ./latch.sh serve
#
# TODO: There should be a 'latch run' command that does 'watch and 'serve'
# together. This is like 'webpipe run'.


set -o nounset

Expand Down Expand Up @@ -43,7 +57,7 @@ print-files() {

check-tools() {
which inotifywait >/dev/null \
|| die "inotifywait must be installed (sudo apt-get install inotifytools)."
|| die "inotifywait must be installed (sudo apt-get install inotify-tools)."

which which >/dev/null \
|| die "curl must be installed (sudo apt-get install curl)."
Expand Down Expand Up @@ -99,6 +113,21 @@ rebuild() {

local output="_tmp/$rel_output"

# HACK to sleep 100ms before building. Otherwise we get:
#
# Couldn't watch doc/tutorial.md: No such file or directory
# changed
# ./build.sh: line 68: doc/tutorial.md: No such file or directory
#
# What is happening is that:
# - we get notificatino of a changed inode
# - but vim hasn't actually saved the new file yet
# - we can't build without the new file
# - TODO: should we listen for another event in wait-vim? move_self vs
# modify?

sleep 0.1

# Rebuild
$build_cmd $changed $output

Expand Down Expand Up @@ -131,9 +160,6 @@ watch() {
done
}

# TODO: There should be a 'latch run' command that does 'watch and 'serve'
# together. This is like 'webpipe run'.

serve() {
export PYTHONPATH=$THIS_DIR:~/hg/json-template/python
$THIS_DIR/latch/latch.py "$@"
Expand All @@ -144,4 +170,13 @@ notify() {
curl --request POST http://$LATCH_HOST/-/latch/$name
}

help() {
cat $THIS_DIR/doc/latch-help.txt
}

if test $# -eq 0; then
help
exit 0
fi

"$@"
7 changes: 7 additions & 0 deletions latch/latch.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def CreateOptionsParser():
<script src="/-/latch.js"></script>
"""

LATCH_BODY = """\
<p id="latch-status">Waiting for latch...</p>
"""

class LatchRequestHandler(httpd.BaseRequestHandler):
"""
Notify latches
Expand Down Expand Up @@ -240,6 +244,9 @@ def do_GET(self):
if stripped == '<!-- INSERT LATCH JS -->':
out = LATCH_HEAD
log('replaced %r', stripped)
elif stripped == '<!-- INSERT LATCH HTML -->':
out = LATCH_BODY
log('replaced %r', stripped)
else:
out = line
self.wfile.write(out)
Expand Down
7 changes: 7 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,11 @@ exif() {
identify -format '%[exif:*]' "$@"
}

_link() { ln -s -f -v "$@"; }

install() {
_link $PWD/latch.sh ~/bin/latch
_link $PWD/wp.sh ~/bin/wp
}

"$@"

0 comments on commit a0f0275

Please sign in to comment.