Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add odoc support-files-targets #232

Merged
merged 2 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/odoc/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ end = struct
~doc:"Compile a cmti, cmt, cmi or mld file to an odoc file."
end

module Support_files = struct
module Support_files_command = struct
let support_files without_theme output_dir =
Support_files.write ~without_theme output_dir

let without_theme =
let doc = "Don't copy the default theme to output directory." in
Arg.(value & flag & info ~doc ["without-theme"])

let cmd =
let without_theme =
let doc = "Don't copy the default theme to output directory." in
Arg.(value & flag & info ~doc ["without-theme"])
in
Term.(const support_files $ without_theme $ dst)

let info =
Expand All @@ -177,7 +177,7 @@ module Support_files = struct
end

module Css = struct
let cmd = Support_files.cmd
let cmd = Support_files_command.cmd

let info =
let doc =
Expand Down Expand Up @@ -375,6 +375,19 @@ module Targets = struct
let info =
Term.info "html-targets" ~doc:"TODO: Fill in."
end

module Support_files =
struct
let list_targets without_theme output_directory =
Support_files.print_filenames ~without_theme output_directory

let cmd =
Term.(const list_targets $ Support_files_command.without_theme $ dst)

let info =
Term.info "support-files-targets"
~doc:"Lists the names of the files that 'odoc support-files' outputs."
end
end

let () =
Expand All @@ -384,12 +397,13 @@ let () =
[ Compile.(cmd, info)
; Html.(cmd, info)
; Html_fragment.(cmd, info)
; Support_files.(cmd, info)
; Support_files_command.(cmd, info)
; Css.(cmd, info)
; Depends.Compile.(cmd, info)
; Depends.Html.(cmd, info)
; Targets.Compile.(cmd, info)
; Targets.Html.(cmd, info)
; Targets.Support_files.(cmd, info)
]
in
let default =
Expand Down
20 changes: 14 additions & 6 deletions src/odoc/support_files.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
let write ?(without_theme = false) output_dir =
let iter_files f ?(without_theme = false) output_directory =
let file name content =
let channel =
Fs.File.create ~directory:output_dir ~name
let name =
Fs.File.create ~directory:output_directory ~name
|> Fs.File.to_string
|> Pervasives.open_out
in
Pervasives.output_string channel content;
Pervasives.close_out channel
f name content
in

if not without_theme then begin
file "odoc.css" Css_file.content
end;
file "highlight.pack.js" Highlight_js.content

let write =
iter_files begin fun name content ->
let channel = Pervasives.open_out name in
Pervasives.output_string channel content;
Pervasives.close_out channel
end

let print_filenames =
iter_files (fun name _content -> print_endline name)
6 changes: 5 additions & 1 deletion src/odoc/support_files.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
(** Copies odoc's support files (default theme and JS files) to a specified
location. *)

val write : ?without_theme: bool -> Fs.Directory.t -> unit
val write : ?without_theme:bool -> Fs.Directory.t -> unit
(** [write ?without_theme output_dir] copies the support files to the
[output_dir]. If [without_theme] is [true] the theme will {e not} be
copied, the default value is [false]. *)

val print_filenames : ?without_theme:bool -> Fs.Directory.t -> unit
(** Prints, to STDOUT, the names of the files that calling [Support_files.write]
would output, one filename per line. *)