Skip to content

Commit

Permalink
Small changes to sites documentation (#5748)
Browse files Browse the repository at this point in the history
- The site section stanza seems to need a list as an argument.
- The original demo code doesn't build (missing reference to lookup_dirs).

Signed-off-by: Jack Feser <[email protected]>

Co-authored-by: Etienne Millon <[email protected]>
  • Loading branch information
jfeser and emillon authored Jul 26, 2022
1 parent ac18854 commit ba17d11
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions doc/sites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ in the section ``share``. This package can add files to this ``site`` using the
.. code:: scheme
(install
(section (site mygui themes))
(section (site (mygui themes)))
(files
(layout.css as default/layout.css)
(ok.png as default/ok.png)
Expand Down Expand Up @@ -95,29 +95,28 @@ Then inside ``mygui.ml`` module the locations can be recovered and used:
(** Locations of the site for the themes *)
let themes_locations : string list = Mysites.Sites.themes
(** Merge the content of the directories in [dirs] *)
let rec readdirs dirs =
List.concat
(List.map
(fun dir -> Array.to_list (Sys.readdir dir))
(List.filter Sys.file_exists dirs))
(** Get the lists of the available themes *)
let find_available_themes () : string list = lookup_dirs themes_locations
(** Lookup a file in the directories *)
let rec lookup_file filename = function
| [] -> raise Not_found
| dir::dirs ->
let filename' = Filename.concat dir filename in
if Sys.file_exists filename' then filename'
else lookup_file filename dirs
(** Merge the contents of the directories in [dirs] *)
let lookup_dirs dirs =
List.filter Sys.file_exists dirs
|> List.map (fun dir -> Array.to_list (Sys.readdir dir))
|> List.concat
(** Get the available themes *)
let find_available_themes () = lookup_dirs themes_locations
(** [lookup_file name dirs] finds the first file called [name] in [dirs] *)
let lookup_file filename dirs =
List.find_map
(fun dir ->
let filename' = Filename.concat dir filename in
if Sys.file_exists filename' then Some filename' else None)
dirs
(** [lookup_theme_file theme file] get the [file] of the [theme] *)
let lookup_theme_file file theme =
lookup_file (Filename.concat theme file) themes_locations
let get_layout_css = lookup_theme_file "layout.css"
let get_ok_ico = lookup_theme_file "ok.png"
let get_ko_ico = lookup_theme_file "ko.png"
Expand Down

0 comments on commit ba17d11

Please sign in to comment.