summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason2015-01-09 22:45:32 -0700
committerjason2015-01-09 22:45:32 -0700
commited4b3887768ed6644a1d744b46ea244574c8f751 (patch)
treed0ac0261a4325f7ab4628505b9e44d812783b1d7
parent330bb81e4fa31b3d4a51ce68ee7e3bfbd4073357 (diff)
downloaddossier-ed4b3887768ed6644a1d744b46ea244574c8f751.tar.gz
dossier-ed4b3887768ed6644a1d744b46ea244574c8f751.zip
mithril abandonmentHEADmaster
-rw-r--r--src/dossier/Dossier.go3
-rw-r--r--src/dossier/templates/index.html67
-rw-r--r--src/dossier/wiki/handlers.go16
-rw-r--r--src/dossier/wiki/utils.go3
4 files changed, 49 insertions, 40 deletions
diff --git a/src/dossier/Dossier.go b/src/dossier/Dossier.go
index 5bc64c4..6b4fb81 100644
--- a/src/dossier/Dossier.go
+++ b/src/dossier/Dossier.go
@@ -4,6 +4,7 @@ import (
4 "dossier/wiki" 4 "dossier/wiki"
5 "log" 5 "log"
6 "net/http" 6 "net/http"
7 "path"
7) 8)
8 9
9func main() { 10func main() {
@@ -12,7 +13,7 @@ func main() {
12 http.HandleFunc("/wiki/save/", wiki.SaveHandler) 13 http.HandleFunc("/wiki/save/", wiki.SaveHandler)
13 http.HandleFunc("/wiki/", wiki.IndexHandler) 14 http.HandleFunc("/wiki/", wiki.IndexHandler)
14 15
15 http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) 16 http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(path.Join(".", "src", "dossier", "static")))))
16 17
17 log.Println("Starting... ") 18 log.Println("Starting... ")
18 http.ListenAndServe(":8080", nil) 19 http.ListenAndServe(":8080", nil)
diff --git a/src/dossier/templates/index.html b/src/dossier/templates/index.html
index 5445a61..3fc2e03 100644
--- a/src/dossier/templates/index.html
+++ b/src/dossier/templates/index.html
@@ -2,44 +2,49 @@
2<body></body> 2<body></body>
3<script src="/static/mithril.min.js"></script> 3<script src="/static/mithril.min.js"></script>
4<script> 4<script>
5 var wiki = {};
6 5
7 wiki.Page = function(data) { 6 (function (m) {
8 this.title = m.prop(data.title);
9 this.body = m.prop(data.body);
10 };
11 7
12 wiki.Page.load_page = function(title) { 8 var wiki = {};
13 return m.request({method: "GET", url: "/wiki/view/"+title, type: wiki.Page}).then(function(data){
14 return wiki.Page(data);
15 });
16 };
17
18 wiki.vm = (function() {
19 var vm = {};
20 9
21 vm.init = function() { 10 wiki.Page = function (data) {
22 vm.title = m.prop("title"); 11 this.title = m.prop(data.title);
23 vm.body = m.prop(""); 12 this.body = m.prop(data.body);
24 console.debug(vm); 13 this.loaded = m.prop(true);
25 }; 14 };
26 15
27 return vm; 16 wiki.Get = function (title) {
28 }()); 17 return m.request({ method: "GET", url: "/wiki/view/" + title, type: wiki.Page})
18 };
19 // view model
20 wiki.vm = (function () {
21 var vm = {};
22 vm.init = function (title) {
23 vm.resp = wiki.Get(title)
24 };
25 return vm;
26 }());
27
28 wiki.controller = function () {
29 var title = m.route.param('title');
30 wiki.vm.init(title);
31 };
29 32
30 wiki.controller = function() { 33 wiki.view = function (controller) {
31 wiki.vm.init(); 34 console.log(wiki.vm.resp())
32 }; 35 return m('div', {class:'body'}, [
36 m('div', {'class': 'title'}, wiki.vm.resp().body()),
37 m('div', {'class': 'content'}, wiki.vm.resp().title())
38 ]
39 );
40 };
33 41
34 wiki.view = function(controller) { 42 m.route.mode = 'hash';
35 wiki.Page.load_page("MainPage");
36 console.debug(wiki.vm.title);
37 };
38 43
39 m.route.mode = 'hash'; 44 m.route(document.body, "/MainPage", {
45 "/:title": wiki
46 });
47 }(m));
40 48
41 m.route(document.body, "/MainPage", {
42 "/:title": wiki
43 });
44</script> 49</script>
45</html> \ No newline at end of file 50</html>
diff --git a/src/dossier/wiki/handlers.go b/src/dossier/wiki/handlers.go
index ea1609c..a500113 100644
--- a/src/dossier/wiki/handlers.go
+++ b/src/dossier/wiki/handlers.go
@@ -9,15 +9,18 @@ import (
9) 9)
10 10
11func IndexHandler(w http.ResponseWriter, r *http.Request) { 11func IndexHandler(w http.ResponseWriter, r *http.Request) {
12 lp := path.Join(".", "templates", "index.html") 12 template_path := path.Join(".", "src", "dossier", "templates", "index.html")
13 log.Println(lp) 13 log.Println(template_path)
14 14
15 tmpl, err := template.ParseFiles(lp) 15 template, err := template.ParseFiles(template_path)
16 if err != nil { 16 if err != nil {
17 log.Println("500:", err)
17 fmt.Fprintf(w, "500: %s", err) 18 fmt.Fprintf(w, "500: %s", err)
18 return 19 return
19 } 20 }
20 tmpl.Execute(w, lp) 21 log.Println("executing")
22 template.Execute(w, template_path)
23 log.Println("executed")
21} 24}
22 25
23func SaveHandler(w http.ResponseWriter, r *http.Request) { 26func SaveHandler(w http.ResponseWriter, r *http.Request) {
@@ -50,13 +53,12 @@ func EditHandler(w http.ResponseWriter, r *http.Request) {
50func PageViewHandler(w http.ResponseWriter, r *http.Request) { 53func PageViewHandler(w http.ResponseWriter, r *http.Request) {
51 var title string = r.URL.Path[len("/wiki/view/"):] 54 var title string = r.URL.Path[len("/wiki/view/"):]
52 55
53 log.Println("200: ", title)
54
55 p, err := loadPage(title) 56 p, err := loadPage(title)
56 if err != nil { 57 if err != nil {
57 fmt.Fprintf(w, "error") 58 fmt.Fprintf(w, "error: %s", err)
58 return 59 return
59 } 60 }
60 61
61 fmt.Fprintf(w, "{\"title\": \"%s\", \"body\": \"%s\"}", p.Title, p.Body) 62 fmt.Fprintf(w, "{\"title\": \"%s\", \"body\": \"%s\"}", p.Title, p.Body)
63 log.Println("200: ", title)
62} 64}
diff --git a/src/dossier/wiki/utils.go b/src/dossier/wiki/utils.go
index 58e98f7..7e237b3 100644
--- a/src/dossier/wiki/utils.go
+++ b/src/dossier/wiki/utils.go
@@ -1,9 +1,10 @@
1package wiki 1package wiki
2 2
3import "io/ioutil" 3import "io/ioutil"
4import "path"
4 5
5func loadPage(title string) (*Page, error) { 6func loadPage(title string) (*Page, error) {
6 var filename string = title + FILE_EXTENSION 7 filename := path.Join(".", "src", "dossier", title+FILE_EXTENSION)
7 8
8 body, err := ioutil.ReadFile(filename) 9 body, err := ioutil.ReadFile(filename)
9 if err != nil { 10 if err != nil {