From 5325336ea46e4347f4ca12d4daaeec6269ce6c7b Mon Sep 17 00:00:00 2001 From: rtz12 Date: Wed, 20 Jan 2016 19:34:19 +0100 Subject: Buildsystem verfeinert Dafuer JS temporaer kaputtgemacht diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..7b37dd5 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/.gitignore b/.gitignore index 4244e70..2d7ed77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ grilist.conf +package.json +.npm_update +node_modules/ assets/* diff --git a/Makefile b/Makefile index 109242b..26ba81f 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,58 @@ -CSS_FILES := $(shell find assets_src/css/ -maxdepth 1 -type f -name '*.css') -CSS_FILES := $(addprefix assets/, $(CSS_FILES:assets_src/%=%)) -LESS_FILES := $(shell find assets_src/css/ -maxdepth 1 -type f -name '*.less') -LESS_FILES := $(addprefix assets/, $(LESS_FILES:assets_src/%=%)) -LESS_FILES := $(LESS_FILES:.less=.css) -JS_FILES := $(shell find assets_src/js/ -maxdepth 1 -type f -name '*.js') -JS_FILES := $(addprefix assets/, $(JS_FILES:assets_src/%=%)) +include config.mk -all: $(CSS_FILES) $(LESS_FILES) $(JS_FILES) +CSS_FILES = $(patsubst assets_src/%, assets/%, $(shell find assets_src/css/ -type f -name '*.css')) +LESS_FILES = $(patsubst assets_src/%.less, assets/%.css, $(shell find assets_src/css/ -type f -name '*.less')) +JS_FILES = $(patsubst assets_src/%, assets/%, $(shell find assets_src/js/ -maxdepth 1 -type f -name '*.js')) + +BROWSERIFY := ./node_modules/browserify/bin/cmd.js +LESSC := ./node_modules/less/bin/lessc + +rewrite_imports = "s/(require\([\"'])lib/\1.\/lib/g" + +all: .npm_update $(CSS_FILES) $(LESS_FILES) $(JS_FILES) + +print_info: + @echo $(CSS_FILES) + @echo $(LESS_FILES) + @echo $(JS_FILES) + +.npm_update: package.json + touch $@ + npm install + +package.json: package.json.tpl config.mk + export NAME=$(NAME) &&\ + export VERSION=$(VERSION) &&\ + ./bin/template.awk < $< | sh > $@ assets/css/%.css: assets_src/css/%.css + @mkdir -p $(@D) cp $< $@ assets/css/%.css: assets_src/css/%.less - lessc $< > $@ + mkdir -p $(@D) + @echo lessc $< > $@ + @$(LESSC) $< > $@ -assets/js/%.js: assets_src/js/%.js - babel $< -o $@ +assets/js/%.js: assets_src/js/%.js .babelrc + @echo browserify $< -o $@ + @$(BROWSERIFY) --debug $< -o $@ -t babelify clean: -rm -- $(CSS_FILES) -rm -- $(LESS_FILES) -rm -- $(JS_FILES) + -rm -r -- .jsobj + +superclean: clean + -rm -- .npm_last_update + -rm -- package.json + +ultraclean: superclean + -rm -r -- node_modules run: all go run *.go -.PHONY: all clear run +.PHONY: all print_info clean superclean ultraclean run diff --git a/assets_src/js/lib/search.js b/assets_src/js/lib/search.js new file mode 100644 index 0000000..0cb33df --- /dev/null +++ b/assets_src/js/lib/search.js @@ -0,0 +1,40 @@ +var strokeTimeout = null; + +function instantSearch() { + if (strokeTimeout) { + clearTimeout(strokeTimeout); + } + strokeTimeout = setTimeout(doSearch, 150); +} + +function doSearch() { + value = document.getElementById("search").value; + + if (value === "") { + strokeTimeout = null; + document.getElementById("search-results").innerHTML = ""; + return; + } + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == XMLHttpRequest.DONE) { + if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined' || xhr.response === '404 not found') { + document.getElementById("search-results").innerHTML = ''; + return + } + if (value === "") { + document.getElementById("search-results").innerHTML = ""; + return; + } + + document.getElementById("search-results").innerHTML = xhr.response.replace(new RegExp('{ (.*?)(' + value + ')(.*?) }', 'gi'), "$1$2$3").replace(new RegExp('{ (.*?) }', 'gi'), '$1'); + } + } + xhr.open('GET', '/search/gril_instant/' + value, true); + xhr.send(null); + strokeTimeout = null; +} + +function clickSearchResult(resId) { + +} \ No newline at end of file diff --git a/assets_src/js/search.js b/assets_src/js/search.js deleted file mode 100644 index 0cb33df..0000000 --- a/assets_src/js/search.js +++ /dev/null @@ -1,40 +0,0 @@ -var strokeTimeout = null; - -function instantSearch() { - if (strokeTimeout) { - clearTimeout(strokeTimeout); - } - strokeTimeout = setTimeout(doSearch, 150); -} - -function doSearch() { - value = document.getElementById("search").value; - - if (value === "") { - strokeTimeout = null; - document.getElementById("search-results").innerHTML = ""; - return; - } - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState == XMLHttpRequest.DONE) { - if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined' || xhr.response === '404 not found') { - document.getElementById("search-results").innerHTML = ''; - return - } - if (value === "") { - document.getElementById("search-results").innerHTML = ""; - return; - } - - document.getElementById("search-results").innerHTML = xhr.response.replace(new RegExp('{ (.*?)(' + value + ')(.*?) }', 'gi'), "$1$2$3").replace(new RegExp('{ (.*?) }', 'gi'), '$1'); - } - } - xhr.open('GET', '/search/gril_instant/' + value, true); - xhr.send(null); - strokeTimeout = null; -} - -function clickSearchResult(resId) { - -} \ No newline at end of file diff --git a/bin/template.awk b/bin/template.awk new file mode 100755 index 0000000..f543506 --- /dev/null +++ b/bin/template.awk @@ -0,0 +1,56 @@ +#!/usr/bin/awk -f +#taken from werc [http://werc.cat-v.org/] +function pr(str) { + if(lastc !~ "[{(]") + gsub(/'/, "''", str) + printf "%s", str +} +function trans(c) { + printf "%s", end + + lastc = c + end = "\n" + if(c == "%") + end = "" + else if(c == "(") + printf "echo -n " + else if(c ~ "[})]") { + end = "'\n" + printf "echo -n '" + } +} + +BEGIN { + lastc = "{" + trans("}") +} +END { + print end +} + +/^%/ && $0 !~ /^%[{()}%]/ && lastc !~ /[({]/ { + trans("%") + print substr($0, 2) + next +} +{ + if(lastc == "%") + trans("}") + n = split($0, a, "%") + pr(a[1]) + for(i=2; i<=n; i++) { + c = substr(a[i], 1, 1) + rest = substr(a[i], 2) + + if((lastc !~ "[({]" && c ~ "[({]") || + (lastc == "{" && c == "}") || + (lastc == "(" && c == ")")) + trans(c) + else if(c == "%") + pr("%") + else + pr("%" c) + pr(rest) + } + pr("\n") +} diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..3a9328c --- /dev/null +++ b/config.mk @@ -0,0 +1,2 @@ +NAME := grilist +VERSION := 0.0.1 diff --git a/package.json.tpl b/package.json.tpl new file mode 100644 index 0000000..c2d075b --- /dev/null +++ b/package.json.tpl @@ -0,0 +1,10 @@ +{ + "name": "%($NAME%)", + "version": "%($VERSION%)", + "devDependencies": { + "less": "2.5.3", + "babel-preset-es2015": "6.3.13", + "browserify": "13.0.0", + "babelify": "7.2.0" + } +} -- cgit v0.10.1