voterunner

quick and dirty votes and discussions
git clone https://git.ce9e.org/voterunner.git

commit
bcc991285b7fffbf45ece3da768d5bba2efd3c7d
parent
74e9047bd490b1183a34c4c81d206aa56d5d2861
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2016-09-15 18:23
Merge pull request #2 from xi/dwt-master

Add livereload support

Diffstat

A .gitignore 2 ++
M README.md 22 +++++++++++++++-------
M app.js 1 -
A bin/manage_db.sh 33 +++++++++++++++++++++++++++++++++
A bin/watch.py 31 +++++++++++++++++++++++++++++++
A watch_requirements.txt 1 +

6 files changed, 82 insertions, 8 deletions


diff --git a/.gitignore b/.gitignore

@@ -0,0 +1,2 @@
   -1     1 node_modules
   -1     2 data

diff --git a/README.md b/README.md

@@ -69,14 +69,22 @@ Voterunner is a [node.js](http://nodejs.org/) app using
   69    69 [PostgreSQL](http://www.postgresql.org/) as a database so the following
   70    70 lines will bring it up:
   71    71 
   72    -1     $ git clone https://git.gitorious.org/electomat/voterunner.git
   -1    72     $ git clone https://github.com/xi/voterunner
   73    73     $ cd voterunner
   74    74     $ npm install
   75    -1     $ export PORT=5000
   76    -1     $ export DATABASE_URL='postgresql://user:password@host/database'
   -1    75     $ bin/manage_db.sh init
   -1    76     $ bin/manage_db.sh start
   -1    77     $ export DATABASE_URL="postgresql://:@localhost/voterunner"
   77    78     $ node app.js
   78    -1         info  - socket.io started
   79    -1         info  - Listening on 5000
   -1    79         ... Listening on localhost:5000
   -1    80     $ open http://localhost:5000/  # introduction
   -1    81     $ open http://localhost:5000/my-topic/  # discuss on a topic
   -1    82 
   -1    83 For development it may be nice to automatically restart the app and refresh the
   -1    84 browser whenever you make changes:
   -1    85 
   -1    86     $ pip install -r watch_requirements.txt
   -1    87     $ bin/watch.py
   80    88 
   81    89 
   82    90 Development
@@ -102,7 +110,7 @@ The communication is done using socket.io sockets.
  102   110       ...
  103   111     });
  104   112 
  105    -1 ### setup
   -1   113 ### Setup
  106   114 
  107   115 These messages are used to set up the connection between client and
  108   116 server:
@@ -110,7 +118,7 @@ server:
  110   118 `register(topic, id)`
  111   119 :   register for id and topic. needs to be done before anything else.
  112   120 
  113    -1 ### change the Graph
   -1   121 ### Change the Graph
  114   122 
  115   123 These messages will be broadcasted to all sockets which are registered
  116   124 to the same topic as the one emitting in. The emitting socket must omit

diff --git a/app.js b/app.js

@@ -77,7 +77,6 @@ var tpl = function(file, data, res) {
   77    77 			} else {
   78    78 				return '';
   79    79 			}
   80    -1 
   81    80 		});
   82    81 
   83    82 		res.send(html);

diff --git a/bin/manage_db.sh b/bin/manage_db.sh

@@ -0,0 +1,33 @@
   -1     1 #!/bin/sh
   -1     2 
   -1     3 cd "$(dirname "$0")/.."
   -1     4 DB_DIR="$(pwd)/data/postgres"
   -1     5 mkdir -p $DB_DIR
   -1     6 
   -1     7 start() {
   -1     8 	pg_ctl start -w -D "$DB_DIR" -o "-h localhost" -o "-k '$DB_DIR'"
   -1     9 }
   -1    10 
   -1    11 stop() {
   -1    12 	pg_ctl stop -D "$DB_DIR"
   -1    13 }
   -1    14 
   -1    15 if [ "$1" = 'start' ]; then
   -1    16 	start
   -1    17 elif [ "$1" = 'stop' ]; then
   -1    18 	stop
   -1    19 elif [ "$1" = 'init' ]; then
   -1    20 	if test ! -d "$DB_DIR/base"; then
   -1    21 		pg_ctl initdb -D "$DB_DIR"
   -1    22 		start
   -1    23 		createdb -h "$DB_DIR" voterunner
   -1    24 		stop
   -1    25 	else
   -1    26 		echo "skipping"
   -1    27 	fi
   -1    28 elif [ "$1" = 'clean' ]; then
   -1    29 	rm -r "$DB_DIR"
   -1    30 else
   -1    31 	echo "invalid command"
   -1    32 	exit 1
   -1    33 fi

diff --git a/bin/watch.py b/bin/watch.py

@@ -0,0 +1,31 @@
   -1     1 #!/usr/bin/env python
   -1     2 
   -1     3 # install dependencies via `pip install -r watch_requirements.txt`
   -1     4 # install browser extension from http://livereload.com/extensions/
   -1     5 
   -1     6 from __future__ import print_function
   -1     7 
   -1     8 from livereload import Server, shell
   -1     9 
   -1    10 UNCOMPILED_FILES = ['static/*.js', 'static/*.css', 'static/test/*', 'README.md']
   -1    11 JS_SRC_FILES = ['static/src/*.js']
   -1    12 CSS_SRC_FILES = ['static/scss/*.scss']
   -1    13 
   -1    14 server = Server()
   -1    15 
   -1    16 
   -1    17 def watch(file_set, shell_command=None, delay=None):
   -1    18     for path in file_set:
   -1    19         server.watch(path, shell_command, delay=delay)
   -1    20 
   -1    21 
   -1    22 def show(file_set):
   -1    23     map(print, file_set)
   -1    24 
   -1    25 
   -1    26 if __name__ == '__main__':
   -1    27     watch(JS_SRC_FILES, shell('make static/voterunner.js static/markdown.js'))
   -1    28     watch(CSS_SRC_FILES, shell('make static/style.css'))
   -1    29     watch(UNCOMPILED_FILES)
   -1    30 
   -1    31     server.serve(liveport=35729)

diff --git a/watch_requirements.txt b/watch_requirements.txt

@@ -0,0 +1 @@
   -1     1 livereload