fix demo index files
[mkws-moved-to-github.git] / test / widgets / Makefile
index 9e560c2..6433265 100644 (file)
@@ -1,13 +1,15 @@
 # Copyright (c) 2013-2014 Index Data ApS. http://indexdata.com
 
-PHANTOMJS_TIMEOUT=18
-PHANTOMJS=     ../node_modules/phantomjs/bin/phantomjs
+PHANTOMJS_TIMEOUT=30
+PHANTOMJS=     perl ../bin/bomb.pl --timeout=${PHANTOMJS_TIMEOUT} ../node_modules/phantomjs/bin/phantomjs
 IMAGES=                ./images
 SCREENSHOT_WIDTH_HEIGHT=       1000 1200
 PERL_SCRIPTS=  ../bin/bomb.pl
 PROG=  ../phantom/screenshot.js
 MD5=   $(shell which md5 md5sum)
-TIMEOUT=5
+TESTS= koha demos mike # koha.url
+TIMEOUT=4
+PREFIX=        test
 
 PHANTOMJS_URL= http://cph.koha.indexdata.com/cgi-bin/koha/opac-search.pl?q=sushi
 PHANTOMJS_URL= http://www.indexdata.com/
@@ -15,30 +17,61 @@ PHANTOMJS_URL=      http://www.indexdata.com/
 all: help
 
 clean:
-       rm -f mkws-error.png mkws-error.html 
+       rm -f index-*.html
+       rm -f iframe-*.html
        rm -f ${IMAGES}/*.png
-       rm -f ${IMAGES}/index.html
 
 distclean: clean
+       rm -f ${IMAGES}/*.png.tmp
 
 test: check
 
 screenshot:
-       file=$$(echo "${PHANTOMJS_URL}" | perl -npe 's,(\W),-,g'); \
-       ${PHANTOMJS} ${PROG} ${PHANTOMJS_URL} ${IMAGES}/$$file.png ${SCREENSHOT_WIDTH_HEIGHT} ${TIMEOUT}
+       file=${PREFIX}.$$(echo "${PHANTOMJS_URL}" | perl -npe 's,(\W),-,g; s/-$$//;'); \
+         ${PHANTOMJS} ${PROG} "${PHANTOMJS_URL}" ${IMAGES}/tmp.$$file.png ${SCREENSHOT_WIDTH_HEIGHT} ${TIMEOUT}; \
+         mv -f  ${IMAGES}/tmp.$$file.png  ${IMAGES}/$$file.png
 
-screenshots:
-       for i in $$(cat url.txt); do \
-         make PHANTOMJS_URL="$$i" TIMEOUT=4 screenshot; \
-       done; wait
-       make index
+screenshots: clean estimate-time iframe
+       set -e; \
+       for t in ${TESTS}; do \
+           for i in $$(cat url.$$t); do \
+               ${MAKE} PHANTOMJS_URL="$$i" TIMEOUT=4 PREFIX=$$t screenshot & sleep 1; \
+           done; wait; \
+           ${MAKE} PREFIX=$$t index; \
+       done
+       ${MAKE} index-widgets tidy help-url
+
+help-url:
+       @echo ""
+       @echo "Please check now: http://localhost/test/widgets/index.html"
+
+estimate-time:
+       @wc -l url.* | tail -n1 | awk '{print "Estimeate run time: " $$1 * (1 + '${TIMEOUT}') * 0.5, "seconds" }'
+       @echo ""
 
 index:
-       cd ${IMAGES}; ls *.png | perl -ne 'chomp; print qq{<h2>$$_</h2><img src="$$_"/><br/><br/><p/>\n}' > index.html
+       ( cd ${IMAGES}; ls -tr ${PREFIX}.*.png | perl -ne 'chomp; print qq{<h2>$$_</h2><img src="'${IMAGES}/'$$_"/><br/><br/><p/>\n}' ) > index-${PREFIX}.html
+
+index-widgets:
+       ls -t index-*html iframe-*.html | perl -ne 'chomp; print qq{<a href="$$_">$$_</a><br/>\n}' > index.html
+
+iframe: index-iframe-demo
+index-iframe-demo:
+       ( egrep example.indexdata.com url.demos | perl -ne 'chomp; print qq{<h2>$$_</h2><iframe width="900px" height="600px" src="$$_"></iframe>\n}' ) > iframe-demos-example.html
+       ( egrep -v example.indexdata.com url.demos | perl -ne 'chomp; print qq{<h2>$$_</h2><iframe width="900px" height="600px" src="$$_"></iframe>\n}' ) > iframe-demos-other.html
+
+tidy:
+       for i in iframe-demos*.html index*.html; do \
+           tidy -i -m $$i >/dev/null 2>&1; \
+           perl -i -npe 's,(^\s*</head>),<link type="text/css" rel="stylesheet" href="screenshots.css" /> $$1,' $$i; \
+       done
 
 help:
        @echo "make [ all | clean | distclean ]"
        @echo "     [ screenshots ]"
-       @echo "     [ screenshot | index ]"
+       @echo "     [ screenshot | index | iframe | tidy ]"
+       @echo ""
+       @echo "Examples: "
        @echo ""
+       @echo "make TESTS=mike screenshots"