Permalink
Browse files

New coding conventions of MLstate.

  • Loading branch information...
akoprow committed Feb 22, 2012
1 parent f913470 commit de93d16a7fb33a7dbae65f358ac0f4bf975fd63e
Showing with 175 additions and 175 deletions.
  1. +39 −37 hello_wiki_rest.opa
  2. +71 −73 hello_wiki_rest_client.opa
  3. +65 −65 hello_wiki_rest_client_customizable.opa
View
@@ -4,35 +4,35 @@ database stringmap(string) /wiki
database /wiki[_] = "This page is empty. Double click to edit"
exposed function load_source(topic) {
- /wiki[topic]
+ /wiki[topic];
}
exposed function load_rendered(topic) {
- source = load_source(topic)
- Markdown.xhtml_of_string(Markdown.default_options, source)
+ source = load_source(topic);
+ Markdown.xhtml_of_string(Markdown.default_options, source);
}
exposed function save_source(topic, source) {
- /wiki[topic] <- source
- load_rendered(topic)
+ /wiki[topic] <- source;
+ load_rendered(topic);
}
exposed function remove_topic(topic) {
- Db.remove(@/wiki[topic])
+ Db.remove(@/wiki[topic]);
}
function edit(topic) {
- Dom.set_value(#edit_content, load_source(topic))
- Dom.hide(#show_content)
- Dom.show(#edit_content)
- Dom.give_focus(#edit_content)
+ Dom.set_value(#edit_content, load_source(topic));
+ Dom.hide(#show_content);
+ Dom.show(#edit_content);
+ Dom.give_focus(#edit_content);
}
function save(topic) {
- content = save_source(topic, Dom.get_value(#edit_content))
- #show_content = content
- Dom.hide(#edit_content)
- Dom.show(#show_content)
+ content = save_source(topic, Dom.get_value(#edit_content));
+ #show_content = content;
+ Dom.hide(#edit_content);
+ Dom.show(#show_content);
}
function display(topic) {
@@ -43,44 +43,46 @@ function display(topic) {
</>
<textarea class="edit_content" id=#edit_content style="display:none"
cols="40" rows="30" onblur={function(_) { save(topic) }}></>
- )
+ );
}
function rest(topic) {
- match (HttpRequest.get_method()) {
+ match (HttpRequest.get_method()) {
case {some: method} :
- match (method) {
+ match (method) {
case {post}:
- _ = save_source(topic, HttpRequest.get_body() ? "")
- Resource.raw_status({success})
+ _ = save_source(topic, HttpRequest.get_body() ? "");
+ Resource.raw_status({success});
case {delete}:
- remove_topic(topic)
- Resource.raw_status({success})
+ remove_topic(topic);
+ Resource.raw_status({success});
case {get}:
- Resource.raw_response(load_source(topic), "text/plain", {success})
+ Resource.raw_response(load_source(topic), "text/plain", {success});
default:
- Resource.raw_status({method_not_allowed})
- }
+ Resource.raw_status({method_not_allowed});
+ }
default:
- Resource.raw_status({bad_request})
- }
+ Resource.raw_status({bad_request});
+ }
}
function topic_of_path(path) {
- String.capitalize(String.to_lower(List.to_string_using("", "", "::", path)))
+ String.capitalize(
+ String.to_lower(List.to_string_using("", "", "::", path))
+ );
}
function start(url) {
- match (url) {
- case {path: [] ... }: display("Hello")
- case {path: ["_rest_" | path] ...}: rest(topic_of_path(path))
- case {~path ...}: display(topic_of_path(path))
- }
+ match (url) {
+ case {path: [] ... }: display("Hello");
+ case {path: ["_rest_" | path] ...}: rest(topic_of_path(path));
+ case {~path ...}: display(topic_of_path(path));
+ }
}
-Server.start(Server.http,
- [ {resources: @static_include_directory("resources")}
- , {dispatch: start}
- ]
+Server.start(
+ Server.http,
+ [ {resources: @static_include_directory("resources")}
+ , {dispatch: start}
+ ]
)
-
View
@@ -1,113 +1,111 @@
import stdlib.tools.markdown
function uri_for_topic(topic) {
- Uri.of_absolute(
- {Uri.default_absolute with
- schema : {some: "http"},
- domain : "localhost",
- port : {some: 8080},
- path : ["_rest_", topic]
- }
- )
+ Uri.of_absolute(
+ {Uri.default_absolute with
+ schema : {some: "http"},
+ domain : "localhost",
+ port : {some: 8080},
+ path : ["_rest_", topic]
+ }
+ )
}
exposed function load_source(topic) {
- match (WebClient.Get.try_get(uri_for_topic(topic))) {
- case {failure: _} : "Error, could not connect"
- case {~success} :
- match (WebClient.Result.get_class(success)) {
- case {success}: success.content
- default: "Error {success.code}"
- }
- }
+ match (WebClient.Get.try_get(uri_for_topic(topic))) {
+ case { failure : _ }: "Error, could not connect";
+ case ~{ success }:
+ match (WebClient.Result.get_class(success)) {
+ case { success }: success.content;
+ default: "Error {success.code}";
+ }
+ }
}
exposed function load_rendered(topic) {
- source = load_source(topic)
- Markdown.xhtml_of_string(Markdown.default_options, source)
+ source = load_source(topic);
+ Markdown.xhtml_of_string(Markdown.default_options, source);
}
exposed function save_source(topic, source) {
- match (WebClient.Post.try_post(uri_for_topic(topic), source)) {
- case { failure: _ }:
- {failure: "Could not reach the distant server"}
+ match (WebClient.Post.try_post(uri_for_topic(topic), source)) {
+ case { failure: _ }: {failure: "Could not reach the distant server"};
case { success: s }:
- match (WebClient.Result.get_class(s)) {
- case {success}:
- {success: load_rendered(topic)}
- default:
- {failure: "Error {s.code}"}
- }
- }
+ match (WebClient.Result.get_class(s)) {
+ case { success }: {success : load_rendered(topic)};
+ default: {failure : "Error {s.code}"};
+ }
+ }
}
function remove_topic(topic) {
- _ = WebClient.Delete.try_delete(uri_for_topic(topic))
- void
+ _ = WebClient.Delete.try_delete(uri_for_topic(topic));
+ void;
}
function edit(topic) {
- #show_messages = <></>
- Dom.set_value(#edit_content, load_source(topic))
- Dom.hide(#show_content)
- Dom.show(#edit_content)
- Dom.give_focus(#edit_content)
+ #show_messages = <></>;
+ Dom.set_value(#edit_content, load_source(topic));
+ Dom.hide(#show_content);
+ Dom.show(#edit_content);
+ Dom.give_focus(#edit_content);
}
function save(topic) {
- match (save_source(topic, Dom.get_value(#edit_content))) {
+ match (save_source(topic, Dom.get_value(#edit_content))) {
case { ~success }:
- #show_content = success
- Dom.hide(#edit_content)
- Dom.show(#show_content)
+ #show_content = success;
+ Dom.hide(#edit_content);
+ Dom.show(#show_content);
case {~failure}:
- #show_messages = <>{failure}</>
- }
+ #show_messages = <>{failure}</>;
+ }
}
function 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={function(_) { edit(topic) }}>{load_rendered(topic)}</>
- <div class="show_messages" id=#show_messages />
- <textarea class="edit_content" id=#edit_content style="display:none" cols="40" rows="30" onblur={function(_) { save(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={function(_) { edit(topic) }}>{load_rendered(topic)}</>
+ <div class="show_messages" id=#show_messages />
+ <textarea class="edit_content" id=#edit_content style="display:none" cols="40" rows="30" onblur={function(_) { save(topic) }}></>
+ );
}
function rest(topic) {
- match (HttpRequest.get_method()) {
+ match (HttpRequest.get_method()) {
case {some: method}:
- match (method) {
- case {post}:
- _ = save_source(topic, HttpRequest.get_body()?"")
- Resource.raw_status({success})
- case {delete}:
- remove_topic(topic)
- Resource.raw_status({success})
- case {get}:
- Resource.source(load_source(topic), "text/plain")
- default:
- Resource.raw_status({method_not_allowed})
- }
- default:
- Resource.raw_status({bad_request})
- }
+ match (method) {
+ case { post }:
+ _ = save_source(topic, `?`(HttpRequest.get_body(), ""));
+ Resource.raw_status({success});
+ case { delete }: remove_topic(topic);
+ Resource.raw_status({success});
+ case { get }: Resource.source(load_source(topic), "text/plain");
+ default: Resource.raw_status({method_not_allowed});
+ }
+ default: Resource.raw_status({bad_request});
+ }
}
function topic_of_path(path) {
- String.capitalize(String.to_lower(List.to_string_using("", "", "::", path)))
+ String.capitalize(
+ String.to_lower(List.to_string_using("", "", "::", path))
+ );
}
function start(url) {
- match (url) {
- case {path: [] ... }: display("Hello")
- case {path: ["rest" | path] ...}: rest(topic_of_path(path))
- case {~path ...}: display(topic_of_path(path))
- }
+ match (url) {
+ case { path : [], ... }: display("Hello");
+ case { path : ["rest" | path], ... }: rest(topic_of_path(path));
+ case ~{ path, ... }: display(topic_of_path(path));
+ }
+
}
-Server.start(Server.http,
- [ {resources: @static_include_directory("resources")}
- , {dispatch: start}
- ]
+Server.start(
+ Server.http,
+ [ {resources: @static_include_directory("resources")}
+ , {dispatch: start}
+ ]
)
Oops, something went wrong.

0 comments on commit de93d16

Please sign in to comment.