Skip to content

Commit

Permalink
Update for new json printer
Browse files Browse the repository at this point in the history
  • Loading branch information
cgay committed Dec 31, 2020
1 parent 2c24c12 commit 68440de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define module dylan-playground
respond-to-post,
server-root };
use json,
import: { encode-json, parse-json, <json-parse-error> };
import: { print-json, parse-json, <json-parse-error> };
use locators,
import: { <directory-locator>,
<file-locator>,
Expand Down
11 changes: 6 additions & 5 deletions play.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ define taglib playground ()
output("%s",
get-attribute(page-context(), $main-code-attr)
| get-query-value($main-code-attr)
| find-example-code($hello-world));
| find-example-code($default-example));
end;
tag library-code (page :: <playground-page>) ()
begin
Expand All @@ -95,9 +95,10 @@ define taglib playground ()
tag examples-menu (page :: <playground-page>) ()
for (v in $examples)
let name = v[0];
output("<option value=\"%s\">%s</option>\n", name, name);
output("<option value=\"%s\" %s>%s</option>\n",
name, (name = $default-example & "selected") | "", name);
end;
tag example (page :: <playground-page>) (name :: <string> = $hello-world)
tag example (page :: <playground-page>) (name :: <string> = $default-example)
output(find-example-code(name) | "example not found");
end;

Expand All @@ -119,7 +120,7 @@ define method respond-to-post (resource :: <build-and-run>, #key) => ()
else
result[$compiler-output-attr] := "Please enter some code.";
end;
encode-json(current-response(), result);
print-json(result, current-response());
end method;

define function generate-project-name () => (project-name :: <string>)
Expand Down Expand Up @@ -253,7 +254,7 @@ define module %s
use print;
use pprint;
use streams;
// from libraries with only one exported module
// from libraries with one module, named the same as the library.
use hash-algorithms;
use logging;
use regular-expressions;
Expand Down
15 changes: 8 additions & 7 deletions share.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ define method respond-to-post (resource :: <create-share>, #key) => ()
else
result["error"] := "nothing to share!";
end;
encode-json(current-response(), result);
print-json(result, current-response());
end method;

// Generate a key to use to find a playground share. The key is used in the
Expand Down Expand Up @@ -78,12 +78,13 @@ define function save-share (key :: <string>, text :: <string>) => ()
fs/with-open-file (stream = locator,
direction: #"output",
if-does-not-exist: #"create")
encode-json(stream, begin
let t = make(<string-table>);
t["format"] := $share-format;
t["code"] := text;
t
end);
print-json(begin
let t = make(<string-table>);
t["format"] := $share-format;
t["code"] := text;
t
end,
stream);
end;
end function;

Expand Down

0 comments on commit 68440de

Please sign in to comment.