author | wenzelm |
Wed, 12 Mar 2025 11:39:00 +0100 | |
changeset 82265 | 4b875a4c83b0 |
parent 82152 | 3312ca0f3915 |
permissions | -rw-r--r-- |
79502 | 1 |
/* Title: Pure/Build/browser_info.scala |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
3 |
|
75949
b09dab301d72
tuned comments, following "isabelle build" usage;
wenzelm
parents:
75947
diff
changeset
|
4 |
HTML/PDF presentation of PIDE document information. |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
6 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
8 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
9 |
|
74677 | 10 |
import scala.annotation.tailrec |
11 |
import scala.collection.mutable |
|
51402 | 12 |
|
13 |
||
75941 | 14 |
object Browser_Info { |
82152
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
15 |
/* SQLite database with compressed entries */ |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
16 |
|
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
17 |
val default_database: Path = Path.explode("$ISABELLE_BROWSER_INFO_LIBRARY") |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
18 |
val default_dir: Path = Path.explode("$ISABELLE_BROWSER_INFO") |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
19 |
|
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
20 |
def make_database(database: Path = default_database, dir: Path = default_dir): Unit = |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
21 |
File_Store.make_database(database, dir, |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
22 |
compress_options = Compress.Options_Zstd(level = 8), |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
23 |
compress_cache = Compress.Cache.make()) |
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
24 |
|
3312ca0f3915
support for browser_info.db --- requires approx. 10s to compress 1.2GB to 152MB;
wenzelm
parents:
82147
diff
changeset
|
25 |
|
75945 | 26 |
/* browser_info store configuration */ |
75943 | 27 |
|
28 |
object Config { |
|
29 |
val none: Config = new Config { def enabled: Boolean = false } |
|
30 |
val standard: Config = new Config { def enabled: Boolean = true } |
|
31 |
||
32 |
def dir(path: Path): Config = |
|
33 |
new Config { |
|
34 |
def enabled: Boolean = true |
|
78178 | 35 |
override def presentation_dir(store: Store): Path = path |
75943 | 36 |
} |
72957 | 37 |
|
75943 | 38 |
def make(s: String): Config = |
39 |
if (s == ":") standard else dir(Path.explode(s)) |
|
40 |
} |
|
41 |
||
42 |
abstract class Config private { |
|
43 |
def enabled: Boolean |
|
44 |
def enabled(info: Sessions.Info): Boolean = enabled || info.browser_info |
|
78178 | 45 |
def presentation_dir(store: Store): Path = store.presentation_dir |
75943 | 46 |
} |
47 |
||
48 |
||
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
49 |
/* meta info within the file-system */ |
75961 | 50 |
|
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
51 |
object Meta_Info { |
75961 | 52 |
/* directory */ |
53 |
||
54 |
val PATH: Path = Path.explode(".browser_info") |
|
55 |
||
56 |
def check_directory(dir: Path): Unit = { |
|
57 |
if (dir.is_dir && !(dir + PATH).is_dir && File.read_dir(dir).nonEmpty) { |
|
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
58 |
error("Existing content in " + dir.expand + " lacks " + PATH + " meta info.\n" + |
75961 | 59 |
"To avoid potential disaster, it has not been changed automatically.\n" + |
60 |
"If this is the intended directory, please move/remove/empty it manually.") |
|
61 |
} |
|
62 |
} |
|
63 |
||
82023
9601f5582f33
more robust wrt. Par_List.map in Browser_Info.build(), see also 2fff9ce6b460 and 787a203a20b6;
wenzelm
parents:
81566
diff
changeset
|
64 |
def init_directory(dir: Path, permissive: Boolean = false): Path = { |
9601f5582f33
more robust wrt. Par_List.map in Browser_Info.build(), see also 2fff9ce6b460 and 787a203a20b6;
wenzelm
parents:
81566
diff
changeset
|
65 |
if (!permissive) check_directory(dir) |
75961 | 66 |
Isabelle_System.make_directory(dir + PATH) |
67 |
dir |
|
68 |
} |
|
69 |
||
75982
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
70 |
def clean_directory(dir: Path): Path = { |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
71 |
check_directory(dir) |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
72 |
Isabelle_System.rm_tree(dir) // guarded by check_directory! |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
73 |
Isabelle_System.new_directory(dir + PATH) |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
74 |
} |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
75 |
|
75961 | 76 |
|
77 |
/* content */ |
|
78 |
||
79 |
def make_path(dir: Path, name: String): Path = |
|
80 |
dir + PATH + Path.basic(name) |
|
81 |
||
82 |
def value(dir: Path, name: String): String = { |
|
83 |
val path = make_path(dir, name) |
|
84 |
if (path.is_file) File.read(path) else "" |
|
85 |
} |
|
86 |
||
87 |
def change(dir: Path, name: String)(f: String => String): Unit = { |
|
88 |
val path = make_path(dir, name) |
|
89 |
val x = value(dir, name) |
|
90 |
val y = |
|
91 |
try { f(x) } |
|
92 |
catch { case ERROR(msg) => error("Failed to change " + path.expand + ":\n" + msg)} |
|
93 |
if (x != y) File.write(path, y) |
|
94 |
} |
|
95 |
||
96 |
||
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
97 |
/* build_uuid */ |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
98 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
99 |
val BUILD_UUID = "build_uuid" |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
100 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
101 |
def check_build_uuid(dir: Path, uuid: String): Boolean = { |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
102 |
val uuid0 = value(dir, BUILD_UUID) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
103 |
uuid0.nonEmpty && uuid.nonEmpty && uuid0 == uuid |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
104 |
} |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
105 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
106 |
def set_build_uuid(dir: Path, uuid: String): Unit = |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
107 |
change(dir, BUILD_UUID)(_ => uuid) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
108 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
109 |
|
75961 | 110 |
/* index */ |
111 |
||
112 |
val INDEX = "index.json" |
|
113 |
||
114 |
object Item { |
|
115 |
def parse(json: JSON.T): Item = { |
|
116 |
def err(): Nothing = |
|
117 |
error("Bad JSON object for item:\n" + JSON.Format.pretty_print(json)) |
|
118 |
val obj = JSON.Object.unapply(json) getOrElse err() |
|
119 |
||
120 |
val name = JSON.string(obj, "name") getOrElse err() |
|
121 |
val description = JSON.string(obj, "description") getOrElse "" |
|
122 |
Item(name, description = Symbol.trim_blank_lines(description)) |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
sealed case class Item(name: String, description: String = "") { |
|
75994 | 127 |
override def toString: String = name |
128 |
||
75961 | 129 |
def json: JSON.T = JSON.Object("name" -> name, "description" -> description) |
130 |
} |
|
131 |
||
132 |
object Index { |
|
133 |
def parse(s: JSON.S, kind: String): Index = { |
|
134 |
if (s.isEmpty) Index(kind, Nil) |
|
135 |
else { |
|
136 |
def err(): Nothing = error("Bad JSON object " + kind + " index:\n" + s) |
|
137 |
||
138 |
val json = JSON.parse(s) |
|
139 |
val obj = JSON.Object.unapply(json) getOrElse err() |
|
140 |
||
141 |
val kind1 = JSON.string(obj, "kind") getOrElse err() |
|
142 |
val items = JSON.list(obj, "items", x => Some(Item.parse(x))) getOrElse err() |
|
143 |
if (kind == kind1) Index(kind, items) |
|
144 |
else error("Expected index kind " + quote(kind) + " but found " + quote(kind1)) |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
sealed case class Index(kind: String, items: List[Item]) { |
|
75991 | 150 |
def is_empty: Boolean = items.isEmpty |
151 |
||
75999
b831a0bdd751
clarified signature of Sessions.Session: chapter_defs: vs. known_chapters (in declaration order) vs. chapters (covered by visible sessions);
wenzelm
parents:
75994
diff
changeset
|
152 |
def + (item: Item): Index = |
b831a0bdd751
clarified signature of Sessions.Session: chapter_defs: vs. known_chapters (in declaration order) vs. chapters (covered by visible sessions);
wenzelm
parents:
75994
diff
changeset
|
153 |
Index(kind, (item :: items.filterNot(_.name == item.name)).sortBy(_.name)) |
75961 | 154 |
|
155 |
def json: JSON.T = JSON.Object("kind" -> kind, "items" -> items.map(_.json)) |
|
156 |
def print_json: JSON.S = JSON.Format.pretty_print(json) |
|
157 |
} |
|
158 |
} |
|
159 |
||
160 |
||
75945 | 161 |
/* presentation elements */ |
162 |
||
163 |
sealed case class Elements( |
|
164 |
html: Markup.Elements = Markup.Elements.empty, |
|
165 |
entity: Markup.Elements = Markup.Elements.empty, |
|
166 |
language: Markup.Elements = Markup.Elements.empty) |
|
167 |
||
75979 | 168 |
val default_elements: Elements = |
75945 | 169 |
Elements( |
170 |
html = Rendering.foreground_elements ++ Rendering.text_color_elements + |
|
81566 | 171 |
Markup.TCLASS + Markup.TCONST + Markup.CONST + |
76009
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
172 |
Markup.NUMERAL + Markup.COMMENT + Markup.ENTITY + Markup.LANGUAGE + |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
173 |
Markup.PATH + Markup.URL, |
75945 | 174 |
entity = Markup.Elements(Markup.THEORY, Markup.TYPE_NAME, Markup.CONSTANT, Markup.FACT, |
175 |
Markup.CLASS, Markup.LOCALE, Markup.FREE)) |
|
176 |
||
75979 | 177 |
val extra_elements: Elements = |
75945 | 178 |
Elements( |
75979 | 179 |
html = default_elements.html ++ Rendering.markdown_elements, |
75945 | 180 |
language = Markup.Elements(Markup.Language.DOCUMENT)) |
181 |
||
182 |
||
75943 | 183 |
|
75949
b09dab301d72
tuned comments, following "isabelle build" usage;
wenzelm
parents:
75947
diff
changeset
|
184 |
/** HTML/PDF presentation context **/ |
73718 | 185 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
186 |
def context( |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
187 |
sessions_structure: Sessions.Structure, |
75979 | 188 |
elements: Elements = default_elements, |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
189 |
root_dir: Path = Path.current, |
75907 | 190 |
document_info: Document_Info = Document_Info.empty |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
191 |
): Context = new Context(sessions_structure, elements, root_dir, document_info) |
72957 | 192 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
193 |
class Context private[Browser_Info]( |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
194 |
sessions_structure: Sessions.Structure, |
75897 | 195 |
val elements: Elements, |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
196 |
val root_dir: Path, |
75907 | 197 |
val document_info: Document_Info |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
198 |
) { |
74818
3064e165c660
clarified HTML_Context.theory_exports: prefer value-oriented parallelism;
wenzelm
parents:
74816
diff
changeset
|
199 |
/* directory structure and resources */ |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
200 |
|
75907 | 201 |
def theory_by_name(session: String, theory: String): Option[Document_Info.Theory] = |
202 |
document_info.theory_by_name(session, theory) |
|
75894 | 203 |
|
75907 | 204 |
def theory_by_file(session: String, file: String): Option[Document_Info.Theory] = |
205 |
document_info.theory_by_file(session, file) |
|
75897 | 206 |
|
75980 | 207 |
def session_chapter(session: String): String = |
208 |
sessions_structure(session).chapter |
|
209 |
||
75981 | 210 |
def chapter_dir(session: String): Path = |
211 |
root_dir + Path.basic(session_chapter(session)) |
|
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
212 |
|
75981 | 213 |
def session_dir(session: String): Path = |
214 |
chapter_dir(session) + Path.basic(session) |
|
75961 | 215 |
|
75946 | 216 |
def theory_dir(theory: Document_Info.Theory): Path = |
217 |
session_dir(theory.dynamic_session) |
|
218 |
||
75907 | 219 |
def theory_html(theory: Document_Info.Theory): Path = |
75917
20b918404aa3
evade clash with index.html (allow "Index.thy" even on case-insensitive file-systems);
wenzelm
parents:
75916
diff
changeset
|
220 |
{ |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
221 |
def check(name: String): Option[Path] = { |
75977
59aa034220bf
more robust: ensure that chapter/session/theory do not contain special notation (like "/" or "..");
wenzelm
parents:
75971
diff
changeset
|
222 |
val path = Path.basic(name).html |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
223 |
if (Path.eq_case_insensitive(path, Path.index_html)) None |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
224 |
else Some(path) |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
225 |
} |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
226 |
check(theory.print_short) orElse check(theory.name) getOrElse |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
227 |
error("Illegal global theory name " + quote(theory.name) + |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
228 |
" (conflict with " + Path.index_html + ")") |
75917
20b918404aa3
evade clash with index.html (allow "Index.thy" even on case-insensitive file-systems);
wenzelm
parents:
75916
diff
changeset
|
229 |
} |
75900 | 230 |
|
75915
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
231 |
def file_html(file: String): Path = |
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
232 |
Path.explode(file).squash.html |
75900 | 233 |
|
75914
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75913
diff
changeset
|
234 |
def smart_html(theory: Document_Info.Theory, file: String): Path = |
75915
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
235 |
if (File.is_thy(file)) theory_html(theory) else file_html(file) |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
236 |
|
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
237 |
|
74769 | 238 |
/* HTML content */ |
239 |
||
72962 | 240 |
def head(title: String, rest: XML.Body = Nil): XML.Tree = |
241 |
HTML.div("head", HTML.chapter(title) :: rest) |
|
242 |
||
243 |
def source(body: XML.Body): XML.Tree = HTML.pre("source", body) |
|
244 |
||
75393 | 245 |
def contents( |
246 |
heading: String, |
|
247 |
items: List[XML.Body], |
|
248 |
css_class: String = "contents" |
|
249 |
) : List[XML.Elem] = { |
|
72962 | 250 |
if (items.isEmpty) Nil |
251 |
else List(HTML.div(css_class, List(HTML.section(heading), HTML.itemize(items)))) |
|
252 |
} |
|
253 |
||
75944 | 254 |
|
255 |
/* preview PIDE document */ |
|
256 |
||
75969 | 257 |
lazy val isabelle_css: String = File.read(HTML.isabelle_css) |
74768 | 258 |
|
75393 | 259 |
def html_document(title: String, body: XML.Body, fonts_css: String): HTML_Document = { |
74709 | 260 |
val content = |
261 |
HTML.output_document( |
|
262 |
List( |
|
74768 | 263 |
HTML.style(fonts_css + "\n\n" + isabelle_css), |
74709 | 264 |
HTML.title(title)), |
265 |
List(HTML.source(body)), css = "", structural = false) |
|
266 |
HTML_Document(title, content) |
|
267 |
} |
|
75944 | 268 |
|
269 |
def preview_document( |
|
270 |
snapshot: Document.Snapshot, |
|
271 |
plain_text: Boolean = false, |
|
272 |
fonts_css: String = HTML.fonts_css() |
|
273 |
): HTML_Document = { |
|
274 |
require(!snapshot.is_outdated, "document snapshot outdated") |
|
275 |
||
276 |
val name = snapshot.node_name |
|
277 |
if (plain_text) { |
|
76829
f2a8ba0b8c96
more robust: avoid detour via somewhat fragile Node.Name.path;
wenzelm
parents:
76656
diff
changeset
|
278 |
val title = "File " + Symbol.cartouche_decoded(name.file_name) |
76933 | 279 |
val body = HTML.text(snapshot.node.source) |
75944 | 280 |
html_document(title, body, fonts_css) |
281 |
} |
|
282 |
else { |
|
283 |
Resources.html_document(snapshot) getOrElse { |
|
284 |
val title = |
|
285 |
if (name.is_theory) "Theory " + quote(name.theory_base_name) |
|
76829
f2a8ba0b8c96
more robust: avoid detour via somewhat fragile Node.Name.path;
wenzelm
parents:
76656
diff
changeset
|
286 |
else "File " + Symbol.cartouche_decoded(name.file_name) |
75944 | 287 |
val xml = snapshot.xml_markup(elements = elements.html) |
288 |
val body = Node_Context.empty.make_html(elements, xml) |
|
289 |
html_document(title, body, fonts_css) |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
293 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
294 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
295 |
/* maintain presentation structure */ |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
296 |
|
75980 | 297 |
def update_chapter(session_name: String, session_description: String): Unit = synchronized { |
82023
9601f5582f33
more robust wrt. Par_List.map in Browser_Info.build(), see also 2fff9ce6b460 and 787a203a20b6;
wenzelm
parents:
81566
diff
changeset
|
298 |
val dir = Meta_Info.init_directory(chapter_dir(session_name), permissive = true) |
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
299 |
Meta_Info.change(dir, Meta_Info.INDEX) { text => |
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
300 |
val index0 = Meta_Info.Index.parse(text, "chapter") |
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
301 |
val item = Meta_Info.Item(session_name, description = session_description) |
75961 | 302 |
val index = index0 + item |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
303 |
|
75961 | 304 |
if (index != index0) { |
75981 | 305 |
val title = "Isabelle/" + session_chapter(session_name) + " sessions" |
75961 | 306 |
HTML.write_document(dir, "index.html", |
307 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
|
308 |
HTML.chapter(title) :: |
|
75991 | 309 |
(if (index.is_empty) Nil |
75961 | 310 |
else |
311 |
List(HTML.div("sessions", |
|
312 |
List(HTML.description( |
|
75991 | 313 |
index.items.map(item => |
314 |
(List(HTML.link(item.name + "/index.html", HTML.text(item.name))), |
|
315 |
if (item.description.isEmpty) Nil |
|
316 |
else HTML.break ::: List(HTML.pre(HTML.text(item.description)))))))))), |
|
75961 | 317 |
root = Some(root_dir)) |
318 |
} |
|
75953
32c4f8766831
clarified synchronized operations: approximate file-system transactions;
wenzelm
parents:
75952
diff
changeset
|
319 |
|
75961 | 320 |
index.print_json |
321 |
} |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
322 |
} |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
323 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
324 |
def update_root(): Unit = synchronized { |
82023
9601f5582f33
more robust wrt. Par_List.map in Browser_Info.build(), see also 2fff9ce6b460 and 787a203a20b6;
wenzelm
parents:
81566
diff
changeset
|
325 |
Meta_Info.init_directory(root_dir, permissive = true) |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
326 |
HTML.init_fonts(root_dir) |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
327 |
Isabelle_System.copy_file(Path.explode("~~/lib/logo/isabelle.gif"), |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
328 |
root_dir + Path.explode("isabelle.gif")) |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
329 |
|
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
330 |
Meta_Info.change(root_dir, Meta_Info.INDEX) { text => |
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
331 |
val index0 = Meta_Info.Index.parse(text, "root") |
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
332 |
val index = { |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
333 |
val items1 = |
75999
b831a0bdd751
clarified signature of Sessions.Session: chapter_defs: vs. known_chapters (in declaration order) vs. chapters (covered by visible sessions);
wenzelm
parents:
75994
diff
changeset
|
334 |
sessions_structure.known_chapters |
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
335 |
.map(ch => Meta_Info.Item(ch.name, description = ch.description)) |
75999
b831a0bdd751
clarified signature of Sessions.Session: chapter_defs: vs. known_chapters (in declaration order) vs. chapters (covered by visible sessions);
wenzelm
parents:
75994
diff
changeset
|
336 |
val items2 = index0.items.filterNot(item => items1.exists(_.name == item.name)) |
b831a0bdd751
clarified signature of Sessions.Session: chapter_defs: vs. known_chapters (in declaration order) vs. chapters (covered by visible sessions);
wenzelm
parents:
75994
diff
changeset
|
337 |
index0.copy(items = items1 ::: items2) |
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
338 |
} |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
339 |
|
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
340 |
if (index != index0) { |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
341 |
val title = "The " + XML.text(Isabelle_System.isabelle_name()) + " Library" |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
342 |
HTML.write_document(root_dir, "index.html", |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
343 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
344 |
HTML.chapter(title) :: |
75991 | 345 |
(if (index.is_empty) Nil |
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
346 |
else |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
347 |
List(HTML.div("sessions", |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
348 |
List(HTML.description( |
75991 | 349 |
index.items.map(item => |
350 |
(List(HTML.link(item.name + "/index.html", HTML.text(item.name))), |
|
351 |
if (item.description.isEmpty) Nil |
|
352 |
else HTML.break ::: List(HTML.pre(HTML.text(item.description)))))))))), |
|
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
353 |
root = Some(root_dir)) |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
354 |
} |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
355 |
|
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
356 |
index.print_json |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
357 |
} |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
358 |
} |
72959 | 359 |
} |
360 |
||
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
361 |
sealed case class HTML_Document(title: String, content: String) |
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
362 |
|
72957 | 363 |
|
74678 | 364 |
/* formal entities */ |
74677 | 365 |
|
75891 | 366 |
object Theory_Ref { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
367 |
def unapply(props: Properties.T): Option[String] = |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
368 |
(props, props) match { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
369 |
case (Markup.Kind(Markup.THEORY), Markup.Name(theory)) => Some(theory) |
75891 | 370 |
case _ => None |
371 |
} |
|
372 |
} |
|
74765 | 373 |
|
75891 | 374 |
object Entity_Ref { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
375 |
def unapply(props: Properties.T): Option[(String, String, String)] = |
75891 | 376 |
(props, props, props, props) match { |
75913 | 377 |
case (Markup.Entity.Ref.Prop(_), Position.Def_File(file), Markup.Kind(kind), Markup.Name(name)) |
378 |
if Path.is_wellformed(file) => Some((file, kind, name)) |
|
75891 | 379 |
case _ => None |
380 |
} |
|
381 |
} |
|
74765 | 382 |
|
75927 | 383 |
object Node_Context { |
384 |
val empty: Node_Context = new Node_Context |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
385 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
386 |
def make( |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
387 |
context: Context, |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
388 |
session_name: String, |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
389 |
theory_name: String, |
75929
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
390 |
file_name: String, |
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
391 |
node_dir: Path, |
75927 | 392 |
): Node_Context = |
393 |
new Node_Context { |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
394 |
private val seen_ranges: mutable.Set[Symbol.Range] = mutable.Set.empty |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
395 |
|
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
396 |
override def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
397 |
body match { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
398 |
case List(XML.Elem(Markup("span", List("id" -> _)), _)) => None |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
399 |
case _ => |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
400 |
for (theory <- context.theory_by_name(session_name, theory_name)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
401 |
yield { |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
402 |
val body1 = |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
403 |
if (seen_ranges.contains(range)) { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
404 |
HTML.entity_def(HTML.span(HTML.id(offset_id(range)), body)) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
405 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
406 |
else HTML.span(body) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
407 |
theory.get_defs(file_name, range).foldLeft(body1) { |
75896 | 408 |
case (elem, entity) => |
409 |
HTML.entity_def(HTML.span(HTML.id(entity.kname), List(elem))) |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
410 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
411 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
412 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
413 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
414 |
private def offset_id(range: Text.Range): String = |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
415 |
"offset_" + range.start + ".." + range.stop |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
416 |
|
76009
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
417 |
override def make_file_ref(file: String, body: XML.Body): Option[XML.Elem] = { |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
418 |
for (theory <- context.theory_by_file(session_name, file)) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
419 |
yield { |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
420 |
val html_path = context.theory_dir(theory) + context.smart_html(theory, file) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
421 |
val html_link = HTML.relative_href(html_path, base = Some(node_dir)) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
422 |
HTML.link(html_link, body) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
423 |
} |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
424 |
} |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
425 |
|
75393 | 426 |
override def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = { |
74765 | 427 |
props match { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
428 |
case Theory_Ref(thy_name) => |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
429 |
for (theory <- context.theory_by_name(session_name, thy_name)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
430 |
yield { |
75946 | 431 |
val html_path = context.theory_dir(theory) + context.theory_html(theory) |
75933 | 432 |
val html_link = HTML.relative_href(html_path, base = Some(node_dir)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
433 |
HTML.link(html_link, body) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
434 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
435 |
case Entity_Ref(def_file, kind, name) => |
75907 | 436 |
def logical_ref(theory: Document_Info.Theory): Option[String] = |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
437 |
theory.get_def(def_file, kind, name).map(_.kname) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
438 |
|
75907 | 439 |
def physical_ref(theory: Document_Info.Theory): Option[String] = |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
440 |
props match { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
441 |
case Position.Def_Range(range) if theory.name == theory_name => |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
442 |
seen_ranges += range |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
443 |
Some(offset_id(range)) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
444 |
case _ => None |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
445 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
446 |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
447 |
for { |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
448 |
theory <- context.theory_by_file(session_name, def_file) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
449 |
html_ref <- logical_ref(theory) orElse physical_ref(theory) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
450 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
451 |
yield { |
75946 | 452 |
val html_path = context.theory_dir(theory) + context.smart_html(theory, def_file) |
75933 | 453 |
val html_link = HTML.relative_href(html_path, base = Some(node_dir)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
454 |
HTML.entity_ref(HTML.link(html_link + "#" + html_ref, body)) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
455 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
456 |
case _ => None |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
457 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
458 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
459 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
460 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
461 |
|
75927 | 462 |
class Node_Context { |
74753 | 463 |
def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = None |
464 |
def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = None |
|
76009
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
465 |
def make_file_ref(file: String, body: XML.Body): Option[XML.Elem] = None |
73055 | 466 |
|
75928 | 467 |
val div_elements: Set[String] = |
468 |
Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.`enum`.name, |
|
469 |
HTML.descr.name) |
|
72957 | 470 |
|
75928 | 471 |
def make_html(elements: Elements, xml: XML.Body): XML.Body = { |
472 |
def html_div(html: XML.Body): Boolean = |
|
473 |
html exists { |
|
474 |
case XML.Elem(markup, body) => div_elements.contains(markup.name) || html_div(body) |
|
475 |
case XML.Text(_) => false |
|
476 |
} |
|
477 |
||
478 |
def html_class(c: String, html: XML.Body): XML.Body = |
|
479 |
if (c == "") html |
|
480 |
else if (html_div(html)) List(HTML.div(c, html)) |
|
481 |
else List(HTML.span(c, html)) |
|
72957 | 482 |
|
75928 | 483 |
def html_body(xml_body: XML.Body, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
484 |
xml_body.foldRight((List.empty[XML.Tree], end_offset)) { case (tree, (res, end_offset1)) => |
|
485 |
val (res1, offset) = html_body_single(tree, end_offset1) |
|
486 |
(res1 ++ res, offset) |
|
487 |
} |
|
74677 | 488 |
|
75928 | 489 |
@tailrec |
490 |
def html_body_single(xml_tree: XML.Tree, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
|
491 |
xml_tree match { |
|
81562
d387683ea725
more accurate HTML markup: suppress text_color that has_syntax (amending b57996a0688c);
wenzelm
parents:
81561
diff
changeset
|
492 |
case XML.Wrapped_Elem(markup, _, body) => |
d387683ea725
more accurate HTML markup: suppress text_color that has_syntax (amending b57996a0688c);
wenzelm
parents:
81561
diff
changeset
|
493 |
html_body_single(XML.Elem(markup, body), end_offset) |
75928 | 494 |
case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) => |
495 |
val (body1, offset) = html_body(body, end_offset) |
|
496 |
if (elements.entity(kind)) { |
|
497 |
make_ref(props, body1) match { |
|
498 |
case Some(link) => (List(link), offset) |
|
499 |
case None => (body1, offset) |
|
500 |
} |
|
73056 | 501 |
} |
75928 | 502 |
else (body1, offset) |
76009
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
503 |
case XML.Elem(Markup.Path(file), body) => |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
504 |
val (body1, offset) = html_body(body, end_offset) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
505 |
make_file_ref(file, body1) match { |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
506 |
case Some(link) => (List(link), offset) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
507 |
case None => (body1, offset) |
adf9c4d68581
more links, for files that formally belong to this session;
wenzelm
parents:
76008
diff
changeset
|
508 |
} |
76008 | 509 |
case XML.Elem(Markup.Url(href), body) => |
510 |
val (body1, offset) = html_body(body, end_offset) |
|
511 |
(List(HTML.link(href, body1)), offset) |
|
75928 | 512 |
case XML.Elem(Markup(Markup.LANGUAGE, Markup.Name(name)), body) => |
513 |
val (body1, offset) = html_body(body, end_offset) |
|
514 |
(html_class(if (elements.language(name)) name else "", body1), offset) |
|
515 |
case XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), body) => |
|
516 |
val (body1, offset) = html_body(body, end_offset) |
|
517 |
(List(HTML.par(body1)), offset) |
|
518 |
case XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), body) => |
|
519 |
val (body1, offset) = html_body(body, end_offset) |
|
520 |
(List(HTML.item(body1)), offset) |
|
521 |
case XML.Elem(Markup(Markup.Markdown_Bullet.name, _), text) => |
|
522 |
(Nil, end_offset - XML.symbol_length(text)) |
|
523 |
case XML.Elem(Markup.Markdown_List(kind), body) => |
|
524 |
val (body1, offset) = html_body(body, end_offset) |
|
525 |
if (kind == Markup.ENUMERATE) (List(HTML.`enum`(body1)), offset) |
|
526 |
else (List(HTML.list(body1)), offset) |
|
527 |
case XML.Elem(markup, body) => |
|
528 |
val (body1, offset) = html_body(body, end_offset) |
|
529 |
val html = |
|
530 |
markup.properties match { |
|
531 |
case Markup.Kind(kind) if kind == Markup.COMMAND || kind == Markup.KEYWORD => |
|
532 |
html_class(kind, body1) |
|
533 |
case _ => |
|
534 |
body1 |
|
535 |
} |
|
81562
d387683ea725
more accurate HTML markup: suppress text_color that has_syntax (amending b57996a0688c);
wenzelm
parents:
81561
diff
changeset
|
536 |
val c = |
81564
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81562
diff
changeset
|
537 |
if (Markup.has_syntax(markup.properties)) "" |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81562
diff
changeset
|
538 |
else { |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81562
diff
changeset
|
539 |
Rendering.get_foreground_text_color(markup) match { |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81562
diff
changeset
|
540 |
case Some(color) => color.toString |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81562
diff
changeset
|
541 |
case None => markup.name |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81562
diff
changeset
|
542 |
} |
81562
d387683ea725
more accurate HTML markup: suppress text_color that has_syntax (amending b57996a0688c);
wenzelm
parents:
81561
diff
changeset
|
543 |
} |
d387683ea725
more accurate HTML markup: suppress text_color that has_syntax (amending b57996a0688c);
wenzelm
parents:
81561
diff
changeset
|
544 |
(html_class(c, html), offset) |
75928 | 545 |
case XML.Text(text) => |
546 |
val offset = end_offset - Symbol.length(text) |
|
547 |
val body = HTML.text(Symbol.decode(text)) |
|
548 |
make_def(Text.Range(offset, end_offset), body) match { |
|
549 |
case Some(body1) => (List(body1), offset) |
|
550 |
case None => (body, offset) |
|
551 |
} |
|
552 |
} |
|
73054 | 553 |
|
75928 | 554 |
html_body(xml, XML.symbol_length(xml) + 1)._1 |
555 |
} |
|
73054 | 556 |
} |
72957 | 557 |
|
558 |
||
559 |
||
75945 | 560 |
/** build presentation **/ |
72649 | 561 |
|
75888 | 562 |
val session_graph_path: Path = Path.explode("session_graph.pdf") |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
563 |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
564 |
def build_session( |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
565 |
context: Context, |
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75774
diff
changeset
|
566 |
session_context: Export.Session_Context, |
72992 | 567 |
progress: Progress = new Progress, |
75393 | 568 |
): Unit = { |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
569 |
progress.expose_interrupt() |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
570 |
|
75902 | 571 |
val session_name = session_context.session_name |
572 |
val session_info = session_context.sessions_structure(session_name) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
573 |
|
75961 | 574 |
val session_dir = context.session_dir(session_name).expand |
575 |
progress.echo("Presenting " + session_name + " in " + session_dir + " ...") |
|
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
576 |
|
82054 | 577 |
Meta_Info.init_directory(context.chapter_dir(session_name), permissive = true) |
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
578 |
Meta_Info.clean_directory(session_dir) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
579 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
580 |
val session = context.document_info.the_session(session_name) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
581 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
582 |
Bytes.write(session_dir + session_graph_path, |
75902 | 583 |
graphview.Graph_File.make_pdf(session_info.options, |
584 |
session_context.session_base.session_graph_display)) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
585 |
|
75925 | 586 |
val document_variants = |
72683 | 587 |
for { |
75902 | 588 |
doc <- session_info.document_variants |
75780
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
wenzelm
parents:
75778
diff
changeset
|
589 |
db <- session_context.session_db() |
75902 | 590 |
document <- Document_Build.read_document(db, session_name, doc.name) |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
591 |
} |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
592 |
yield { |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
593 |
val doc_path = session_dir + doc.path.pdf |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
594 |
if (Path.eq_case_insensitive(doc.path.pdf, session_graph_path)) { |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
595 |
error("Illegal document variant " + quote(doc.name) + |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
596 |
" (conflict with " + session_graph_path + ")") |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
597 |
} |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77202
diff
changeset
|
598 |
progress.echo("Presenting document " + session_name + "/" + doc.name, verbose = true) |
75902 | 599 |
if (session_info.document_echo) progress.echo("Document at " + doc_path) |
74732
015282fb3e31
clarified messages, depending on option "document_echo";
wenzelm
parents:
74731
diff
changeset
|
600 |
Bytes.write(doc_path, document.pdf) |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
601 |
doc |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
602 |
} |
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
603 |
|
75925 | 604 |
val document_links = { |
605 |
val link1 = HTML.link(session_graph_path, HTML.text("theory dependencies")) |
|
606 |
val links2 = document_variants.map(doc => HTML.link(doc.path.pdf, HTML.text(doc.name))) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
607 |
Library.separate(HTML.break ::: HTML.nl, |
75925 | 608 |
(link1 :: links2).map(link => HTML.text("View ") ::: List(link))).flatten |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
609 |
} |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
610 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
611 |
def present_theory(theory_name: String): XML.Body = { |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
612 |
progress.expose_interrupt() |
73215 | 613 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
614 |
def err(): Nothing = |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
615 |
error("Missing document information for theory: " + quote(theory_name)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
616 |
|
78280 | 617 |
val snapshot = Build.read_theory(session_context.theory(theory_name)) getOrElse err() |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
618 |
val theory = context.theory_by_name(session_name, theory_name) getOrElse err() |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
619 |
|
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77202
diff
changeset
|
620 |
progress.echo("Presenting theory " + quote(theory_name), verbose = true) |
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
621 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
622 |
val thy_elements = theory.elements(context.elements) |
73215 | 623 |
|
75929
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
624 |
def node_context(file_name: String, node_dir: Path): Node_Context = |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
625 |
Node_Context.make(context, session_name, theory_name, file_name, node_dir) |
75928 | 626 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
627 |
val thy_html = |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
628 |
context.source( |
75929
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
629 |
node_context(theory.thy_file, session_dir). |
75928 | 630 |
make_html(thy_elements, snapshot.xml_markup(elements = thy_elements.html))) |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
631 |
|
76937
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
632 |
val master_dir = Path.explode(snapshot.node_name.master_dir) |
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
633 |
|
75931 | 634 |
val files = |
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
635 |
for { |
76930 | 636 |
blob_name <- snapshot.node_files.tail |
637 |
xml = snapshot.switch(blob_name).xml_markup(elements = thy_elements.html) |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
638 |
if xml.nonEmpty |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
639 |
} |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
640 |
yield { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
641 |
progress.expose_interrupt() |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
642 |
|
76937
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
643 |
val file = blob_name.node |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77202
diff
changeset
|
644 |
progress.echo("Presenting file " + quote(file), verbose = true) |
74715
129fb11b357f
use all entity kinds from theory export, e.g. "method", "attribute";
wenzelm
parents:
74714
diff
changeset
|
645 |
|
76937
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
646 |
val file_html = session_dir + context.file_html(file) |
75932 | 647 |
val file_dir = file_html.dir |
75933 | 648 |
val html_link = HTML.relative_href(file_html, base = Some(session_dir)) |
76937
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
649 |
val html = context.source(node_context(file, file_dir).make_html(thy_elements, xml)) |
75931 | 650 |
|
76937
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
651 |
val path = Path.explode(file) |
82147 | 652 |
val src_path = File.perhaps_relative_path(master_dir, path) |
76937
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
653 |
|
099486b09c0e
prefer relative src_path (if possible) -- in contrast to 9ce0aa145d21:
wenzelm
parents:
76933
diff
changeset
|
654 |
val file_title = "File " + Symbol.cartouche_decoded(src_path.implode_short) |
75932 | 655 |
HTML.write_document(file_dir, file_html.file_name, |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
656 |
List(HTML.title(file_title)), List(context.head(file_title), html), |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
657 |
root = Some(context.root_dir)) |
75931 | 658 |
List(HTML.link(html_link, HTML.text(file_title))) |
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
659 |
} |
73215 | 660 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
661 |
val thy_title = "Theory " + theory.print_short |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
662 |
HTML.write_document(session_dir, context.theory_html(theory).implode, |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
663 |
List(HTML.title(thy_title)), List(context.head(thy_title), thy_html), |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
664 |
root = Some(context.root_dir)) |
73215 | 665 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
666 |
List(HTML.link(context.theory_html(theory), |
75925 | 667 |
HTML.text(theory.print_short) ::: |
668 |
(if (files.isEmpty) Nil else List(HTML.itemize(files))))) |
|
72989 | 669 |
} |
61500 | 670 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
671 |
val theories = session.used_theories.map(present_theory) |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
672 |
|
75902 | 673 |
val title = "Session " + session_name |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
674 |
HTML.write_document(session_dir, "index.html", |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
675 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
676 |
context.head(title, List(HTML.par(document_links))) :: |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
677 |
context.contents("Theories", theories), |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
678 |
root = Some(context.root_dir)) |
75961 | 679 |
|
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
680 |
Meta_Info.set_build_uuid(session_dir, session.build_uuid) |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
681 |
|
75980 | 682 |
context.update_chapter(session_name, session_info.description) |
61372 | 683 |
} |
75947 | 684 |
|
685 |
def build( |
|
686 |
browser_info: Config, |
|
78178 | 687 |
store: Store, |
75947 | 688 |
deps: Sessions.Deps, |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
689 |
sessions: List[String], |
78379 | 690 |
progress: Progress = new Progress, |
691 |
server: SSH.Server = SSH.no_server |
|
75947 | 692 |
): Unit = { |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
693 |
val root_dir = browser_info.presentation_dir(store).absolute |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
694 |
progress.echo("Presentation in " + root_dir) |
75947 | 695 |
|
78379 | 696 |
using(Export.open_database_context(store, server = server)) { database_context => |
75979 | 697 |
val context0 = context(deps.sessions_structure, root_dir = root_dir) |
75947 | 698 |
|
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
699 |
val sessions1 = |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
700 |
deps.sessions_structure.build_requirements(sessions).filter { session_name => |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
701 |
using(database_context.open_database(session_name)) { session_database => |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
702 |
database_context.store.read_build(session_database.db, session_name) match { |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
703 |
case None => false |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
704 |
case Some(build) => |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
705 |
val session_dir = context0.session_dir(session_name) |
77202
064566bc1f35
clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents:
76937
diff
changeset
|
706 |
!Meta_Info.check_build_uuid(session_dir, build.uuid) |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
707 |
} |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
708 |
} |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
709 |
} |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
710 |
|
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
711 |
val context1 = |
75979 | 712 |
context(deps.sessions_structure, root_dir = root_dir, |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
713 |
document_info = Document_Info.read(database_context, deps, sessions1)) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
714 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
715 |
context1.update_root() |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
716 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
717 |
Par_List.map({ (session: String) => |
76656 | 718 |
using(database_context.open_session(deps.background(session))) { session_context => |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77202
diff
changeset
|
719 |
build_session(context1, session_context, progress = progress) |
75947 | 720 |
} |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
721 |
}, sessions1) |
75947 | 722 |
} |
723 |
} |
|
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
724 |
} |