Skip to content

Commit

Permalink
added default 'unnamed exercise module' for exercise modules that are…
Browse files Browse the repository at this point in the history
… unnamed. without this, unnamed module exported as .txt files rather than .ml files
  • Loading branch information
russell-rozenbaum committed Dec 18, 2024
1 parent ccdd04d commit 47a69c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/haz3lweb/app/editors/mode/ExercisesMode.re
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ module Update = {

let export_exercise_module = (exercises: Model.t): unit => {
let exercise = Model.get_current(exercises);
let module_name = exercise.editors.module_name;
let filename = exercise.editors.module_name ++ ".ml";
let module_name =
StringUtil.isEmptyOrWhitespace(exercise.editors.module_name)
? "Unnamed Exercise Module" : exercise.editors.module_name;
let filename = module_name ++ ".ml";
let content_type = "text/plain";
let contents =
Exercise.export_module(module_name, {eds: exercise.editors});
Expand Down
5 changes: 5 additions & 0 deletions src/util/StringUtil.re
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ let unescape_linebreaks: string => string =
Re.Str.global_replace(Re.Str.regexp("\\\\n"), "\n");

let trim_leading = Re.Str.global_replace(Re.Str.regexp("\n[ ]*"), "\n");

let isEmptyOrWhitespace = str => {
let trimmed = String.trim(str);
String.length(trimmed) == 0;
};

0 comments on commit 47a69c3

Please sign in to comment.