src/Pure/Thy/present.ML
changeset 15570 8d8c70b41bab
parent 15531 08c8dad8e399
child 15801 d2f5ca3c048d
equal deleted inserted replaced
15569:1b3115d1a8df 15570:8d8c70b41bab
   113     val path' = Path.append (Path.make session) (html_path name);
   113     val path' = Path.append (Path.make session) (html_path name);
   114   in
   114   in
   115    {name = name, ID = ID_of session name, dir = sess_name,
   115    {name = name, ID = ID_of session name, dir = sess_name,
   116     path =
   116     path =
   117       if null session then "" else
   117       if null session then "" else
   118       if is_some remote_path andalso not is_local then
   118       if isSome remote_path andalso not is_local then
   119         Url.pack (Url.append (the remote_path) (Url.File
   119         Url.pack (Url.append (valOf remote_path) (Url.File
   120           (Path.append (Path.make session) (html_path name))))
   120           (Path.append (Path.make session) (html_path name))))
   121       else Path.pack (Path.append (mk_rel_path curr_sess session) (html_path name)),
   121       else Path.pack (Path.append (mk_rel_path curr_sess session) (html_path name)),
   122     unfold = false,
   122     unfold = false,
   123     parents =
   123     parents =
   124       map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) (ThyInfo.get_preds name)}
   124       map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) (ThyInfo.get_preds name)}
   294           std_error "Warning: missing document directory\n"); (NONE, NONE))
   294           std_error "Warning: missing document directory\n"); (NONE, NONE))
   295         else (SOME (Path.append html_prefix doc_path), SOME (Path.ext doc doc_path));
   295         else (SOME (Path.append html_prefix doc_path), SOME (Path.ext doc doc_path));
   296 
   296 
   297       val parent_index_path = Path.append Path.parent index_path;
   297       val parent_index_path = Path.append Path.parent index_path;
   298       val index_up_lnk = if first_time then
   298       val index_up_lnk = if first_time then
   299           Url.append (the remote_path) (Url.File (Path.append sess_prefix parent_index_path))
   299           Url.append (valOf remote_path) (Url.File (Path.append sess_prefix parent_index_path))
   300         else Url.File parent_index_path;
   300         else Url.File parent_index_path;
   301       val readme =
   301       val readme =
   302         if File.exists readme_html_path then SOME readme_html_path
   302         if File.exists readme_html_path then SOME readme_html_path
   303         else if File.exists readme_path then SOME readme_path
   303         else if File.exists readme_path then SOME readme_path
   304         else NONE;
   304         else NONE;
   305 
   305 
   306       val index_text = HTML.begin_index (index_up_lnk, parent_name)
   306       val index_text = HTML.begin_index (index_up_lnk, parent_name)
   307         (Url.File index_path, session_name) (apsome Url.File readme)
   307         (Url.File index_path, session_name) (Option.map Url.File readme)
   308           (apsome Url.File document_path) (Url.unpack "medium.html");
   308           (Option.map Url.File document_path) (Url.unpack "medium.html");
   309     in
   309     in
   310       session_info := SOME (make_session_info (name, parent_name, session_name, path, html_prefix,
   310       session_info := SOME (make_session_info (name, parent_name, session_name, path, html_prefix,
   311       info, doc, doc_graph, doc_prefix1, doc_prefix2, remote_path, verbose, readme));
   311       info, doc, doc_graph, doc_prefix1, doc_prefix2, remote_path, verbose, readme));
   312       browser_info := init_browser_info remote_path path;
   312       browser_info := init_browser_info remote_path path;
   313       add_html_index index_text
   313       add_html_index index_text
   361     fun finish_tex path (a, {tex_source, ...}: theory_info) = write_tex tex_source a path;
   361     fun finish_tex path (a, {tex_source, ...}: theory_info) = write_tex tex_source a path;
   362     fun finish_html (a, {html, ...}: theory_info) =
   362     fun finish_html (a, {html, ...}: theory_info) =
   363       Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html);
   363       Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html);
   364 
   364 
   365     val opt_graphs =
   365     val opt_graphs =
   366       if doc_graph andalso (is_some doc_prefix1 orelse is_some doc_prefix2) then
   366       if doc_graph andalso (isSome doc_prefix1 orelse isSome doc_prefix2) then
   367         SOME (isatool_browser graph)
   367         SOME (isatool_browser graph)
   368       else NONE;
   368       else NONE;
   369 
   369 
   370     fun prepare_sources path =
   370     fun prepare_sources path =
   371      (copy_all doc_path path;
   371      (copy_all doc_path path;
   372       copy_files (Path.unpack "~~/lib/texinputs/*.sty") path;
   372       copy_files (Path.unpack "~~/lib/texinputs/*.sty") path;
   373       (case opt_graphs of NONE => () | SOME (pdf, eps) =>
   373       (case opt_graphs of NONE => () | SOME (pdf, eps) =>
   374         (File.write (Path.append path graph_pdf_path) pdf;
   374         (File.write (Path.append path graph_pdf_path) pdf;
   375           File.write (Path.append path graph_eps_path) eps));
   375           File.write (Path.append path graph_eps_path) eps));
   376       write_tex_index tex_index path;
   376       write_tex_index tex_index path;
   377       seq (finish_tex path) thys);
   377       List.app (finish_tex path) thys);
   378   in
   378   in
   379     conditional info (fn () =>
   379     conditional info (fn () =>
   380      (File.mkdir (Path.append html_prefix session_path);
   380      (File.mkdir (Path.append html_prefix session_path);
   381       Buffer.write (Path.append html_prefix pre_index_path) html_index;
   381       Buffer.write (Path.append html_prefix pre_index_path) html_index;
   382       File.write (Path.append html_prefix session_entries_path) "";
   382       File.write (Path.append html_prefix session_entries_path) "";
   383       create_index html_prefix;
   383       create_index html_prefix;
   384       if length path > 1 then update_index parent_html_prefix name else ();
   384       if length path > 1 then update_index parent_html_prefix name else ();
   385       (case readme of NONE => () | SOME path => File.copy path (Path.append html_prefix path));
   385       (case readme of NONE => () | SOME path => File.copy path (Path.append html_prefix path));
   386       write_graph graph (Path.append html_prefix graph_path);
   386       write_graph graph (Path.append html_prefix graph_path);
   387       copy_files (Path.unpack "~~/lib/browser/GraphBrowser.jar") html_prefix;
   387       copy_files (Path.unpack "~~/lib/browser/GraphBrowser.jar") html_prefix;
   388       seq (fn (a, txt) => File.write (Path.append html_prefix (Path.basic a)) txt)
   388       List.app (fn (a, txt) => File.write (Path.append html_prefix (Path.basic a)) txt)
   389         (HTML.applet_pages name (Url.File index_path, name));
   389         (HTML.applet_pages name (Url.File index_path, name));
   390       copy_files (Path.unpack "~~/lib/html/isabelle.css") html_prefix;
   390       copy_files (Path.unpack "~~/lib/html/isabelle.css") html_prefix;
   391       seq finish_html thys;
   391       List.app finish_html thys;
   392       seq (uncurry File.write) files;
   392       List.app (uncurry File.write) files;
   393       conditional verbose (fn () =>
   393       conditional verbose (fn () =>
   394         std_error ("Browser info at " ^ show_path html_prefix ^ "\n"))));
   394         std_error ("Browser info at " ^ show_path html_prefix ^ "\n"))));
   395 
   395 
   396     (case doc_prefix2 of NONE => () | SOME path =>
   396     (case doc_prefix2 of NONE => () | SOME path =>
   397      (prepare_sources path;
   397      (prepare_sources path;
   424 
   424 
   425 
   425 
   426 fun parent_link remote_path curr_session name =
   426 fun parent_link remote_path curr_session name =
   427   let val {name = _, session, is_local} = get_info (ThyInfo.theory name)
   427   let val {name = _, session, is_local} = get_info (ThyInfo.theory name)
   428   in (if null session then NONE else
   428   in (if null session then NONE else
   429      SOME (if is_some remote_path andalso not is_local then
   429      SOME (if isSome remote_path andalso not is_local then
   430        Url.append (the remote_path) (Url.File
   430        Url.append (valOf remote_path) (Url.File
   431          (Path.append (Path.make session) (html_path name)))
   431          (Path.append (Path.make session) (html_path name)))
   432      else Url.File (Path.append (mk_rel_path curr_session session)
   432      else Url.File (Path.append (mk_rel_path curr_session session)
   433        (html_path name))), name)
   433        (html_path name))), name)
   434   end;
   434   end;
   435 
   435 
   437     with_session thy (fn {name = sess_name, session, path, html_prefix, remote_path, ...} =>
   437     with_session thy (fn {name = sess_name, session, path, html_prefix, remote_path, ...} =>
   438   let
   438   let
   439     val parents = map (parent_link remote_path path) raw_parents;
   439     val parents = map (parent_link remote_path path) raw_parents;
   440     val ml_path = ThyLoad.ml_path name;
   440     val ml_path = ThyLoad.ml_path name;
   441     val files = map (apsnd SOME) orig_files @
   441     val files = map (apsnd SOME) orig_files @
   442       (if is_some (ThyLoad.check_file optpath ml_path) then [(ml_path, NONE)] else []);
   442       (if isSome (ThyLoad.check_file optpath ml_path) then [(ml_path, NONE)] else []);
   443 
   443 
   444     fun prep_file (raw_path, loadit) =
   444     fun prep_file (raw_path, loadit) =
   445       (case ThyLoad.check_file optpath raw_path of
   445       (case ThyLoad.check_file optpath raw_path of
   446         SOME (path, _) =>
   446         SOME (path, _) =>
   447           let
   447           let
   471   in
   471   in
   472     change_theory_info name prep_html_source;
   472     change_theory_info name prep_html_source;
   473     add_graph_entry entry;
   473     add_graph_entry entry;
   474     add_html_index (HTML.theory_entry (Url.File (html_path name), name));
   474     add_html_index (HTML.theory_entry (Url.File (html_path name), name));
   475     add_tex_index (Latex.theory_entry name);
   475     add_tex_index (Latex.theory_entry name);
   476     BrowserInfoData.put {name = sess_name, session = path, is_local = is_some remote_path} thy
   476     BrowserInfoData.put {name = sess_name, session = path, is_local = isSome remote_path} thy
   477   end);
   477   end);
   478 
   478 
   479 
   479 
   480 val hooks = ref ([]: (string -> (string * thm list) list -> unit) list);
   480 val hooks = ref ([]: (string -> (string * thm list) list -> unit) list);
   481 fun add_hook f = hooks := (f :: ! hooks);
   481 fun add_hook f = hooks := (f :: ! hooks);
   482 
   482 
   483 fun results k xs =
   483 fun results k xs =
   484  (seq (fn f => (try (fn () => f k xs) (); ())) (! hooks);
   484  (List.app (fn f => (try (fn () => f k xs) (); ())) (! hooks);
   485   with_session () (fn _ => with_context add_html (HTML.results k xs)));
   485   with_session () (fn _ => with_context add_html (HTML.results k xs)));
   486 
   486 
   487 fun theorem a th = results "theorem" [(a, [th])];
   487 fun theorem a th = results "theorem" [(a, [th])];
   488 fun theorems a ths = results "theorems" [(a, ths)];
   488 fun theorems a ths = results "theorems" [(a, ths)];
   489 fun chapter s = with_session () (fn _ => with_context add_html (HTML.chapter s));
   489 fun chapter s = with_session () (fn _ => with_context add_html (HTML.chapter s));
   522       let val ss = split_lines (File.read (Path.append doc_path (Path.basic name)))
   522       let val ss = split_lines (File.read (Path.append doc_path (Path.basic name)))
   523       in fn s => s mem_string ss end;
   523       in fn s => s mem_string ss end;
   524     val known_syms = known "syms.lst";
   524     val known_syms = known "syms.lst";
   525     val known_ctrls = known "ctrls.lst";
   525     val known_ctrls = known "ctrls.lst";
   526 
   526 
   527     val _ = srcs |> seq (fn (name, base, txt) =>
   527     val _ = srcs |> List.app (fn (name, base, txt) =>
   528       Symbol.explode txt
   528       Symbol.explode txt
   529       |> Latex.symbol_source (known_syms, known_ctrls) (Path.pack base)
   529       |> Latex.symbol_source (known_syms, known_ctrls) (Path.pack base)
   530       |> File.write (Path.append doc_path (tex_path name)));
   530       |> File.write (Path.append doc_path (tex_path name)));
   531     val _ = write_tex_index tex_index doc_path;
   531     val _ = write_tex_index tex_index doc_path;
   532     val _ = isatool_document false doc_format doc_path;
   532     val _ = isatool_document false doc_format doc_path;