Skip to content
Browse files

WIP

  • Loading branch information...
1 parent 1b911bd commit fe45624bf771696e458a1b79c41532125d29db4f Henri Binsztok committed
Showing with 11 additions and 35 deletions.
  1. +11 −35 server/server.opa
View
46 server/server.opa
@@ -1,46 +1,21 @@
-import stdlib.web.template
+// import stdlib.web.template
-db /wiki: stringmap(Template.default_content)
-db /wiki[_] = Template.text("This page is empty"): Template.default_content
+db /wiki: stringmap(string)
+db /wiki[_] = "This page is empty"
-@publish load_source(topic) = Template.to_source(Template.default, /wiki[topic])
-@publish load_rendered(topic) = Template.to_xhtml( Template.default, /wiki[topic])
-@publish save_source(topic, source) =
- match Template.try_parse(Template.default, source) with
- | ~{success} -> do /wiki[topic] <- success; Template.to_xhtml(Template.default, success)
- | {failure = _} -> do /wiki[topic] <- Template.text(source); <>Error: {source}</>
+@publish load_source(topic) = /wiki[topic]
+@publish load_rendered(topic) = /wiki[topic]
+@publish save_source(topic, source) = do /wiki[topic] <- source
remove_topic(topic) = Db.remove(@/wiki[topic])
-edit(topic) =
- do Dom.set_value(#edit_content, load_source(topic))
- do Dom.hide(#show_content)
- do Dom.show(#edit_content)
- do Dom.give_focus(#edit_content)
- void
-
-save(topic) =
- content = save_source(topic, Dom.get_value(#edit_content))
- do Dom.transform([#show_content <- content]);
- do Dom.hide(#edit_content);
- do Dom.show(#show_content);
- void
-
-display(topic) =
- Resource.styled_page("About {topic}", ["/resources/css.css"],
- <div id=#header><div id=#logo></div>About {topic}</div>
- <div class="show_content" id=#show_content ondblclick={_ -> edit(topic)}>
- {load_rendered(topic)}
- </>
- <textarea class="edit_content" id=#edit_content style="display:none"
- cols="40" rows="30" onblur={_ -> save(topic)}></>
- )
-
rest(topic) =
(
match HttpRequest.get_method() with
| {some = method} ->
match method with
- | {post} -> _ = save_source(topic, HttpRequest.get_body()?"") Resource.raw_status({success})
+ | {post} ->
+ do save_source(topic, HttpRequest.get_body()?"")
+ Resource.raw_status({success})
| {delete} -> do remove_topic(topic) Resource.raw_status({success})
| {get} -> Resource.raw_response(load_source(topic), "text/plain", {success})
| _ -> Resource.raw_status({method_not_allowed})
@@ -52,7 +27,8 @@ topic_of_path(path) = String.capitalize(String.to_lower(List.to_string_using("",
// for Adam: here return the list of urls of existing pages
list_topics() =
- ""
+ f(acc, x, y) = if acc=="" then x else "{acc},{x}"
+ StringMap.fold(f, "", /wiki)
id = parser
| id=([0-9a-z]+) -> Text.to_string(id)

0 comments on commit fe45624

Please sign in to comment.
Something went wrong with that request. Please try again.