Skip to content

Commit 1b34ab1

Browse files
committed
feat: Move editor files apart
* 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.
1 parent 299b4b3 commit 1b34ab1

File tree

9 files changed

+40
-22
lines changed

9 files changed

+40
-22
lines changed

src/editor/build.ocp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ begin program "new_exercise"
2020
"new_exercise.ml" ( comp = [ ppx_js ppx_ocplib_i18n] )
2121
]
2222
build_rules = [
23-
"%{new_exercise_FULL_DST_DIR}%/new_exercise.js" (
23+
"%{new_exercise_FULL_DST_DIR}%/new-exercise.js" (
2424
build_target = true
2525
sources = %byte_exe( p = "new_exercise" )
2626
commands = [ {

src/editor/dune

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,5 @@
128128
(install
129129
(section share)
130130
(package learn-ocaml)
131-
(files (editor.bc.js as www/js/editor.js)
132-
(new_exercise.bc.js as www/js/new_exercise.js)))
133-
131+
(files (editor.bc.js as editor/js/editor.js)
132+
(new_exercise.bc.js as editor/js/new-exercise.js)))

src/editor/editor.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ let () =
523523
begin toolbar_button
524524
~icon: "left" [%i"Metadata"] @@ fun () ->
525525
Dom_html.window##.location##assign
526-
(Js.string (api_server ^ "/new_exercise.html#id=" ^ id ^ "&action=open"));
526+
(Js.string (api_server ^ "/new-exercise.html#id=" ^ id ^ "&action=open"));
527527
Lwt.return ()
528528
end;
529529
begin toolbar_button

src/editor/learnocaml_editor_tab.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let export_all_bar =
6464
p [pcdata [%i"Export all exercises to a zip file"]]]]
6565

6666
let new_exercise_bar =
67-
a ~a:[ a_href "new_exercise.html";
67+
a ~a:[ a_href "new-exercise.html";
6868
a_class [ "exercise" ] ] [
6969
div ~a:[ a_class [ "descr" ] ] [
7070
h1 [ pcdata [%i"New exercise"] ];

src/main/learnocaml_main.ml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ module Args = struct
155155
value & opt dir default & info ["contents-dir"] ~docv:"DIR" ~doc:
156156
"directory containing the base learn-ocaml app contents"
157157

158+
let editor_dir =
159+
let default =
160+
readlink (Filename.dirname (Filename.dirname (Sys.executable_name))
161+
/"share"/"learn-ocaml"/"editor")
162+
in
163+
value & opt dir default & info ["editor-dir"] ~docv:"DIR" ~doc:
164+
"directory containing the learn-ocaml-editor app contents"
165+
158166
let enable opt doc =
159167
value & vflag None [
160168
Some true, info ["enable-"^opt] ~doc:("Enable "^doc);
@@ -195,6 +203,7 @@ module Args = struct
195203

196204
type t = {
197205
contents_dir: string;
206+
editor_dir: string;
198207
try_ocaml: bool option;
199208
lessons: bool option;
200209
editor: bool option;
@@ -206,10 +215,10 @@ module Args = struct
206215

207216
let builder_conf =
208217
let apply
209-
contents_dir try_ocaml lessons editor exercises playground toplevel base_url
210-
= { contents_dir; try_ocaml; lessons; editor; exercises; playground; toplevel; base_url }
218+
contents_dir editor_dir try_ocaml lessons editor exercises playground toplevel base_url
219+
= { contents_dir; editor_dir; try_ocaml; lessons; editor; exercises; playground; toplevel; base_url }
211220
in
212-
Term.(const apply $contents_dir $try_ocaml $lessons $editor $exercises $playground $toplevel $base_url)
221+
Term.(const apply $contents_dir $editor_dir $try_ocaml $lessons $editor $exercises $playground $toplevel $base_url)
213222

214223
let repo_conf =
215224
let apply repo_dir exercises_filtered jobs =
@@ -309,17 +318,22 @@ let main o =
309318
else Lwt.return_none
310319
in
311320
let generate () =
321+
let copy title src_dir =
322+
Printf.printf "Updating %s at %s\n%!" title o.app_dir;
323+
Lwt.catch
324+
(fun () -> Lwt_utils.copy_tree src_dir o.app_dir)
325+
(function
326+
| Failure _ ->
327+
Lwt.fail_with @@
328+
Printf.sprintf "Failed to copy %s app contents from %s"
329+
title (readlink src_dir)
330+
| e -> Lwt.fail e)
331+
in
312332
if List.mem Build o.commands then
313-
(Printf.printf "Updating app at %s\n%!" o.app_dir;
314-
Lwt.catch
315-
(fun () -> Lwt_utils.copy_tree o.builder.Builder.contents_dir o.app_dir)
316-
(function
317-
| Failure _ ->
318-
Lwt.fail_with @@ Printf.sprintf
319-
"Failed to copy base app contents from %s"
320-
(readlink o.builder.Builder.contents_dir)
321-
| e -> Lwt.fail e)
322-
>>= fun () ->
333+
(copy "learn-ocaml" o.builder.Builder.contents_dir >>= fun () ->
334+
(if o.builder.Builder.editor <> Some false then
335+
copy "learn-ocaml-editor" o.builder.Builder.editor_dir
336+
else Lwt.return_unit) >>= fun () ->
323337
let server_config = o.repo_dir/"server_config.json"
324338
and www_server_config = o.app_dir/"server_config.json" in
325339
let module ServerData = Learnocaml_data.Server in

src/state/learnocaml_api.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ module Server (Json: JSON_CODEC) (Rh: REQUEST_HANDLER) = struct
400400
| ["playground.html"]
401401
| ["student-view.html"]
402402
| ["description.html"]
403-
| ["new_exercise.html"]
403+
| ["new-exercise.html"]
404404
| ["editor.html"]
405405
| ["partition-view.html"]
406406
| ("js"|"fonts"|"icons"|"css"|"static") :: _ as path),

static/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ FILES = $(wildcard \
1414
css/*.css\
1515
) $(shell find js/mathjax ! -type d)
1616

17+
EDITOR_FILES = $(wildcard \
18+
editor/*.html\
19+
)
20+
1721
ALWAYS:
1822
file-list: icons ALWAYS
19-
@echo ${FILES} >$@
23+
@echo ${FILES} ${EDITOR_FILES} >$@
2024

2125
icons:
2226
@${MAKE} -C icons
@@ -27,6 +31,7 @@ dune: file-list
2731
@echo ' (package learn-ocaml)' >>$@
2832
@echo ' (files' >>$@
2933
@$(foreach f,$(FILES),echo ' ($f as ${addprefix www/,$f})' >>$@;)
34+
@$(foreach f,$(EDITOR_FILES),echo ' ($f as $f)' >>$@;)
3035
@echo ' )' >>$@
3136
@echo ')' >>$@
3237

File renamed without changes.

static/new_exercise.html renamed to static/editor/new-exercise.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="stylesheet" href="/css/learnocaml_tryocaml.css">
1414
<script src="/js/ace/ace.js" type="text/javascript" charset="utf-8" defer></script>
1515
<script language="JavaScript" src="/js/learnocaml-config.js"></script>
16-
<script language="JavaScript" src="/js/new_exercise.js" defer></script>
16+
<script language="JavaScript" src="/js/new-exercise.js" defer></script>
1717
</head>
1818

1919
<body>

0 commit comments

Comments
 (0)