123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(*
* Copyright (c) 2014 Leo White <leo@lpw25.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openOdoc_modelmoduleSource=structtypet=FileofFpath.t|RootofFpath.tletppfmt=function|Filef->Format.fprintffmt"File: %a"Fpath.ppf|Rootf->Format.fprintffmt"File: %a"Fpath.ppfletto_stringf=Format.asprintf"%a"ppfendtypesource=Source.ttypeargs={html_config:Odoc_html.Config.t;source:sourceoption;assets:Fpath.tlist;}letrender{html_config;source=_;assets=_}page=Odoc_html.Generator.render~config:html_configpageletsource_documentssource_infosource~syntax=match(source_info,source)with|Some{Lang.Source_info.id;infos},Somesrc->(letfile=matchsrcwith|Source.Filef->f|Rootf->letopenOdoc_model.Paths.Identifierinletrecget_path_dir:SourceDir.t->Fpath.t=function|{iv=`SourceDir(d,f);_}->Fpath.(get_path_dird/f)|{iv=`Page_;_}->finletget_path:SourcePage.t->Fpath.t=function|{iv=`SourcePage(d,f);_}->Fpath.(get_path_dird/f)inget_pathidinmatchFs.File.readfilewith|Error(`Msgmsg)->Error.raise_warning(Error.filename_only"Couldn't load source file: %s"msg(Fs.File.to_stringfile));[]|Oksource_code->letsyntax_info=Syntax_highlighter.syntax_highlighting_locssource_codein[Odoc_document.Renderer.document_of_source~syntaxidsyntax_infoinfossource_code;])|Some{id;_},None->letfilename=Paths.Identifier.nameidinError.raise_warning(Error.filename_only"The --source should be passed when generating documents from \
compilation units that were compiled with --source-parent and \
--source-name"filename);[]|None,Somesrc->Error.raise_warning(Error.filename_only"--source argument is invalid on compilation unit that were not \
compiled with --source-parent and --source-name"(Source.to_stringsrc));[]|None,None->[]letlist_filter_mapflst=List.rev@@List.fold_left(funaccx->matchfxwithNone->acc|Somex->x::acc)[]lstletasset_documentsparent_idchildrenasset_paths=letasset_names=list_filter_map(functionLang.Page.Asset_childname->Somename|_->None)childreninletrecextractpathsname=matchpathswith|[]->(paths,(name,None))|x::xswhenFpath.basenamex=name->(xs,(name,Somex))|x::xs->letrest,elt=extractxsnamein(x::rest,elt)inletunmatched,paired_or_missing=letrecfoldmappathspaired=function|[]->(paths,paired)|name::names->letpaths,pair=extractpathsnameinfoldmappaths(pair::paired)namesinfoldmapasset_paths[]asset_namesinList.iter(funasset->Error.raise_warning(Error.filename_only"this asset was not declared as a child of %s"(Paths.Identifier.nameparent_id)(Fs.File.to_stringasset)))unmatched;list_filter_map(fun(name,path)->matchpathwith|None->Error.raise_warning(Error.filename_only"asset is missing."name);None|Somepath->letasset_id=Paths.Identifier.Mk.asset_file(parent_id,name)inleturl=Odoc_document.Url.Path.from_identifierasset_idinSome(Odoc_document.Types.Document.Asset{url;src=path}))paired_or_missingletextra_documentsargsinput~syntax=matchinputwith|Odoc_document.Renderer.CUunit->source_documentsunit.Lang.Compilation_unit.source_infoargs.source~syntax|Pagepage->asset_documentspage.Lang.Page.namepage.childrenargs.assetsletrenderer={Odoc_document.Renderer.name="html";render;extra_documents}