Skip to content

Commit

Permalink
feat: Move editor files apart
Browse files Browse the repository at this point in the history
* In sub-directories:

  - static/editor/ (*.html)
  - _opam/share/learn-ocaml/editor/ (*.js|*.html)

* Rename one resource as well (s/new_exercise/new-exercise/)

* Ensure `learn-ocaml build --disable-editor` does not copy files into www.
  • Loading branch information
erikmd committed Aug 26, 2021
1 parent 299b4b3 commit 1b34ab1
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/editor/build.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ begin program "new_exercise"
"new_exercise.ml" ( comp = [ ppx_js ppx_ocplib_i18n] )
]
build_rules = [
"%{new_exercise_FULL_DST_DIR}%/new_exercise.js" (
"%{new_exercise_FULL_DST_DIR}%/new-exercise.js" (
build_target = true
sources = %byte_exe( p = "new_exercise" )
commands = [ {
Expand Down
5 changes: 2 additions & 3 deletions src/editor/dune
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,5 @@
(install
(section share)
(package learn-ocaml)
(files (editor.bc.js as www/js/editor.js)
(new_exercise.bc.js as www/js/new_exercise.js)))

(files (editor.bc.js as editor/js/editor.js)
(new_exercise.bc.js as editor/js/new-exercise.js)))
2 changes: 1 addition & 1 deletion src/editor/editor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ let () =
begin toolbar_button
~icon: "left" [%i"Metadata"] @@ fun () ->
Dom_html.window##.location##assign
(Js.string (api_server ^ "/new_exercise.html#id=" ^ id ^ "&action=open"));
(Js.string (api_server ^ "/new-exercise.html#id=" ^ id ^ "&action=open"));
Lwt.return ()
end;
begin toolbar_button
Expand Down
2 changes: 1 addition & 1 deletion src/editor/learnocaml_editor_tab.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let export_all_bar =
p [pcdata [%i"Export all exercises to a zip file"]]]]

let new_exercise_bar =
a ~a:[ a_href "new_exercise.html";
a ~a:[ a_href "new-exercise.html";
a_class [ "exercise" ] ] [
div ~a:[ a_class [ "descr" ] ] [
h1 [ pcdata [%i"New exercise"] ];
Expand Down
40 changes: 27 additions & 13 deletions src/main/learnocaml_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ module Args = struct
value & opt dir default & info ["contents-dir"] ~docv:"DIR" ~doc:
"directory containing the base learn-ocaml app contents"

let editor_dir =
let default =
readlink (Filename.dirname (Filename.dirname (Sys.executable_name))
/"share"/"learn-ocaml"/"editor")
in
value & opt dir default & info ["editor-dir"] ~docv:"DIR" ~doc:
"directory containing the learn-ocaml-editor app contents"

let enable opt doc =
value & vflag None [
Some true, info ["enable-"^opt] ~doc:("Enable "^doc);
Expand Down Expand Up @@ -195,6 +203,7 @@ module Args = struct

type t = {
contents_dir: string;
editor_dir: string;
try_ocaml: bool option;
lessons: bool option;
editor: bool option;
Expand All @@ -206,10 +215,10 @@ module Args = struct

let builder_conf =
let apply
contents_dir try_ocaml lessons editor exercises playground toplevel base_url
= { contents_dir; try_ocaml; lessons; editor; exercises; playground; toplevel; base_url }
contents_dir editor_dir try_ocaml lessons editor exercises playground toplevel base_url
= { contents_dir; editor_dir; try_ocaml; lessons; editor; exercises; playground; toplevel; base_url }
in
Term.(const apply $contents_dir $try_ocaml $lessons $editor $exercises $playground $toplevel $base_url)
Term.(const apply $contents_dir $editor_dir $try_ocaml $lessons $editor $exercises $playground $toplevel $base_url)

let repo_conf =
let apply repo_dir exercises_filtered jobs =
Expand Down Expand Up @@ -309,17 +318,22 @@ let main o =
else Lwt.return_none
in
let generate () =
let copy title src_dir =
Printf.printf "Updating %s at %s\n%!" title o.app_dir;
Lwt.catch
(fun () -> Lwt_utils.copy_tree src_dir o.app_dir)
(function
| Failure _ ->
Lwt.fail_with @@
Printf.sprintf "Failed to copy %s app contents from %s"
title (readlink src_dir)
| e -> Lwt.fail e)
in
if List.mem Build o.commands then
(Printf.printf "Updating app at %s\n%!" o.app_dir;
Lwt.catch
(fun () -> Lwt_utils.copy_tree o.builder.Builder.contents_dir o.app_dir)
(function
| Failure _ ->
Lwt.fail_with @@ Printf.sprintf
"Failed to copy base app contents from %s"
(readlink o.builder.Builder.contents_dir)
| e -> Lwt.fail e)
>>= fun () ->
(copy "learn-ocaml" o.builder.Builder.contents_dir >>= fun () ->
(if o.builder.Builder.editor <> Some false then
copy "learn-ocaml-editor" o.builder.Builder.editor_dir
else Lwt.return_unit) >>= fun () ->
let server_config = o.repo_dir/"server_config.json"
and www_server_config = o.app_dir/"server_config.json" in
let module ServerData = Learnocaml_data.Server in
Expand Down
2 changes: 1 addition & 1 deletion src/state/learnocaml_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ module Server (Json: JSON_CODEC) (Rh: REQUEST_HANDLER) = struct
| ["playground.html"]
| ["student-view.html"]
| ["description.html"]
| ["new_exercise.html"]
| ["new-exercise.html"]
| ["editor.html"]
| ["partition-view.html"]
| ("js"|"fonts"|"icons"|"css"|"static") :: _ as path),
Expand Down
7 changes: 6 additions & 1 deletion static/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ FILES = $(wildcard \
css/*.css\
) $(shell find js/mathjax ! -type d)

EDITOR_FILES = $(wildcard \
editor/*.html\
)

ALWAYS:
file-list: icons ALWAYS
@echo ${FILES} >$@
@echo ${FILES} ${EDITOR_FILES} >$@

icons:
@${MAKE} -C icons
Expand All @@ -27,6 +31,7 @@ dune: file-list
@echo ' (package learn-ocaml)' >>$@
@echo ' (files' >>$@
@$(foreach f,$(FILES),echo ' ($f as ${addprefix www/,$f})' >>$@;)
@$(foreach f,$(EDITOR_FILES),echo ' ($f as $f)' >>$@;)
@echo ' )' >>$@
@echo ')' >>$@

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<link rel="stylesheet" href="/css/learnocaml_tryocaml.css">
<script src="/js/ace/ace.js" type="text/javascript" charset="utf-8" defer></script>
<script language="JavaScript" src="/js/learnocaml-config.js"></script>
<script language="JavaScript" src="/js/new_exercise.js" defer></script>
<script language="JavaScript" src="/js/new-exercise.js" defer></script>
</head>

<body>
Expand Down

0 comments on commit 1b34ab1

Please sign in to comment.