this repo has no description

Fully remove Assets from the document abstraction

+96 -55
+1 -4
src/document/renderer.ml
··· 24 24 type 'a t = { 25 25 name : string; 26 26 render : 'a -> Types.Block.t option -> Types.Document.t -> page list; 27 + filepath : 'a -> Url.Path.t -> Fpath.t; 27 28 } 28 29 29 30 let document_of_page ~syntax v = ··· 38 39 match syntax with 39 40 | Reason -> Reason.compilation_unit v 40 41 | OCaml -> ML.compilation_unit v 41 - 42 - let document_of_asset path (v : Odoc_model.Lang.Asset.t) = 43 - let url = Url.Path.from_identifier v.name in 44 - Types.Document.Asset { url; src = path }
+1 -6
src/document/types.ml
··· 196 196 end = 197 197 Source_page 198 198 199 - and Asset : sig 200 - type t = { url : Url.Path.t; src : Fpath.t } 201 - end = 202 - Asset 203 - 204 199 module Document = struct 205 - type t = Page of Page.t | Source_page of Source_page.t | Asset of Asset.t 200 + type t = Page of Page.t | Source_page of Source_page.t 206 201 end 207 202 208 203 let inline ?(attr = []) desc = Inline.{ attr; desc }
+3 -21
src/html/generator.ml
··· 535 535 if Config.as_json config then 536 536 Html_fragment_json.make_src ~config ~url ~breadcrumbs [ doc ] 537 537 else Html_page.make_src ~breadcrumbs ~header ~config ~url title [ doc ] 538 - 539 - let asset ~config { Asset.url; src } = 540 - let filename = Link.Path.as_filename ~is_flat:(Config.flat config) url in 541 - let content ppf = 542 - let ic = open_in_bin (Fpath.to_string src) in 543 - let len = 1024 in 544 - let buf = Bytes.create len in 545 - let rec loop () = 546 - let read = input ic buf 0 len in 547 - if read = len then ( 548 - Format.fprintf ppf "%s" (Bytes.to_string buf); 549 - loop ()) 550 - else if len > 0 then 551 - let buf = Bytes.sub buf 0 read in 552 - Format.fprintf ppf "%s" (Bytes.to_string buf) 553 - in 554 - loop (); 555 - close_in ic 556 - in 557 - { Odoc_document.Renderer.filename; content; children = [] } 558 538 end 559 539 560 540 let render ~config ~sidebar = function 561 541 | Document.Page page -> [ Page.page ~config ~sidebar page ] 562 542 | Source_page src -> [ Page.source_page ~config src ] 563 - | Asset asset -> [ Page.asset ~config asset ] 543 + 544 + let filepath ~config url = 545 + Link.Path.as_filename ~is_flat:(Config.flat config) url 564 546 565 547 let doc ~config ~xref_base_uri b = 566 548 let resolve = Link.Base xref_base_uri in
+2
src/html/generator.mli
··· 4 4 Odoc_document.Types.Document.t -> 5 5 Odoc_document.Renderer.page list 6 6 7 + val filepath : config:Config.t -> Odoc_document.Url.Path.t -> Fpath.t 8 + 7 9 val doc : 8 10 config:Config.t -> 9 11 xref_base_uri:string ->
+5 -3
src/latex/generator.ml
··· 40 40 ( List.map segment_to_string dir, 41 41 String.concat "." (List.map segment_to_string file) ) 42 42 43 - let filename url = 43 + let filename ?(add_ext = true) url = 44 44 let dir, file = get_dir_and_file url in 45 45 let file = Fpath.(v (String.concat dir_sep (dir @ [ file ]))) in 46 - Fpath.(add_ext "tex" file) 46 + if add_ext then Fpath.add_ext "tex" file else file 47 47 end 48 48 49 49 let style = function ··· 477 477 478 478 let render ~with_children = function 479 479 | Document.Page page -> [ Page.page ~with_children page ] 480 - | Source_page _ | Asset _ -> [] 480 + | Source_page _ -> [] 481 + 482 + let filepath url = Link.filename ~add_ext:false url
+2
src/latex/generator.mli
··· 6 6 with_children:bool -> 7 7 Odoc_document.Types.Document.t -> 8 8 Odoc_document.Renderer.page list 9 + 10 + val filepath : Odoc_document.Url.Path.t -> Fpath.t
+3 -1
src/manpage/generator.ml
··· 562 562 563 563 let render = function 564 564 | Document.Page page -> [ render_page page ] 565 - | Source_page _ | Asset _ -> [] 565 + | Source_page _ -> [] 566 + 567 + let filepath url = Link.as_filename ~add_ext:false url
+2
src/manpage/generator.mli
··· 1 1 val render : Odoc_document.Types.Document.t -> Odoc_document.Renderer.page list 2 + 3 + val filepath : Odoc_document.Url.Path.t -> Fpath.t
+2 -2
src/manpage/link.ml
··· 7 7 | `Module | `Page | `LeafPage | `Class -> name 8 8 | _ -> Format.asprintf "%a-%s" Odoc_document.Url.Path.pp_kind kind name 9 9 10 - let as_filename (url : Url.Path.t) = 10 + let as_filename ?(add_ext = true) (url : Url.Path.t) = 11 11 let components = Url.Path.to_list url in 12 12 let dir, path = 13 13 Url.Path.split ··· 17 17 let dir = List.map segment_to_string dir in 18 18 let path = String.concat "." (List.map segment_to_string path) in 19 19 let str_path = String.concat Fpath.dir_sep (dir @ [ path ]) in 20 - Fpath.(v str_path + ".3o") 20 + if add_ext then Fpath.(v str_path + ".3o") else Fpath.v str_path 21 21 22 22 let rec is_class_or_module_path (url : Url.Path.t) = 23 23 match url.kind with
+34 -11
src/odoc/fs.ml
··· 21 21 22 22 type file = Fpath.t 23 23 24 + let mkdir_p dir = 25 + let mkdir d = 26 + try Unix.mkdir (Fpath.to_string d) 0o755 with 27 + | Unix.Unix_error (Unix.EEXIST, _, _) -> () 28 + | exn -> raise exn 29 + in 30 + let rec dirs_to_create p acc = 31 + if Sys.file_exists (Fpath.to_string p) then acc 32 + else dirs_to_create (Fpath.parent p) (p :: acc) 33 + in 34 + List.iter (dirs_to_create dir []) ~f:mkdir 35 + 24 36 module File = struct 25 37 type t = file 26 38 ··· 92 104 Result.Error (`Msg err) 93 105 with Sys_error e -> Result.Error (`Msg e) 94 106 107 + let copy ~src ~dst = 108 + let with_ open_ close filename f = 109 + let c = open_ (Fpath.to_string filename) in 110 + Odoc_utils.Fun.protect ~finally:(fun () -> close c) (fun () -> f c) 111 + in 112 + let with_ic = with_ open_in_bin close_in_noerr in 113 + let with_oc = with_ open_out_bin close_out_noerr in 114 + try 115 + with_ic src (fun ic -> 116 + mkdir_p (dirname dst); 117 + with_oc dst (fun oc -> 118 + let len = 1024 in 119 + let buf = Bytes.create len in 120 + let rec loop () = 121 + let read = input ic buf 0 len in 122 + output oc buf 0 read; 123 + if read = len then loop () 124 + in 125 + Ok (loop ()))) 126 + with Sys_error e -> Result.Error (`Msg e) 127 + 95 128 let exists file = Sys.file_exists (Fpath.to_string file) 96 129 97 130 let rec of_segs_tl acc = function ··· 140 173 141 174 let contains ~parentdir f = Fpath.is_rooted ~root:parentdir f 142 175 143 - let mkdir_p dir = 144 - let mkdir d = 145 - try Unix.mkdir (Fpath.to_string d) 0o755 with 146 - | Unix.Unix_error (Unix.EEXIST, _, _) -> () 147 - | exn -> raise exn 148 - in 149 - let rec dirs_to_create p acc = 150 - if Sys.file_exists (Fpath.to_string p) then acc 151 - else dirs_to_create (Fpath.parent p) (p :: acc) 152 - in 153 - List.iter (dirs_to_create dir []) ~f:mkdir 176 + let mkdir_p dir = mkdir_p dir 154 177 155 178 let to_string = Fpath.to_string 156 179
+2
src/odoc/fs.mli
··· 91 91 92 92 val read : t -> (string, [> msg ]) result 93 93 94 + val copy : src:t -> dst:t -> (unit, [> msg ]) result 95 + 94 96 val exists : t -> bool 95 97 96 98 val of_segs : string list -> t
+4 -1
src/odoc/html_page.ml
··· 19 19 let render { html_config } sidebar page = 20 20 Odoc_html.Generator.render ~config:html_config ~sidebar page 21 21 22 - let renderer = { Odoc_document.Renderer.name = "html"; render } 22 + let filepath { html_config } url = 23 + Odoc_html.Generator.filepath ~config:html_config url 24 + 25 + let renderer = { Odoc_document.Renderer.name = "html"; render; filepath }
+3 -1
src/odoc/latex.ml
··· 5 5 let render args _sidebar page = 6 6 Odoc_latex.Generator.render ~with_children:args.with_children page 7 7 8 - let renderer = { Renderer.name = "latex"; render } 8 + let filepath _args url = Odoc_latex.Generator.filepath url 9 + 10 + let renderer = { Renderer.name = "latex"; render; filepath }
+3 -1
src/odoc/man_page.ml
··· 2 2 3 3 let render _ _sidebar page = Odoc_manpage.Generator.render page 4 4 5 - let renderer = { Renderer.name = "man"; render } 5 + let filepath _ url = Odoc_manpage.Generator.filepath url 6 + 7 + let renderer = { Renderer.name = "man"; render; filepath }
+10 -4
src/odoc/rendering.ml
··· 42 42 match doc with 43 43 | Odoc_document.Types.Document.Page { url; _ } -> url 44 44 | Source_page { url; _ } -> url 45 - | Asset { url; _ } -> url 46 45 in 47 46 let sidebar = 48 47 Odoc_utils.Option.map ··· 120 119 Odoc_file.load file >>= fun unit -> 121 120 match unit.content with 122 121 | Odoc_file.Asset_content unit -> 123 - let doc = Renderer.document_of_asset asset_file unit in 124 - render_document renderer ~output ~sidebar:None ~extra_suffix ~extra doc; 125 - Ok () 122 + let url = Odoc_document.Url.Path.from_identifier unit.name in 123 + let filename = renderer.Renderer.filepath extra url in 124 + let filename = 125 + match extra_suffix with 126 + | Some s -> Fpath.add_ext s filename 127 + | None -> filename 128 + in 129 + 130 + let dst = Fs.File.append output filename in 131 + Fs.File.copy ~src:asset_file ~dst 126 132 | Page_content _ | Unit_content _ | Impl_content _ -> 127 133 Error (`Msg "Expected an asset unit") 128 134
+19
src/utils/odoc_utils.ml
··· 80 80 module Option = struct 81 81 let map f = function None -> None | Some x -> Some (f x) 82 82 end 83 + 84 + module Fun = struct 85 + include Fun 86 + let protect ~(finally : unit -> unit) work = 87 + let finally_no_exn () = 88 + try finally () 89 + with e -> 90 + let bt = Printexc.get_raw_backtrace () in 91 + Printexc.raise_with_backtrace (Finally_raised e) bt 92 + in 93 + match work () with 94 + | result -> 95 + finally_no_exn (); 96 + result 97 + | exception work_exn -> 98 + let work_bt = Printexc.get_raw_backtrace () in 99 + finally_no_exn (); 100 + Printexc.raise_with_backtrace work_exn work_bt 101 + end