213 (* session_info *) |
213 (* session_info *) |
214 |
214 |
215 type session_info = |
215 type session_info = |
216 {name: string, parent: string, session: string, path: string list, html_prefix: Path.T, |
216 {name: string, parent: string, session: string, path: string list, html_prefix: Path.T, |
217 info: bool, doc_format: string, doc_graph: bool, documents: (string * string) list, |
217 info: bool, doc_format: string, doc_graph: bool, documents: (string * string) list, |
218 doc_prefix1: (Path.T * Path.T) option, doc_prefix2: (bool * Path.T) option, |
218 doc_prefix1: (Path.T * Path.T) option, dump_prefix: (bool * Path.T) option, |
219 remote_path: Url.T option, verbose: bool, readme: Path.T option}; |
219 remote_path: Url.T option, verbose: bool, readme: Path.T option}; |
220 |
220 |
221 fun make_session_info |
221 fun make_session_info |
222 (name, parent, session, path, html_prefix, info, doc_format, doc_graph, documents, |
222 (name, parent, session, path, html_prefix, info, doc_format, doc_graph, documents, |
223 doc_prefix1, doc_prefix2, remote_path, verbose, readme) = |
223 doc_prefix1, dump_prefix, remote_path, verbose, readme) = |
224 {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix, |
224 {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix, |
225 info = info, doc_format = doc_format, doc_graph = doc_graph, documents = documents, |
225 info = info, doc_format = doc_format, doc_graph = doc_graph, documents = documents, |
226 doc_prefix1 = doc_prefix1, doc_prefix2 = doc_prefix2, remote_path = remote_path, |
226 doc_prefix1 = doc_prefix1, dump_prefix = dump_prefix, remote_path = remote_path, |
227 verbose = verbose, readme = readme}: session_info; |
227 verbose = verbose, readme = readme}: session_info; |
228 |
228 |
229 |
229 |
230 (* state *) |
230 (* state *) |
231 |
231 |
277 |
277 |
278 (* init session *) |
278 (* init session *) |
279 |
279 |
280 fun name_of_session elems = space_implode "/" ("Isabelle" :: elems); |
280 fun name_of_session elems = space_implode "/" ("Isabelle" :: elems); |
281 |
281 |
282 fun init build info doc doc_graph doc_variants path name doc_prefix2 |
282 fun init build info doc doc_graph doc_variants path name dump_prefix |
283 (remote_path, first_time) verbose thys = CRITICAL (fn () => |
283 (remote_path, first_time) verbose thys = CRITICAL (fn () => |
284 if not build andalso not info andalso doc = "" andalso is_none doc_prefix2 then |
284 if not build andalso not info andalso doc = "" andalso is_none dump_prefix then |
285 (browser_info := empty_browser_info; session_info := NONE) |
285 (browser_info := empty_browser_info; session_info := NONE) |
286 else |
286 else |
287 let |
287 let |
288 val parent_name = name_of_session (take (length path - 1) path); |
288 val parent_name = name_of_session (take (length path - 1) path); |
289 val session_name = name_of_session path; |
289 val session_name = name_of_session path; |
312 map (fn (name, _) => (Url.File (Path.ext doc (Path.basic name)), name)) documents; |
312 map (fn (name, _) => (Url.File (Path.ext doc (Path.basic name)), name)) documents; |
313 val index_text = HTML.begin_index (index_up_lnk, parent_name) |
313 val index_text = HTML.begin_index (index_up_lnk, parent_name) |
314 (Url.File index_path, session_name) docs (Url.explode "medium.html"); |
314 (Url.File index_path, session_name) docs (Url.explode "medium.html"); |
315 in |
315 in |
316 session_info := SOME (make_session_info (name, parent_name, session_name, path, html_prefix, |
316 session_info := SOME (make_session_info (name, parent_name, session_name, path, html_prefix, |
317 info, doc, doc_graph, documents, doc_prefix1, doc_prefix2, remote_path, verbose, readme)); |
317 info, doc, doc_graph, documents, doc_prefix1, dump_prefix, remote_path, verbose, readme)); |
318 browser_info := init_browser_info remote_path path thys; |
318 browser_info := init_browser_info remote_path path thys; |
319 add_html_index (0, index_text) |
319 add_html_index (0, index_text) |
320 end); |
320 end); |
321 |
321 |
322 |
322 |
365 write_tex (index_buffer tex_index |> Buffer.add Latex.tex_trailer) doc_indexN path; |
365 write_tex (index_buffer tex_index |> Buffer.add Latex.tex_trailer) doc_indexN path; |
366 |
366 |
367 |
367 |
368 fun finish () = CRITICAL (fn () => |
368 fun finish () = CRITICAL (fn () => |
369 with_session () (fn {name, info, html_prefix, doc_format, doc_graph, |
369 with_session () (fn {name, info, html_prefix, doc_format, doc_graph, |
370 documents, doc_prefix1, doc_prefix2, path, verbose, readme, ...} => |
370 documents, doc_prefix1, dump_prefix, path, verbose, readme, ...} => |
371 let |
371 let |
372 val {theories, files, tex_index, html_index, graph} = ! browser_info; |
372 val {theories, files, tex_index, html_index, graph} = ! browser_info; |
373 val thys = Symtab.dest theories; |
373 val thys = Symtab.dest theories; |
374 val parent_html_prefix = Path.append html_prefix Path.parent; |
374 val parent_html_prefix = Path.append html_prefix Path.parent; |
375 |
375 |
377 fun finish_html (a, {html, ...}: theory_info) = |
377 fun finish_html (a, {html, ...}: theory_info) = |
378 File.write_buffer (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_document html); |
378 File.write_buffer (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_document html); |
379 |
379 |
380 val sorted_graph = sorted_index graph; |
380 val sorted_graph = sorted_index graph; |
381 val opt_graphs = |
381 val opt_graphs = |
382 if doc_graph andalso (is_some doc_prefix1 orelse is_some doc_prefix2) then |
382 if doc_graph andalso (is_some doc_prefix1 orelse is_some dump_prefix) then |
383 SOME (isabelle_browser sorted_graph) |
383 SOME (isabelle_browser sorted_graph) |
384 else NONE; |
384 else NONE; |
385 |
385 |
386 fun prepare_sources cp path = |
386 fun prepare_sources cp path = |
387 (Isabelle_System.mkdirs path; |
387 (Isabelle_System.mkdirs path; |
410 List.app finish_html thys; |
410 List.app finish_html thys; |
411 List.app (uncurry File.write) files; |
411 List.app (uncurry File.write) files; |
412 if verbose then Output.raw_stderr ("Browser info at " ^ show_path html_prefix ^ "\n") else ()) |
412 if verbose then Output.raw_stderr ("Browser info at " ^ show_path html_prefix ^ "\n") else ()) |
413 else (); |
413 else (); |
414 |
414 |
415 (case doc_prefix2 of NONE => () | SOME (cp, path) => |
415 (case dump_prefix of NONE => () | SOME (cp, path) => |
416 (prepare_sources cp path; |
416 (prepare_sources cp path; |
417 if verbose then Output.raw_stderr ("Document sources at " ^ show_path path ^ "\n") else ())); |
417 if verbose then Output.raw_stderr ("Document sources at " ^ show_path path ^ "\n") else ())); |
418 |
418 |
419 (case doc_prefix1 of NONE => () | SOME (path, result_path) => |
419 (case doc_prefix1 of NONE => () | SOME (path, result_path) => |
420 documents |> List.app (fn (name, tags) => |
420 documents |> List.app (fn (name, tags) => |