diff options
| author | jason | 2014-12-31 09:03:35 -0700 |
|---|---|---|
| committer | jason | 2014-12-31 09:03:35 -0700 |
| commit | 330bb81e4fa31b3d4a51ce68ee7e3bfbd4073357 (patch) | |
| tree | 2f9cf8fd40c57d7220231168367ea90df3d351b5 | |
| parent | ff408df58ba6b7e21b9b0ce387c2fb477b19a53b (diff) | |
| download | dossier-330bb81e4fa31b3d4a51ce68ee7e3bfbd4073357.tar.gz dossier-330bb81e4fa31b3d4a51ce68ee7e3bfbd4073357.zip | |
stuff
| -rw-r--r-- | src/dossier/Dossier.go | 18 | ||||
| -rw-r--r-- | src/dossier/static/mithril.min.js | 8 | ||||
| -rw-r--r-- | src/dossier/templates/index.html | 45 | ||||
| -rw-r--r-- | src/dossier/wiki/handlers.go | 34 | ||||
| -rw-r--r-- | src/wiki/wiki.go | 22 |
5 files changed, 93 insertions, 34 deletions
diff --git a/src/dossier/Dossier.go b/src/dossier/Dossier.go index e5f60bb..5bc64c4 100644 --- a/src/dossier/Dossier.go +++ b/src/dossier/Dossier.go | |||
| @@ -1,9 +1,19 @@ | |||
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import "fmt" | 3 | import ( |
| 4 | import "net/http" | 4 | "dossier/wiki" |
| 5 | import "wiki/handlers" | 5 | "log" |
| 6 | "net/http" | ||
| 7 | ) | ||
| 6 | 8 | ||
| 7 | func main() { | 9 | func main() { |
| 8 | http.HandleFunc("/view/", viewHandler) | 10 | http.HandleFunc("/wiki/view/", wiki.PageViewHandler) |
| 11 | http.HandleFunc("/wiki/edit/", wiki.EditHandler) | ||
| 12 | http.HandleFunc("/wiki/save/", wiki.SaveHandler) | ||
| 13 | http.HandleFunc("/wiki/", wiki.IndexHandler) | ||
| 14 | |||
| 15 | http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) | ||
| 16 | |||
| 17 | log.Println("Starting... ") | ||
| 18 | http.ListenAndServe(":8080", nil) | ||
| 9 | } | 19 | } |
diff --git a/src/dossier/static/mithril.min.js b/src/dossier/static/mithril.min.js new file mode 100644 index 0000000..ff3793f --- /dev/null +++ b/src/dossier/static/mithril.min.js | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | /* | ||
| 2 | Mithril v0.1.27 | ||
| 3 | http://github.com/lhorie/mithril.js | ||
| 4 | (c) Leo Horie | ||
| 5 | License: MIT | ||
| 6 | */ | ||
| 7 | var m=function a(b,c){function d(a){C=a.document,D=a.location,F=a.cancelAnimationFrame||a.clearTimeout,E=a.requestAnimationFrame||a.setTimeout}function e(){var a,b=[].slice.call(arguments),c=!(null==b[1]||K.call(b[1])!==G||"tag"in b[1]||"subtree"in b[1]),d=c?b[1]:{},e="class"in d?"class":"className",f={tag:"div",attrs:{}},g=[];if(K.call(b[0])!=I)throw new Error("selector in m(selector, attrs, children) should be a string");for(;a=L.exec(b[0]);)if(""===a[1]&&a[2])f.tag=a[2];else if("#"===a[1])f.attrs.id=a[2];else if("."===a[1])g.push(a[2]);else if("["===a[3][0]){var h=M.exec(a[3]);f.attrs[h[1]]=h[3]||(h[2]?"":!0)}g.length>0&&(f.attrs[e]=g.join(" "));var i=c?b[2]:b[1];f.children=K.call(i)===H?i:b.slice(c?2:1);for(var j in d)f.attrs[j]=j===e?(f.attrs[j]||"")+" "+d[j]:d[j];return f}function f(a,b,d,e,i,k,l,m,n,o,p){if((null==i||null==i.toString())&&(i=""),"retain"===i.subtree)return k;var q=K.call(k),r=K.call(i);if(null==k||q!==r){if(null!=k)if(d&&d.nodes){var s=m-e,t=s+(r===H?i:k.nodes).length;h(d.nodes.slice(s,t),d.slice(s,t))}else k.nodes&&h(k.nodes,k);k=new i.constructor,k.tag&&(k={}),k.nodes=[]}if(r===H){for(var u=0,v=i.length;v>u;u++)K.call(i[u])===H&&(i=i.concat.apply([],i),u--);for(var w=[],x=k.length===i.length,y=0,z=1,A=2,B=3,D={},E=[],F=!1,u=0,v=k.length;v>u;u++)k[u]&&k[u].attrs&&null!=k[u].attrs.key&&(F=!0,D[k[u].attrs.key]={action:z,index:u});if(F){i.indexOf(null)>-1&&(i=i.filter(function(a){return null!=a}));for(var u=0,v=i.length;v>u;u++)if(i[u]&&i[u].attrs)if(null!=i[u].attrs.key){var L=i[u].attrs.key;D[L]=D[L]?{action:B,index:u,from:D[L].index,element:a.childNodes[D[L].index]||C.createElement("div")}:{action:A,index:u}}else E.push({index:u,element:a.childNodes[u]||C.createElement("div")});for(var M,O=Object.keys(D).map(function(a){return D[a]}),P=O.sort(function(a,b){return a.action-b.action||a.index-b.index}),Q=k.slice(),u=0;M=P[u];u++){if(M.action===z&&(h(k[M.index].nodes,k[M.index]),Q.splice(M.index,1)),M.action===A){var R=C.createElement("div");R.key=i[M.index].attrs.key,a.insertBefore(R,a.childNodes[M.index]||null),Q.splice(M.index,0,{attrs:{key:i[M.index].attrs.key},nodes:[R]})}M.action===B&&(a.childNodes[M.index]!==M.element&&null!==M.element&&a.insertBefore(M.element,a.childNodes[M.index]||null),Q[M.index]=k[M.from])}for(var u=0,v=E.length;v>u;u++){var M=E[u];a.insertBefore(M.element,a.childNodes[M.index]||null),Q[M.index]=k[M.index]}k=Q,k.nodes=[];for(var S,u=0;S=a.childNodes[u];u++)k.nodes.push(S)}for(var u=0,T=0,v=i.length;v>u;u++){var U=f(a,b,k,m,i[u],k[T],l,m+y||y,n,o,p);U!==c&&(U.nodes.intact||(x=!1),y+=U.$trusted?(U.match(/<[^\/]|\>\s*[^<]/g)||[]).length:K.call(U)===H?U.length:1,k[T++]=U)}if(!x){for(var u=0,v=i.length;v>u;u++)null!=k[u]&&w.push.apply(w,k[u].nodes);for(var V,u=0;V=k.nodes[u];u++)null!=V.parentNode&&w.indexOf(V)<0&&h([V],[k[u]]);i.length<k.length&&(k.length=i.length),k.nodes=w}}else if(null!=i&&r===G){i.attrs||(i.attrs={}),k.attrs||(k.attrs={});{var W=Object.keys(i.attrs);W.length>("key"in i.attrs?1:0)}if((i.tag!=k.tag||W.join()!=Object.keys(k.attrs).join()||i.attrs.id!=k.attrs.id)&&(k.nodes.length&&h(k.nodes),k.configContext&&typeof k.configContext.onunload===J&&k.configContext.onunload()),K.call(i.tag)!=I)return;var V,X=0===k.nodes.length;if(i.attrs.xmlns?o=i.attrs.xmlns:"svg"===i.tag?o="http://www.w3.org/2000/svg":"math"===i.tag&&(o="http://www.w3.org/1998/Math/MathML"),X?(V=i.attrs.is?o===c?C.createElement(i.tag,i.attrs.is):C.createElementNS(o,i.tag,i.attrs.is):o===c?C.createElement(i.tag):C.createElementNS(o,i.tag),k={tag:i.tag,attrs:W.length?g(V,i.tag,i.attrs,{},o):{},children:null!=i.children&&i.children.length>0?f(V,i.tag,c,c,i.children,k.children,!0,0,i.attrs.contenteditable?V:n,o,p):i.children,nodes:[V]},k.children&&!k.children.nodes&&(k.children.nodes=[]),"select"===i.tag&&i.attrs.value&&g(V,i.tag,{value:i.attrs.value},{},o),a.insertBefore(V,a.childNodes[m]||null)):(V=k.nodes[0],W.length&&g(V,i.tag,i.attrs,k.attrs,o),k.children=f(V,i.tag,c,c,i.children,k.children,!1,0,i.attrs.contenteditable?V:n,o,p),k.nodes.intact=!0,l===!0&&null!=V&&a.insertBefore(V,a.childNodes[m]||null)),typeof i.attrs.config===J){var Y=k.configContext=k.configContext||{},Z=function(a,b){return function(){return a.attrs.config.apply(a,b)}};p.push(Z(i,[V,!X,Y,k]))}}else if(typeof r!=J){var w;0===k.nodes.length?(i.$trusted?w=j(a,m,i):(w=[C.createTextNode(i)],a.nodeName.match(N)||a.insertBefore(w[0],a.childNodes[m]||null)),k="string number boolean".indexOf(typeof i)>-1?new i.constructor(i):i,k.nodes=w):k.valueOf()!==i.valueOf()||l===!0?(w=k.nodes,n&&n===C.activeElement||(i.$trusted?(h(w,k),w=j(a,m,i)):"textarea"===b?a.value=i:n?n.innerHTML=i:((1===w[0].nodeType||w.length>1)&&(h(k.nodes,k),w=[C.createTextNode(i)]),a.insertBefore(w[0],a.childNodes[m]||null),w[0].nodeValue=i)),k=new i.constructor(i),k.nodes=w):k.nodes.intact=!0}return k}function g(a,b,c,d,e){for(var f in c){var g=c[f],h=d[f];if(f in d&&h===g)"value"===f&&"input"===b&&a.value!=g&&(a.value=g);else{d[f]=g;try{if("config"===f)continue;if(typeof g===J&&0===f.indexOf("on"))a[f]=k(g,a);else if("style"===f&&null!=g&&K.call(g)===G){for(var i in g)(null==h||h[i]!==g[i])&&(a.style[i]=g[i]);for(var i in h)i in g||(a.style[i]="")}else null!=e?"href"===f?a.setAttributeNS("http://www.w3.org/1999/xlink","href",g):"className"===f?a.setAttribute("class",g):a.setAttribute(f,g):f in a&&"list"!==f&&"style"!==f&&"form"!==f&&"type"!==f?("input"!=f||a[f]!==g)&&(a[f]=g):a.setAttribute(f,g)}catch(j){if(j.message.indexOf("Invalid argument")<0)throw j}}}return d}function h(a,b){for(var c=a.length-1;c>-1;c--)if(a[c]&&a[c].parentNode){try{a[c].parentNode.removeChild(a[c])}catch(d){}b=[].concat(b),b[c]&&i(b[c])}0!=a.length&&(a.length=0)}function i(a){if(a.configContext&&typeof a.configContext.onunload===J&&a.configContext.onunload(),a.children)if(K.call(a.children)===H)for(var b,c=0;b=a.children[c];c++)i(b);else a.children.tag&&i(a.children)}function j(a,b,c){var d=a.childNodes[b];if(d){var e=1!=d.nodeType,f=C.createElement("span");e?(a.insertBefore(f,d||null),f.insertAdjacentHTML("beforebegin",c),a.removeChild(f)):d.insertAdjacentHTML("beforebegin",c)}else a.insertAdjacentHTML("beforeend",c);for(var g=[];a.childNodes[b]!==d;)g.push(a.childNodes[b]),b++;return g}function k(a,b){return function(c){c=c||event,e.redraw.strategy("diff"),e.startComputation();try{return a.call(b,c)}finally{_()}}}function l(a){var b=Q.indexOf(a);return 0>b?Q.push(a)-1:b}function m(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b}function n(){for(var a,b="all"===e.redraw.strategy(),c=0;a=T[c];c++)V[c]&&e.render(a,U[c].view(V[c]),b);Y&&(Y(),Y=null),W=null,X=new Date,e.redraw.strategy("diff")}function o(a){return a.slice(cb[e.route.mode].length)}function p(a,b,c){ab={};var d=c.indexOf("?");-1!==d&&(ab=t(c.substr(d+1,c.length)),c=c.substr(0,d));for(var f in b){if(f===c)return e.module(a,b[f]),!0;var g=new RegExp("^"+f.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(g.test(c))return c.replace(g,function(){for(var c=f.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,1,-2),g=0,h=c.length;h>g;g++)ab[c[g].replace(/:|\./g,"")]=decodeURIComponent(d[g]);e.module(a,b[f])}),!0}}function q(a){if(a=a||event,!a.ctrlKey&&!a.metaKey&&2!==a.which){a.preventDefault?a.preventDefault():a.returnValue=!1;var b=a.currentTarget||this,c="pathname"===e.route.mode&&b.search?t(b.search.slice(1)):{};e.route(b[e.route.mode].slice(cb[e.route.mode].length),c)}}function r(){"hash"!=e.route.mode&&D.hash?D.hash=D.hash:b.scrollTo(0,0)}function s(a,b){var c=[];for(var d in a){var e=b?b+"["+d+"]":d,f=a[d];c.push(null!=f&&K.call(f)===G?s(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f))}return c.join("&")}function t(a){for(var b=a.split("&"),c={},d=0,e=b.length;e>d;d++){var f=b[d].split("=");c[u(f[0])]=f[1]?u(f[1]):""}return c}function u(a){return decodeURIComponent(a.replace(/\+/g," "))}function v(a){var b=l(a);h(a.childNodes,R[b]),R[b]=c}function w(a){var b=e.prop();return a.then(b),b.then=function(b,c){return w(a.then(b,c))},b}function x(a,b){function c(a){l=a||j,n.map(function(a){l===i&&a.resolve(m)||a.reject(m)})}function d(a,b,c,d){if((null!=m&&K.call(m)===G||typeof m===J)&&typeof a===J)try{var f=0;a.call(m,function(a){f++||(m=a,b())},function(a){f++||(m=a,c())})}catch(g){e.deferred.onerror(g),m=g,c()}else d()}function f(){var j;try{j=m&&m.then}catch(n){return e.deferred.onerror(n),m=n,l=h,f()}d(j,function(){l=g,f()},function(){l=h,f()},function(){try{l===g&&typeof a===J?m=a(m):l===h&&"function"==typeof b&&(m=b(m),l=g)}catch(f){return e.deferred.onerror(f),m=f,c()}m===k?(m=TypeError(),c()):d(j,function(){c(i)},c,function(){c(l===g&&i)})})}var g=1,h=2,i=3,j=4,k=this,l=0,m=0,n=[];k.promise={},k.resolve=function(a){return l||(m=a,l=g,f()),this},k.reject=function(a){return l||(m=a,l=h,f()),this},k.promise.then=function(a,b){var c=new x(a,b);return l===i?c.resolve(m):l===j?c.reject(m):n.push(c),c.promise}}function y(a){return a}function z(a){if(!a.dataType||"jsonp"!==a.dataType.toLowerCase()){var d=new b.XMLHttpRequest;if(d.open(a.method,a.url,!0,a.user,a.password),d.onreadystatechange=function(){4===d.readyState&&(d.status>=200&&d.status<300?a.onload({type:"load",target:d}):a.onerror({type:"error",target:d}))},a.serialize===JSON.stringify&&a.data&&"GET"!==a.method&&d.setRequestHeader("Content-Type","application/json; charset=utf-8"),a.deserialize===JSON.parse&&d.setRequestHeader("Accept","application/json, text/*"),typeof a.config===J){var e=a.config(d,a);null!=e&&(d=e)}var f="GET"!==a.method&&a.data?a.data:"";if(f&&K.call(f)!=I&&f.constructor!=b.FormData)throw"Request data should be either be a string or FormData. Check the `serialize` option in `m.request`";return d.send(f),d}var g="mithril_callback_"+(new Date).getTime()+"_"+Math.round(1e16*Math.random()).toString(36),h=C.createElement("script");b[g]=function(d){C.body.removeChild(h),a.onload({type:"load",target:{responseText:d}}),b[g]=c},h.onerror=function(){return C.body.removeChild(h),a.onerror({type:"error",target:{status:500,responseText:JSON.stringify({error:"Error making jsonp request"})}}),b[g]=c,!1},h.onload=function(){return!1},h.src=a.url+(a.url.indexOf("?")>0?"&":"?")+(a.callbackKey?a.callbackKey:"callback")+"="+g+"&"+s(a.data||{}),C.body.appendChild(h)}function A(a,b,c){if("GET"===a.method&&"jsonp"!=a.dataType){var d=a.url.indexOf("?")<0?"?":"&",e=s(b);a.url=a.url+(e?d+e:"")}else a.data=c(b);return a}function B(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;d<c.length;d++){var e=c[d].slice(1);a=a.replace(c[d],b[e]),delete b[e]}return a}var C,D,E,F,G="[object Object]",H="[object Array]",I="[object String]",J="function",K={}.toString,L=/(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g,M=/\[(.+?)(?:=("|'|)(.*?)\2)?\]/,N=/^(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR)$/;d(b);var O,P={appendChild:function(a){O===c&&(O=C.createElement("html")),C.documentElement&&C.documentElement!==a?C.replaceChild(a,C.documentElement):C.appendChild(a),this.childNodes=C.childNodes},insertBefore:function(a){this.appendChild(a)},childNodes:[]},Q=[],R={};e.render=function(a,b,d){var e=[];if(!a)throw new Error("Please ensure the DOM element exists before rendering a template into it.");var g=l(a),i=a===C,j=i||a===C.documentElement?P:a;i&&"html"!=b.tag&&(b={tag:"html",attrs:{},children:b}),R[g]===c&&h(j.childNodes),d===!0&&v(a),R[g]=f(j,null,c,c,b,R[g],!1,0,null,c,e);for(var k=0,m=e.length;m>k;k++)e[k]()},e.trust=function(a){return a=new String(a),a.$trusted=!0,a},e.prop=function(a){return(null!=a&&K.call(a)===G||typeof a===J)&&typeof a.then===J?w(a):m(a)};var S,T=[],U=[],V=[],W=null,X=0,Y=null,Z=16;e.module=function(a,b){var c=T.indexOf(a);0>c&&(c=T.length);var d=!1;if(V[c]&&typeof V[c].onunload===J){var f={preventDefault:function(){d=!0}};V[c].onunload(f)}if(!d){e.redraw.strategy("all"),e.startComputation(),T[c]=a;var g=S=b,h=new b.controller;return g===S&&(V[c]=h,U[c]=b),_(),V[c]}},e.redraw=function(a){W&&a!==!0?(new Date-X>Z||E===b.requestAnimationFrame)&&(W>0&&F(W),W=E(n,Z)):(n(),W=E(function(){W=null},Z))},e.redraw.strategy=e.prop();var $=0;e.startComputation=function(){$++},e.endComputation=function(){$=Math.max($-1,0),0===$&&e.redraw()};var _=function(){"none"==e.redraw.strategy()?($--,e.redraw.strategy("diff")):e.endComputation()};e.withAttr=function(a,b){return function(c){c=c||event;var d=c.currentTarget||this;b(a in d?d[a]:d.getAttribute(a))}};var ab,bb,cb={pathname:"",hash:"#",search:"?"},db=function(){};return e.route=function(){if(0===arguments.length)return bb;if(3===arguments.length&&K.call(arguments[1])===I){var a=arguments[0],c=arguments[1],d=arguments[2];db=function(b){var f=bb=o(b);p(a,d,f)||e.route(c,!0)};var f="hash"===e.route.mode?"onhashchange":"onpopstate";b[f]=function(){bb!=o(D[e.route.mode])&&db(D[e.route.mode])},Y=r,b[f]()}else if(arguments[0].addEventListener){{var g=arguments[0];arguments[1],arguments[2]}g.href=("pathname"!==e.route.mode?D.pathname:"")+cb[e.route.mode]+this.attrs.href,g.removeEventListener("click",q),g.addEventListener("click",q)}else if(K.call(arguments[0])===I){bb=arguments[0];var h=arguments[1]||{},i=bb.indexOf("?"),j=i>-1?t(bb.slice(i+1)):{};for(var k in h)j[k]=h[k];var l=s(j),m=i>-1?bb.slice(0,i):bb;l&&(bb=m+(-1===m.indexOf("?")?"?":"&")+l);var n=(3===arguments.length?arguments[2]:arguments[1])===!0;b.history.pushState?(Y=function(){b.history[n?"replaceState":"pushState"](null,C.title,cb[e.route.mode]+bb),r()},db(cb[e.route.mode]+bb)):D[e.route.mode]=bb}},e.route.param=function(a){if(!ab)throw new Error("You must call m.route(element, defaultRoute, routes) before calling m.route.param()");return ab[a]},e.route.mode="search",e.deferred=function(){var a=new x;return a.promise=w(a.promise),a},e.deferred.onerror=function(a){if("[object Error]"===K.call(a)&&!a.constructor.toString().match(/ Error/))throw a},e.sync=function(a){function b(a,b){return function(e){return g[a]=e,b||(c="reject"),0===--f&&(d.promise(g),d[c](g)),e}}var c="resolve",d=e.deferred(),f=a.length,g=new Array(f);if(a.length>0)for(var h=0;h<a.length;h++)a[h].then(b(h,!0),b(h,!1));else d.resolve([]);return d.promise},e.request=function(a){a.background!==!0&&e.startComputation();var b=e.deferred(),c=a.dataType&&"jsonp"===a.dataType.toLowerCase(),d=a.serialize=c?y:a.serialize||JSON.stringify,f=a.deserialize=c?y:a.deserialize||JSON.parse,g=a.extract||function(a){return 0===a.responseText.length&&f===JSON.parse?null:a.responseText};return a.url=B(a.url,a.data),a=A(a,a.data,d),a.onload=a.onerror=function(c){try{c=c||event;var d=("load"===c.type?a.unwrapSuccess:a.unwrapError)||y,h=d(f(g(c.target,a)));if("load"===c.type)if(K.call(h)===H&&a.type)for(var i=0;i<h.length;i++)h[i]=new a.type(h[i]);else a.type&&(h=new a.type(h));b["load"===c.type?"resolve":"reject"](h)}catch(c){e.deferred.onerror(c),b.reject(c)}a.background!==!0&&e.endComputation()},z(a),b.promise(a.initialValue),b.promise},e.deps=function(a){return d(b=a||b),b},e.deps.factory=a,e}("undefined"!=typeof window?window:{});"undefined"!=typeof module&&null!==module&&module.exports?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m}); | ||
| 8 | //# sourceMappingURL=mithril.min.js.map \ No newline at end of file | ||
diff --git a/src/dossier/templates/index.html b/src/dossier/templates/index.html new file mode 100644 index 0000000..5445a61 --- /dev/null +++ b/src/dossier/templates/index.html | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | <html> | ||
| 2 | <body></body> | ||
| 3 | <script src="/static/mithril.min.js"></script> | ||
| 4 | <script> | ||
| 5 | var wiki = {}; | ||
| 6 | |||
| 7 | wiki.Page = function(data) { | ||
| 8 | this.title = m.prop(data.title); | ||
| 9 | this.body = m.prop(data.body); | ||
| 10 | }; | ||
| 11 | |||
| 12 | wiki.Page.load_page = function(title) { | ||
| 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 | |||
| 21 | vm.init = function() { | ||
| 22 | vm.title = m.prop("title"); | ||
| 23 | vm.body = m.prop(""); | ||
| 24 | console.debug(vm); | ||
| 25 | }; | ||
| 26 | |||
| 27 | return vm; | ||
| 28 | }()); | ||
| 29 | |||
| 30 | wiki.controller = function() { | ||
| 31 | wiki.vm.init(); | ||
| 32 | }; | ||
| 33 | |||
| 34 | wiki.view = function(controller) { | ||
| 35 | wiki.Page.load_page("MainPage"); | ||
| 36 | console.debug(wiki.vm.title); | ||
| 37 | }; | ||
| 38 | |||
| 39 | m.route.mode = 'hash'; | ||
| 40 | |||
| 41 | m.route(document.body, "/MainPage", { | ||
| 42 | "/:title": wiki | ||
| 43 | }); | ||
| 44 | </script> | ||
| 45 | </html> \ No newline at end of file | ||
diff --git a/src/dossier/wiki/handlers.go b/src/dossier/wiki/handlers.go index 4f241eb..ea1609c 100644 --- a/src/dossier/wiki/handlers.go +++ b/src/dossier/wiki/handlers.go | |||
| @@ -2,11 +2,26 @@ package wiki | |||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "html/template" | ||
| 6 | "log" | ||
| 5 | "net/http" | 7 | "net/http" |
| 8 | "path" | ||
| 6 | ) | 9 | ) |
| 7 | 10 | ||
| 11 | func IndexHandler(w http.ResponseWriter, r *http.Request) { | ||
| 12 | lp := path.Join(".", "templates", "index.html") | ||
| 13 | log.Println(lp) | ||
| 14 | |||
| 15 | tmpl, err := template.ParseFiles(lp) | ||
| 16 | if err != nil { | ||
| 17 | fmt.Fprintf(w, "500: %s", err) | ||
| 18 | return | ||
| 19 | } | ||
| 20 | tmpl.Execute(w, lp) | ||
| 21 | } | ||
| 22 | |||
| 8 | func SaveHandler(w http.ResponseWriter, r *http.Request) { | 23 | func SaveHandler(w http.ResponseWriter, r *http.Request) { |
| 9 | var title string = r.URL.Path[len("/save/"):] | 24 | var title string = r.URL.Path[len("/wiki/save/"):] |
| 10 | body := r.FormValue("body") | 25 | body := r.FormValue("body") |
| 11 | p := &Page{Title: title, Body: []byte(body)} | 26 | p := &Page{Title: title, Body: []byte(body)} |
| 12 | var err error = p.Save() | 27 | var err error = p.Save() |
| @@ -14,7 +29,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) { | |||
| 14 | fmt.Fprintf(w, "500: %s", err) | 29 | fmt.Fprintf(w, "500: %s", err) |
| 15 | return | 30 | return |
| 16 | } | 31 | } |
| 17 | http.Redirect(w, r, "/view/"+title, http.StatusFound) | 32 | http.Redirect(w, r, "/wiki/view/"+title, http.StatusFound) |
| 18 | } | 33 | } |
| 19 | 34 | ||
| 20 | func EditHandler(w http.ResponseWriter, r *http.Request) { | 35 | func EditHandler(w http.ResponseWriter, r *http.Request) { |
| @@ -23,22 +38,25 @@ func EditHandler(w http.ResponseWriter, r *http.Request) { | |||
| 23 | if err != nil { | 38 | if err != nil { |
| 24 | p = &Page{Title: title} | 39 | p = &Page{Title: title} |
| 25 | } | 40 | } |
| 26 | fmt.Fprintf(w, "<h1>Editing %s</h1>"+ | 41 | fmt.Fprintf(w, "<script src='/static/mithril.min.js'>"+ |
| 27 | "<form action=\"/save/%s\" method=\"POST\">"+ | 42 | "<h1>Editing %s</h1>"+ |
| 43 | "<form action=\"/wiki/save/%s\" method=\"POST\">"+ | ||
| 28 | "<textarea name=\"body\">%s</textarea><br>"+ | 44 | "<textarea name=\"body\">%s</textarea><br>"+ |
| 29 | "<input type=\"submit\" value=\"Save\">"+ | 45 | "<input type=\"submit\" value=\"Save\">"+ |
| 30 | "</form>", | 46 | "</form>", |
| 31 | p.Title, p.Title, p.Body) | 47 | p.Title, p.Title, p.Body) |
| 32 | } | 48 | } |
| 33 | 49 | ||
| 34 | func PageHandler(w http.ResponseWriter, r *http.Request) { | 50 | func PageViewHandler(w http.ResponseWriter, r *http.Request) { |
| 35 | var title string = r.URL.Path[len("/view/"):] | 51 | var title string = r.URL.Path[len("/wiki/view/"):] |
| 52 | |||
| 53 | log.Println("200: ", title) | ||
| 36 | 54 | ||
| 37 | p, err := loadPage(title) | 55 | p, err := loadPage(title) |
| 38 | if err != nil { | 56 | if err != nil { |
| 39 | http.Redirect(w, r, "/edit/"+title, http.StatusFound) | 57 | fmt.Fprintf(w, "error") |
| 40 | return | 58 | return |
| 41 | } | 59 | } |
| 42 | 60 | ||
| 43 | fmt.Fprintf(w, "<h1>%s</h1><hr>%s", p.Title, p.Body) | 61 | fmt.Fprintf(w, "{\"title\": \"%s\", \"body\": \"%s\"}", p.Title, p.Body) |
| 44 | } | 62 | } |
diff --git a/src/wiki/wiki.go b/src/wiki/wiki.go deleted file mode 100644 index 2f80194..0000000 --- a/src/wiki/wiki.go +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | package wiki | ||
| 2 | |||
| 3 | import "io/ioutil" | ||
| 4 | |||
| 5 | type Page struct { | ||
| 6 | Title string | ||
| 7 | Body []byte // markdown filled body | ||
| 8 | } | ||
| 9 | |||
| 10 | func (p *Page) save() error { | ||
| 11 | filename := p.Title + ".md" | ||
| 12 | return ioutil.WriteFile(filename, p.Body, 0600) | ||
| 13 | } | ||
| 14 | |||
| 15 | func loadPage(title string) (*Page, error) { | ||
| 16 | filename := title + ".md" | ||
| 17 | body, err := ioutil.ReadFile(filename) | ||
| 18 | if err != nil { | ||
| 19 | return nil, err | ||
| 20 | } | ||
| 21 | return &Page{Title title, Body body}, nil | ||
| 22 | } | ||