Skip to content

Commit

Permalink
difficulty types
Browse files Browse the repository at this point in the history
  • Loading branch information
sabine committed Nov 27, 2023
1 parent 7db230b commit 8f3b9e3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/ocamlorg_data/data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module Paper : sig
end

module Exercise : sig
type difficulty = [ `Beginner | `Intermediate | `Advanced ]
type difficulty = Beginner | Intermediate | Advanced

type t = {
title : string;
Expand Down
10 changes: 6 additions & 4 deletions src/ocamlorg_frontend/components/learn_components.eml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ let book_recommendation ~(link : link) (book: Data.Book.t) =
<% ); %>
</div>
</div>
<a href="<%s link.href %>" class="flex gap-4 mt-4 text-legacy-primary-700 text-lg font-bold items-center underline leading-10">
<a href="<%s link.href %>" class="pt-4 text-primary hover:underline items-center leading-10">
<%s link.title %>
<%s! Icons.arrow_small_right "h-6 w-6" %>
</a>

let lang_manual_banner =
Expand Down Expand Up @@ -140,12 +139,12 @@ let exercise_card (exercise: Data.Exercise.t) =
<%s exercise.description %>
</div>
<div class="my-2.5">
<%s! skill_tag Data.Book.Beginner %>
<%s! skill_tag (match exercise.difficulty with | Data.Exercise.Beginner -> Data.Book.Beginner | Intermediate -> Intermediate | Advanced -> Advanced) %>
</div>
</a>

let exercises_block ~icon ~heading (exercises: Data.Exercise.t list) =
<div class="bg-legacy-default">
<div class="bg-legacy-default flex flex-col">
<div class="max-w-sm md:max-w-full flex flex-col">
<%s! block_heading ~icon ~title:"EXERCISES" ~heading %>
<div class="mt-6 grid gap-10 grid-cols-2 lg:grid-cols-4">
Expand All @@ -154,6 +153,9 @@ let exercises_block ~icon ~heading (exercises: Data.Exercise.t list) =
<% ); %>
</div>
</div>
<a href="<%s Url.exercises %>" class="pt-4 text-primary hover:underline items-center leading-10">
View all Exercises
</a>
</div>

let contribute_footer ~href =
Expand Down
12 changes: 6 additions & 6 deletions src/ocamlorg_frontend/pages/exercises.eml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ in
</div>

let danger = function
| `Beginner -> ""
| `Intermediate -> "☡"
| `Advanced -> "☡☡"
| Data.Exercise.Beginner -> ""
| Intermediate -> "☡"
| Advanced -> "☡☡"

let difficulty_to_string = function
| `Beginner -> "Beginner"
| `Intermediate -> "Intermediate"
| `Advanced -> "Advanced"
| Data.Exercise.Beginner -> "Beginner"
| Intermediate -> "Intermediate"
| Advanced -> "Advanced"

let render
?(difficulty_level = "All")
Expand Down
23 changes: 21 additions & 2 deletions src/ocamlorg_frontend/pages/learn.eml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Learn_layout.single_column_layout
%>
</div>

<div class="border my-6"></div>

<div class="grid gap-6 mt-6 lg:grid-cols-2">
<%s! Learn_components.book_recommendation
(Data.Book.get_by_slug "ocaml-programming-cs3110" |> Option.get)
Expand All @@ -85,6 +87,8 @@ Learn_layout.single_column_layout
~link:{href = Url.books; title = "See More Books"} %>
</div>

<div class="border my-6"></div>

<div class="mt-6">
<%s! Learn_components.exercises_block
~icon:Learn_components.beginner_section_icon
Expand Down Expand Up @@ -124,6 +128,8 @@ Learn_layout.single_column_layout
%>
</div>

<div class="border my-6"></div>

<div class="grid gap-6 mt-6 lg:grid-cols-2">
<%s! Learn_components.book_recommendation
(Data.Book.get_by_slug "real-world-ocaml" |> Option.get)
Expand All @@ -133,13 +139,26 @@ Learn_layout.single_column_layout
~link:{href = Url.books; title = "See More Books"} %>
</div>

<div class="border my-6"></div>

<div class="my-6">
<%s! Learn_components.exercises_block
~icon:Learn_components.intermediate_section_icon
~heading:"Practice with Exercises"
[ Data.Exercise.get_by_slug "55" |> Option.get
; Data.Exercise.get_by_slug "64" |> Option.get
; Data.Exercise.get_by_slug "68" |> Option.get
; Data.Exercise.get_by_slug "81" |> Option.get
] %>
</div>

<%s! Learn_components.lang_manual_banner %>

<h2 id="advanced_section" class="mt-16 mb-8 text-text_content text-3xl font-regular leading-9 tracking-widest">
<span class="text-primary font-bold">ELEVATED</span>
EXPERTISE
</h2>

<%s! Learn_components.lang_manual_banner %>

<div class="grid gap-6 mt-6 lg:grid-cols-2">
<%s! Learn_components.book_recommendation
(Data.Book.get_by_slug "ocaml-scientific-computing" |> Option.get)
Expand Down
6 changes: 3 additions & 3 deletions src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ let exercises req =
let all_exercises = Data.Exercise.all in
let difficulty_level = Dream.query req "difficulty_level" in
let compare_difficulty = function
| "beginner" -> ( = ) `Beginner
| "intermediate" -> ( = ) `Intermediate
| "advanced" -> ( = ) `Advanced
| "beginner" -> ( = ) Data.Exercise.Beginner
| "intermediate" -> ( = ) Data.Exercise.Intermediate
| "advanced" -> ( = ) Data.Exercise.Advanced
| _ -> Fun.const true
in
let by_difficulty level (exercise : Data.Exercise.t) =
Expand Down
14 changes: 5 additions & 9 deletions tool/ood-gen/lib/exercise.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Proficiency = struct
type t = [ `Beginner | `Intermediate | `Advanced ]
type t = Beginner | Intermediate | Advanced
[@@deriving show { with_path = false }]

let of_string = function
| "beginner" -> Ok `Beginner
| "intermediate" -> Ok `Intermediate
| "advanced" -> Ok `Advanced
| "beginner" -> Ok Beginner
| "intermediate" -> Ok Intermediate
| "advanced" -> Ok Advanced
| s -> Error (`Msg ("Unknown proficiency type: " ^ s))

let of_yaml = Utils.of_yaml of_string "Expected a string for difficulty type"
Expand Down Expand Up @@ -76,11 +76,7 @@ let all () = Utils.map_files decode "exercises/*.md"
let template () =
Format.asprintf
{|
type difficulty =
[ `Beginner
| `Intermediate
| `Advanced
]
type difficulty = Beginner | Intermediate | Advanced

type t =
{ title : string
Expand Down

0 comments on commit 8f3b9e3

Please sign in to comment.