1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956
|
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 2001 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(** Generation of html documentation.*)
open Odoc_info
open Value
open Type
open Extension
open Exception
open Class
open Module
module String = Misc.Stdlib.String
let with_parameter_list = ref false
let css_style = ref None
let index_only = ref false
let colorize_code = ref false
let html_short_functors = ref false
let charset = ref "UTF-8"
let show_navbar = ref true
(** The functions used for naming files and html marks.*)
module Naming =
struct
(** The prefix for modules marks. *)
let mark_module = "MODULE"
(** The prefix for module type marks. *)
let mark_module_type = "MODULETYPE"
(** The prefix for types marks. *)
let mark_type = "TYPE"
(** The prefix for types elements (record fields or constructors). *)
let mark_type_elt = "TYPEELT"
(** The prefix for functions marks. *)
let mark_function = "FUN"
(** The prefix for extensions marks. *)
let mark_extension = "EXTENSION"
(** The prefix for exceptions marks. *)
let mark_exception = "EXCEPTION"
(** The prefix for values marks. *)
let mark_value = "VAL"
(** The prefix for attributes marks. *)
let mark_attribute = "ATT"
(** The prefix for methods marks. *)
let mark_method = "METHOD"
(** The prefix for code files. *)
let code_prefix = "code_"
(** The prefix for type files. *)
let type_prefix = "type_"
(** Return the two html files names for the given module or class name.*)
let html_files name =
let qual =
try
let i = String.rindex name '.' in
match name.[i + 1] with
| 'A'..'Z' -> ""
| _ -> "-c"
with Not_found -> ""
in
let prefix = name^qual in
let html_file = prefix^".html" in
let html_frame_file = prefix^"-frame.html" in
(html_file, html_frame_file)
(** Return the target for the given prefix and simple name. *)
let target pref simple_name = pref^simple_name
(** Return the complete link target (file#target) for the given prefix string and complete name.*)
let complete_target pref complete_name =
let simple_name = Name.simple complete_name in
let module_name =
let s = Name.father complete_name in
if s = "" then simple_name else s
in
let (html_file, _) = html_files module_name in
html_file^"#"^(target pref simple_name)
(**return the link target for the given module. *)
let module_target m = target mark_module (Name.simple m.m_name)
(**return the link target for the given module type. *)
let module_type_target mt = target mark_module_type (Name.simple mt.mt_name)
(** Return the link target for the given type. *)
let type_target t = target mark_type (Name.simple t.ty_name)
(** Return the link target for the given variant constructor. *)
let const_target t f =
let name = Printf.sprintf "%s.%s" (Name.simple t.ty_name) f.vc_name in
target mark_type_elt name
(** Return the link target for the given record field. *)
let recfield_target t f = target mark_type_elt
(Printf.sprintf "%s.%s" (Name.simple t.ty_name) f.rf_name)
(** Return the link target for the given inline record field. *)
let inline_recfield_target t c f = target mark_type_elt
(Printf.sprintf "%s.%s.%s" t c f.rf_name)
(** Return the link target for the given object field. *)
let objfield_target t f = target mark_type_elt
(Printf.sprintf "%s.%s" (Name.simple t.ty_name) f.of_name)
(** Return the complete link target for the given type. *)
let complete_type_target t = complete_target mark_type t.ty_name
let complete_recfield_target name =
let typ = Name.father name in
let field = Name.simple name in
Printf.sprintf "%s.%s" (complete_target mark_type_elt typ) field
let complete_const_target = complete_recfield_target
(** Return the link target for the given extension. *)
let extension_target x = target mark_extension (Name.simple x.xt_name)
(** Return the complete link target for the given extension. *)
let complete_extension_target x = complete_target mark_extension x.xt_name
(** Return the link target for the given exception. *)
let exception_target e = target mark_exception (Name.simple e.ex_name)
(** Return the complete link target for the given exception. *)
let complete_exception_target e = complete_target mark_exception e.ex_name
(** Return the link target for the given value. *)
let value_target v = target mark_value (Name.simple v.val_name)
(** Return the given value name where symbols accepted in infix values
are replaced by strings, to avoid clashes with the filesystem.*)
let subst_infix_symbols name =
let len = String.length name in
let buf = Buffer.create len in
let ch c = Buffer.add_char buf c in
let st s = Buffer.add_string buf s in
for i = 0 to len - 1 do
match name.[i] with
| '|' -> st "_pipe_"
| '<' -> st "_lt_"
| '>' -> st "_gt_"
| '@' -> st "_at_"
| '^' -> st "_exp_"
| '&' -> st "_amp_"
| '+' -> st "_plus_"
| '-' -> st "_minus_"
| '*' -> st "_star_"
| '/' -> st "_slash_"
| '$' -> st "_dollar_"
| '%' -> st "_percent_"
| '=' -> st "_equal_"
| ':' -> st "_column_"
| '~' -> st "_tilde_"
| '!' -> st "_bang_"
| '?' -> st "_questionmark_"
| c -> ch c
done;
Buffer.contents buf
(** Return the complete link target for the given value. *)
let complete_value_target v = complete_target mark_value v.val_name
(** Return the complete filename for the code of the given value. *)
let file_code_value_complete_target v =
code_prefix^mark_value^(subst_infix_symbols v.val_name)^".html"
(** Return the link target for the given attribute. *)
let attribute_target a = target mark_attribute (Name.simple a.att_value.val_name)
(** Return the complete link target for the given attribute. *)
let complete_attribute_target a = complete_target mark_attribute a.att_value.val_name
(** Return the complete filename for the code of the given attribute. *)
let file_code_attribute_complete_target a =
code_prefix^mark_attribute^a.att_value.val_name^".html"
(** Return the link target for the given method. *)
let method_target m = target mark_method (Name.simple m.met_value.val_name)
(** Return the complete link target for the given method. *)
let complete_method_target m = complete_target mark_method m.met_value.val_name
(** Return the complete filename for the code of the given method. *)
let file_code_method_complete_target m =
code_prefix^mark_method^m.met_value.val_name^".html"
(** Return the link target for the given label section. *)
let label_target l = target "" l
(** Return the complete link target for the given section label. *)
let complete_label_target l = complete_target "" l
(** Return the complete filename for the code of the type of the
given module or module type name. *)
let file_type_module_complete_target name =
type_prefix^name^".html"
(** Return the complete filename for the code of the
given module name. *)
let file_code_module_complete_target name =
code_prefix^name^".html"
(** Return the complete filename for the code of the type of the
given class or class type name. *)
let file_type_class_complete_target name =
type_prefix^name^".html"
end
(** A class with a method to colorize a string which represents OCaml code. *)
class ocaml_code =
object
method html_of_code b ?(with_pre=true) code =
Odoc_ocamlhtml.html_of_code b ~with_pre: with_pre code
end
let new_buf () = Buffer.create 1024
let bp = Printf.bprintf
let bs = Buffer.add_string
(** Generation of html code from text structures. *)
class virtual text =
object (self)
(** We want to display colorized code. *)
inherit ocaml_code
(** Escape the strings which would clash with html syntax, and
make some replacements (double newlines replaced by <br>). *)
method escape s = Odoc_ocamlhtml.escape_base s
method keep_alpha_num s =
let len = String.length s in
let buf = Buffer.create len in
for i = 0 to len - 1 do
match s.[i] with
'a'..'z' | 'A'..'Z' | '0'..'9' -> Buffer.add_char buf s.[i]
| _ -> ()
done;
Buffer.contents buf
(** Return a label created from the first sentence of a text. *)
method label_of_text t=
let t2 = Odoc_info.first_sentence_of_text t in
let s = Odoc_info.string_of_text t2 in
self#keep_alpha_num s
(** Create a label for the associated title.
Return the label specified by the user or a label created
from the title level and the first sentence of the title. *)
method create_title_label (n,label_opt,t) =
match label_opt with
Some s -> s
| None -> Printf.sprintf "%d_%s" n (self#label_of_text t)
(** Print the html code corresponding to the [text] parameter. *)
method html_of_text ?(with_p=false) b t =
if not with_p then
List.iter (self#html_of_text_element b) t
else
self#html_of_text_with_p b t
method html_of_text_with_p b t =
(* In order to enclose the generated text in <p> </p>, we first
output the content inside a inner buffer b', and then generate
the whole paragraph, if the content is not empty,
either at the end of the text, at a Newline element or when
encountering an element that cannot be part of a paragraph element
*)
let b' = Buffer.create 17 (* paragraph buffer *) in
let flush b' =
(* trim the inner string to avoid outputting empty <p></p> *)
let s = String.trim @@ Buffer.contents b' in
if s <> "" then
begin
bp b "<p>";
bs b s;
bp b "</p>\n"
end;
Buffer.clear b' in
let rec iter txt =
match txt with
| [] ->
flush b' (* flush b' at the end of the text *)
| (List _ | Enum _ | Title _ | CodePre _ | Verbatim _ | Center _
| Left _ | Right _ | Newline | Index_list ) as a :: q
(* these elements cannot be part of <p> element *)
->
flush b'; (* stop the current paragraph *)
self#html_of_text_element b a; (*output [a] directly on [b] *)
iter q
| a :: q -> self#html_of_text_element b' a; iter q
in
iter t
(** Print the html code for the [text_element] in parameter. *)
method html_of_text_element b txt =
match txt with
| Odoc_info.Raw s -> self#html_of_Raw b s
| Odoc_info.Code s -> self#html_of_Code b s
| Odoc_info.CodePre s -> self#html_of_CodePre b s
| Odoc_info.Verbatim s -> self#html_of_Verbatim b s
| Odoc_info.Bold t -> self#html_of_Bold b t
| Odoc_info.Italic t -> self#html_of_Italic b t
| Odoc_info.Emphasize t -> self#html_of_Emphasize b t
| Odoc_info.Center t -> self#html_of_Center b t
| Odoc_info.Left t -> self#html_of_Left b t
| Odoc_info.Right t -> self#html_of_Right b t
| Odoc_info.List tl -> self#html_of_List b tl
| Odoc_info.Enum tl -> self#html_of_Enum b tl
| Odoc_info.Newline -> self#html_of_Newline b
| Odoc_info.Block t -> self#html_of_Block b t
| Odoc_info.Title (n, l_opt, t) -> self#html_of_Title b n l_opt t
| Odoc_info.Latex s -> self#html_of_Latex b s
| Odoc_info.Link (s, t) -> self#html_of_Link b s t
| Odoc_info.Ref (name, ref_opt, text_opt) ->
self#html_of_Ref b name ref_opt text_opt
| Odoc_info.Superscript t -> self#html_of_Superscript b t
| Odoc_info.Subscript t -> self#html_of_Subscript b t
| Odoc_info.Module_list l -> self#html_of_Module_list b l
| Odoc_info.Index_list -> self#html_of_Index_list b
| Odoc_info.Custom (s,t) -> self#html_of_custom_text b s t
| Odoc_info.Target (target, code) -> self#html_of_Target b ~target ~code
method html_of_custom_text _ _ _ = ()
method html_of_Target b ~target ~code =
if String.lowercase_ascii target = "html" then bs b code else ()
method html_of_Raw b s = bs b (self#escape s)
method html_of_Code b s =
if !colorize_code then
self#html_of_code b ~with_pre: false s
else
(
bs b "<code class=\"";
bs b Odoc_ocamlhtml.code_class ;
bs b "\">";
bs b (self#escape s);
bs b "</code>"
)
method html_of_CodePre =
let remove_useless_newlines s =
let len = String.length s in
let rec iter_first n =
if n >= len then
None
else
match s.[n] with
| '\n' -> iter_first (n+1)
| _ -> Some n
in
match iter_first 0 with
None -> ""
| Some first ->
let rec iter_last n =
if n <= first then
None
else
match s.[n] with
'\t' -> iter_last (n-1)
| _ -> Some n
in
match iter_last (len-1) with
None -> String.sub s first 1
| Some last -> String.sub s first ((last-first)+1)
in
fun b s ->
if !colorize_code then
(
bs b "<pre class=\"codepre\">";
self#html_of_code b (remove_useless_newlines s);
bs b "</pre>"
)
else
(
bs b "<pre class=\"codepre\"><code class=\"";
bs b Odoc_ocamlhtml.code_class;
bs b "\">" ;
bs b (self#escape (remove_useless_newlines s));
bs b "</code></pre>"
)
method html_of_Verbatim b s =
bs b "<pre class=\"verbatim\">";
bs b (self#escape s);
bs b "</pre>"
method html_of_Bold b t =
bs b "<b>";
self#html_of_text b t;
bs b "</b>"
method html_of_Italic b t =
bs b "<i>" ;
self#html_of_text b t;
bs b "</i>"
method html_of_Emphasize b t =
bs b "<em>" ;
self#html_of_text b t ;
bs b "</em>"
method html_of_Center b t =
bs b "<center>";
self#html_of_text b t;
bs b "</center>"
method html_of_Left b t =
bs b "<div align=left>";
self#html_of_text b t;
bs b "</div>"
method html_of_Right b t =
bs b "<div align=right>";
self#html_of_text b t;
bs b "</div>"
method html_of_List b tl =
bs b "<ul>\n";
List.iter
(fun t -> bs b "<li>"; self#html_of_text b t; bs b "</li>\n")
tl;
bs b "</ul>\n"
method html_of_Enum b tl =
bs b "<OL>\n";
List.iter
(fun t -> bs b "<li>"; self#html_of_text b t; bs b"</li>\n")
tl;
bs b "</OL>\n"
method html_of_Newline b = bs b "\n"
method html_of_Block b t =
bs b "<blockquote>\n";
self#html_of_text b t;
bs b "</blockquote>\n"
method html_of_Title b n label_opt t =
let label1 = self#create_title_label (n, label_opt, t) in
let (tag_o, tag_c) =
if n > 6 then
(Printf.sprintf "div class=\"h%d\"" (n+1), "div")
else
let t = Printf.sprintf "h%d" (n+1) in (t, t)
in
bs b "<";
bp b "%s id=\"%s\"" tag_o (Naming.label_target label1);
bs b ">";
self#html_of_text b t;
bs b "</";
bs b tag_c;
bs b ">"
method html_of_Latex _ _ = ()
(* don't care about LaTeX stuff in HTML. *)
method html_of_Link b s t =
bs b "<a href=\"";
bs b (self#escape s);
bs b "\">";
self#html_of_text b t;
bs b "</a>"
method html_of_Ref b name ref_opt text_opt =
match ref_opt with
None ->
let text =
match text_opt with
None -> [Odoc_info.Code name]
| Some t -> t
in
self#html_of_text b text
| Some kind ->
let h name = Odoc_info.Code (Odoc_info.use_hidden_modules name) in
let (target, text) =
match kind with
Odoc_info.RK_module
| Odoc_info.RK_module_type
| Odoc_info.RK_class
| Odoc_info.RK_class_type ->
let (html_file, _) = Naming.html_files name in
(html_file, h name)
| Odoc_info.RK_value -> (Naming.complete_target Naming.mark_value name, h name)
| Odoc_info.RK_type -> (Naming.complete_target Naming.mark_type name, h name)
| Odoc_info.RK_extension -> (Naming.complete_target Naming.mark_extension name, h name)
| Odoc_info.RK_exception -> (Naming.complete_target Naming.mark_exception name, h name)
| Odoc_info.RK_attribute -> (Naming.complete_target Naming.mark_attribute name, h name)
| Odoc_info.RK_method -> (Naming.complete_target Naming.mark_method name, h name)
| Odoc_info.RK_section t -> (Naming.complete_label_target name,
Odoc_info.Italic [Raw (Odoc_info.string_of_text t)])
| Odoc_info.RK_recfield -> (Naming.complete_recfield_target name, h name)
| Odoc_info.RK_const -> (Naming.complete_const_target name, h name)
in
let text =
match text_opt with
None -> [text]
| Some text -> text
in
bs b ("<a href=\""^target^"\">");
self#html_of_text b text;
bs b "</a>"
method html_of_Superscript b t =
bs b "<sup class=\"superscript\">";
self#html_of_text b t;
bs b "</sup>"
method html_of_Subscript b t =
bs b "<sub class=\"subscript\">";
self#html_of_text b t;
bs b "</sub>"
method virtual html_of_info_first_sentence : _
method html_of_Module_list b l =
bs b "\n<table class=\"indextable module-list\">\n";
List.iter
(fun name ->
bs b "<tr><td class=\"module\">";
(
try
let m =
List.find (fun m -> m.m_name = name) self#list_modules
in
let (html, _) = Naming.html_files m.m_name in
bp b "<a href=\"%s\">%s</a></td>" html m.m_name;
bs b "<td>";
self#html_of_info_first_sentence b m.m_info;
with
Not_found ->
Odoc_global.pwarning (Odoc_messages.cross_module_not_found name);
bp b "%s</td><td>" name
);
bs b "</td></tr>\n"
)
l;
bs b "</table>\n"
method html_of_Index_list b =
let index_if_not_empty l url m =
match l with
[] -> ()
| _ -> bp b "<li><a href=\"%s\">%s</a></li>\n" url m
in
bp b "<ul class=\"indexlist\">\n";
index_if_not_empty self#list_types self#index_types Odoc_messages.index_of_types;
index_if_not_empty self#list_extensions self#index_extensions Odoc_messages.index_of_extensions;
index_if_not_empty self#list_exceptions self#index_exceptions Odoc_messages.index_of_exceptions;
index_if_not_empty self#list_values self#index_values Odoc_messages.index_of_values;
index_if_not_empty self#list_attributes self#index_attributes Odoc_messages.index_of_attributes;
index_if_not_empty self#list_methods self#index_methods Odoc_messages.index_of_methods;
index_if_not_empty self#list_classes self#index_classes Odoc_messages.index_of_classes;
index_if_not_empty self#list_class_types self#index_class_types Odoc_messages.index_of_class_types;
index_if_not_empty self#list_modules self#index_modules Odoc_messages.index_of_modules;
index_if_not_empty self#list_module_types self#index_module_types Odoc_messages.index_of_module_types;
bp b "</ul>\n"
method virtual list_types : Odoc_info.Type.t_type list
method virtual index_types : string
method virtual list_extensions : Odoc_info.Extension.t_extension_constructor list
method virtual index_extensions : string
method virtual list_exceptions : Odoc_info.Exception.t_exception list
method virtual index_exceptions : string
method virtual list_values : Odoc_info.Value.t_value list
method virtual index_values : string
method virtual list_attributes : Odoc_info.Value.t_attribute list
method virtual index_attributes : string
method virtual list_methods : Odoc_info.Value.t_method list
method virtual index_methods : string
method virtual list_classes : Odoc_info.Class.t_class list
method virtual index_classes : string
method virtual list_class_types : Odoc_info.Class.t_class_type list
method virtual index_class_types : string
method virtual list_modules : Odoc_info.Module.t_module list
method virtual index_modules : string
method virtual list_module_types : Odoc_info.Module.t_module_type list
method virtual index_module_types : string
end
(** A class used to generate html code for info structures. *)
class virtual info =
object (self)
(** The list of pairs [(tag, f)] where [f] is a function taking
the [text] associated to [tag] and returning html code.
Add a pair here to handle a tag.*)
val mutable tag_functions = ([] : (string * (Odoc_info.text -> string)) list)
(** The method used to get html code from a [text]. *)
method virtual html_of_text :
?with_p:bool -> Buffer.t -> Odoc_info.text -> unit
(** Print html for an author list. *)
method html_of_author_list b l =
match l with
[] -> ()
| _ ->
bp b "<li><b>%s:</b> " Odoc_messages.authors;
self#html_of_text b [Raw (String.concat ", " l)];
bs b "</li>\n"
(** Print html code for the given optional version information.*)
method html_of_version_opt b v_opt =
match v_opt with
None -> ()
| Some v ->
bp b "<li><b>%s:</b> " Odoc_messages.version;
self#html_of_text b [Raw v];
bs b "</li>\n"
(** Print html code for the given optional since information.*)
method html_of_since_opt b s_opt =
match s_opt with
None -> ()
| Some s ->
bp b "<li><b>%s</b> " Odoc_messages.since;
self#html_of_text b [Raw s];
bs b "</li>\n"
(** Print html code for the given "before" information.*)
method html_of_before b l =
let f (v, text) =
bp b "<li><b>%s " Odoc_messages.before;
self#html_of_text b [Raw v];
bs b " </b> ";
self#html_of_text b text;
bs b "</li>\n"
in
List.iter f l
(** Print html code for the given list of raised exceptions.*)
method html_of_raised_exceptions b l =
match l with
[] -> ()
| (s, t) :: [] ->
bp b "<li><b>%s</b> <code>%s</code> "
Odoc_messages.raises
s;
self#html_of_text b t;
bs b "</li>\n"
| _ ->
bp b "<li><b>%s</b><ul>" Odoc_messages.raises;
List.iter
(fun (ex, desc) ->
bp b "<li><code>%s</code> " ex ;
self#html_of_text b desc;
bs b "</li>\n"
)
l;
bs b "</ul></li>\n"
(** Print html code for the given "see also" reference. *)
method html_of_see b (see_ref, t) =
let t_ref =
match see_ref with
Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ]
| Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t
| Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t
in
self#html_of_text b t_ref
(** Print html code for the given list of "see also" references.*)
method html_of_sees b l =
match l with
[] -> ()
| see :: [] ->
bp b "<li><b>%s</b> " Odoc_messages.see_also;
self#html_of_see b see;
bs b "</li>\n"
| _ ->
bp b "<li><b>%s</b><ul>" Odoc_messages.see_also;
List.iter
(fun see ->
bs b "<li>" ;
self#html_of_see b see;
bs b "</li>\n"
)
l;
bs b "</ul></li>\n"
(** Print html code for the given optional return information.*)
method html_of_return_opt b return_opt =
match return_opt with
None -> ()
| Some s ->
bp b "<li><b>%s</b> " Odoc_messages.returns;
self#html_of_text b s;
bs b "</li>\n"
(** Print html code for the given list of custom tagged texts. *)
method html_of_custom b l =
List.iter
(fun (tag, text) ->
try
let f = List.assoc tag tag_functions in
Buffer.add_string b (f text)
with
Not_found ->
Odoc_info.warning (Odoc_messages.tag_not_handled tag)
)
l
method html_of_alerts b alerts =
List.iter (fun { alert_name; alert_payload } ->
bp b "<li><b>%s %s.</b>" Odoc_messages.alert alert_name;
(match alert_payload with Some p -> bp b " %s" p | None -> ());
bp b "</li>\n"
) alerts
(** Print html code for a description, except for the [i_params] field.
@param indent can be specified not to use the style of info comments;
default is [true].
*)
method html_of_info ?(cls="") ?(indent=true) b info_opt =
match info_opt with
None ->
()
| Some info ->
let module M = Odoc_info in
if indent then bs b ("<div class=\"info "^cls^"\">\n");
(
match info.M.i_deprecated with
None -> ()
| Some d ->
bs b "<div class=\"info-deprecated\">\n";
bs b "<span class=\"warning\">";
bs b (Odoc_messages.deprecated^". ");
bs b "</span>" ;
self#html_of_text b d;
bs b "</div>\n"
);
(
match info.M.i_desc with
None -> ()
| Some d when d = [Odoc_info.Raw ""] -> ()
| Some d ->
bs b "<div class=\"info-desc\">\n";
self#html_of_text ~with_p:true b d;
bs b "</div>\n"
);
let b' = Buffer.create 17 in
self#html_of_author_list b' info.M.i_authors;
self#html_of_version_opt b' info.M.i_version;
self#html_of_before b' info.M.i_before;
self#html_of_since_opt b' info.M.i_since;
self#html_of_raised_exceptions b' info.M.i_raised_exceptions;
self#html_of_return_opt b' info.M.i_return_value;
self#html_of_sees b' info.M.i_sees;
self#html_of_alerts b' info.M.i_alerts;
self#html_of_custom b' info.M.i_custom;
if Buffer.length b' > 0 then
begin
bs b "<ul class=\"info-attributes\">\n";
Buffer.add_buffer b b';
bs b "</ul>\n"
end;
if indent then bs b "</div>\n"
(** Print html code for the first sentence of a description.
The titles and lists in this first sentence has been removed.*)
method html_of_info_first_sentence b info_opt =
match info_opt with
None -> ()
| Some info ->
let module M = Odoc_info in
let dep = info.M.i_deprecated <> None in
bs b "<div class=\"info\">\n";
if dep then bs b "<span class=\"deprecated\">";
(
match info.M.i_desc with
None -> ()
| Some d when d = [Odoc_info.Raw ""] -> ()
| Some d ->
self#html_of_text ~with_p:true b
(Odoc_info.text_no_title_no_list
(Odoc_info.first_sentence_of_text d));
bs b "\n"
);
if dep then bs b "</span>";
bs b "</div>\n"
end
let opt = Odoc_info.apply_opt
let print_concat b sep f =
let rec iter = function
[] -> ()
| [c] -> f c
| c :: q ->
f c;
bs b sep;
iter q
in
iter
(** Escape "\n", "<", ">", and "&" *)
let text_to_html s =
let len = String.length s in
let b = Buffer.create len in
for i = 0 to len - 1 do
match s.[i] with
| '\n' -> Buffer.add_string b "<br> "
| '<' -> Buffer.add_string b "<"
| '>' -> Buffer.add_string b ">"
| '&' -> Buffer.add_string b "&"
| c -> Buffer.add_char b c
done;
Buffer.contents b
module Generator =
struct
(** This class is used to create objects which can generate a simple html documentation. *)
class html =
object (self)
inherit text
inherit info
val mutable doctype =
"<!DOCTYPE html>\n"
method character_encoding b =
bp b
"<meta content=\"text/html; charset=%s\" http-equiv=\"Content-Type\">\n"
!charset
method meta b =
self#character_encoding b;
bs b "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
(** The default style options. *)
val mutable default_style_options =
[ ".keyword { font-weight : bold ; color : Red }" ;
".keywordsign { color : #C04600 }" ;
".comment { color : Green }" ;
".constructor { color : Blue }" ;
".type { color : #5C6585 }" ;
".string { color : Maroon }" ;
".warning { color : Red ; font-weight : bold }" ;
".info { margin-left : 3em; margin-right: 3em }" ;
".param_info { margin-top: 4px; margin-left : 3em; margin-right : 3em }" ;
".code { color : #465F91 ; }" ;
".typetable { border-style : hidden }" ;
".paramstable { border-style : hidden ; padding: 5pt 5pt}" ;
"tr { background-color : White }" ;
"td.typefieldcomment { background-color : #FFFFFF ; font-size: smaller ;}" ;
"div.sig_block {margin-left: 2em}" ;
"*:target { background: yellow; }" ;
"body {font: 13px sans-serif; color: black; text-align: left; padding: 5px; margin: 0}";
"h1 { font-size : 20pt ; text-align: center; }" ;
"h2 { font-size : 20pt ; text-align: center; }" ;
"h3 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #90BDFF ;"^
"padding: 2px; }" ;
"h4 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #90DDFF ;"^
"padding: 2px; }" ;
"h5 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #90EDFF ;"^
"padding: 2px; }" ;
"h6 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #90FDFF ;"^
"padding: 2px; }" ;
"div.h7 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #90BDFF ; "^
"padding: 2px; }" ;
"div.h8 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #E0FFFF ; "^
"padding: 2px; }" ;
"div.h9 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #F0FFFF ; "^
"padding: 2px; }" ;
"div.h10 { font-size : 20pt ; border: 1px solid #000000; "^
"margin-top: 5px; margin-bottom: 2px;"^
"text-align: center; background-color: #FFFFFF ; "^
"padding: 2px; }" ;
"a {color: #416DFF; text-decoration: none}";
"a:hover {background-color: #ddd; text-decoration: underline}";
"pre { margin-bottom: 4px; font-family: monospace; }" ;
"pre.verbatim, pre.codepre { }";
".indextable {border: 1px #ddd solid; border-collapse: collapse}";
".indextable td, .indextable th {border: 1px #ddd solid; min-width: 80px}";
".indextable td.module {background-color: #eee ; padding-left: 2px; padding-right: 2px}";
".indextable td.module a {color: #4E6272; text-decoration: none; display: block; width: 100%}";
".indextable td.module a:hover {text-decoration: underline; background-color: transparent}";
".deprecated {color: #888; font-style: italic}" ;
".indextable tr td div.info { margin-left: 2px; margin-right: 2px }" ;
"ul.indexlist { margin-left: 0; padding-left: 0;}";
"ul.indexlist li { list-style-type: none ; margin-left: 0; padding-left: 0; }";
"ul.info-attributes {list-style: none; margin: 0; padding: 0; }";
"div.info > p:first-child { margin-top:0; }";
"div.info-desc > p:first-child { margin-top:0; margin-bottom:0; }"
]
(** The style file for all pages. *)
val mutable style_file = "style.css"
(** The code to import the style. Initialized in [init_style]. *)
val mutable style = ""
(** The known types names.
Used to know if we must create a link to a type
when printing a type. *)
val mutable known_types_names = String.Set.empty
(** The known class and class type names.
Used to know if we must create a link to a class
or class type or not when printing a type. *)
val mutable known_classes_names = String.Set.empty
(** The known modules and module types names.
Used to know if we must create a link to a type or not
when printing a module type. *)
val mutable known_modules_names = String.Set.empty
method index_prefix =
if !Odoc_global.out_file = Odoc_messages.default_out_file then
"index"
else
Filename.basename !Odoc_global.out_file
(** The main file. *)
method index =
let p = self#index_prefix in
Printf.sprintf "%s.html" p
(** The file for the index of values. *)
method index_values = Printf.sprintf "%s_values.html" self#index_prefix
(** The file for the index of types. *)
method index_types = Printf.sprintf "%s_types.html" self#index_prefix
(** The file for the index of extensions. *)
method index_extensions = Printf.sprintf "%s_extensions.html" self#index_prefix
(** The file for the index of exceptions. *)
method index_exceptions = Printf.sprintf "%s_exceptions.html" self#index_prefix
(** The file for the index of attributes. *)
method index_attributes = Printf.sprintf "%s_attributes.html" self#index_prefix
(** The file for the index of methods. *)
method index_methods = Printf.sprintf "%s_methods.html" self#index_prefix
(** The file for the index of classes. *)
method index_classes = Printf.sprintf "%s_classes.html" self#index_prefix
(** The file for the index of class types. *)
method index_class_types = Printf.sprintf "%s_class_types.html" self#index_prefix
(** The file for the index of modules. *)
method index_modules = Printf.sprintf "%s_modules.html" self#index_prefix
(** The file for the index of module types. *)
method index_module_types = Printf.sprintf "%s_module_types.html" self#index_prefix
(** The list of attributes. Filled in the [generate] method. *)
val mutable list_attributes = []
method list_attributes = list_attributes
(** The list of methods. Filled in the [generate] method. *)
val mutable list_methods = []
method list_methods = list_methods
(** The list of values. Filled in the [generate] method. *)
val mutable list_values = []
method list_values = list_values
(** The list of extensions. Filled in the [generate] method. *)
val mutable list_extensions = []
method list_extensions = list_extensions
(** The list of exceptions. Filled in the [generate] method. *)
val mutable list_exceptions = []
method list_exceptions = list_exceptions
(** The list of types. Filled in the [generate] method. *)
val mutable list_types = []
method list_types = list_types
(** The list of modules. Filled in the [generate] method. *)
val mutable list_modules = []
method list_modules = list_modules
(** The list of module types. Filled in the [generate] method. *)
val mutable list_module_types = []
method list_module_types = list_module_types
(** The list of classes. Filled in the [generate] method. *)
val mutable list_classes = []
method list_classes = list_classes
(** The list of class types. Filled in the [generate] method. *)
val mutable list_class_types = []
method list_class_types = list_class_types
(** The header of pages. Must be prepared by the [prepare_header] method.*)
val mutable header = fun _ -> fun ?nav:_ -> fun ?comments:_ -> fun _ -> ()
(** Init the style. *)
method init_style =
(match !css_style with
None ->
let default_style = String.concat "\n" default_style_options in
(
try
let file = Filename.concat !Global.target_dir style_file in
if Sys.file_exists file then
Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file)
else
(
let chanout = open_out file in
output_string chanout default_style ;
flush chanout ;
close_out chanout;
Odoc_info.verbose (Odoc_messages.file_generated file)
)
with
Sys_error s ->
prerr_endline s ;
incr Odoc_info.errors ;
)
| Some f ->
style_file <- f
);
style <- "<link rel=\"stylesheet\" href=\""^style_file^"\" type=\"text/css\">\n"
(** Get the title given by the user *)
method title = match !Global.title with None -> "" | Some t -> self#escape t
(** Get the title given by the user completed with the given subtitle. *)
method inner_title s =
(match self#title with "" -> "" | t -> t^" : ")^
(self#escape s)
(** Get the page header. *)
method print_header b ?nav ?comments title = header b ?nav ?comments title
(** A function to build the header of pages. *)
method prepare_header module_list =
let f b ?(nav=None) ?(comments=[]) t =
let link_if_not_empty l m url =
match l with
[] -> ()
| _ ->
bp b "<link title=\"%s\" rel=Appendix href=\"%s\">\n" m url
in
bs b "<head>\n";
bs b style;
self#meta b;
bs b "<link rel=\"Start\" href=\"";
bs b self#index;
bs b "\">\n" ;
(
match nav with
None -> ()
| Some (pre_opt, post_opt, name) ->
(match pre_opt with
None -> ()
| Some name ->
bp b "<link rel=\"previous\" href=\"%s\">\n"
(fst (Naming.html_files name));
);
(match post_opt with
None -> ()
| Some name ->
bp b "<link rel=\"next\" href=\"%s\">\n"
(fst (Naming.html_files name));
);
(
let father = Name.father name in
let href = if father = "" then self#index else fst (Naming.html_files father) in
bp b "<link rel=\"Up\" href=\"%s\">\n" href
)
);
link_if_not_empty self#list_types Odoc_messages.index_of_types self#index_types;
link_if_not_empty self#list_extensions Odoc_messages.index_of_extensions self#index_extensions;
link_if_not_empty self#list_exceptions Odoc_messages.index_of_exceptions self#index_exceptions;
link_if_not_empty self#list_values Odoc_messages.index_of_values self#index_values;
link_if_not_empty self#list_attributes Odoc_messages.index_of_attributes self#index_attributes;
link_if_not_empty self#list_methods Odoc_messages.index_of_methods self#index_methods;
link_if_not_empty self#list_classes Odoc_messages.index_of_classes self#index_classes;
link_if_not_empty self#list_class_types Odoc_messages.index_of_class_types self#index_class_types;
link_if_not_empty self#list_modules Odoc_messages.index_of_modules self#index_modules;
link_if_not_empty self#list_module_types Odoc_messages.index_of_module_types self#index_module_types;
let print_one m =
let html_file = fst (Naming.html_files m.m_name) in
bp b "<link title=\"%s\" rel=\"Chapter\" href=\"%s\">"
m.m_name html_file
in
print_concat b "\n" print_one module_list;
self#html_sections_links b comments;
bs b "<title>";
bs b t ;
bs b "</title>\n</head>\n"
in
header <- f
(** Build the html code for the link tags in the header, defining section and
subsections for the titles found in the given comments.*)
method html_sections_links b comments =
let titles = List.flatten (List.map Odoc_info.get_titles_in_text comments) in
let levels =
let rec iter acc l =
match l with
[] -> acc
| (n,_,_) :: q ->
if List.mem n acc
then iter acc q
else iter (n::acc) q
in
iter [] titles
in
let sorted_levels = List.sort compare levels in
let (section_level, subsection_level) =
match sorted_levels with
[] -> (None, None)
| [n] -> (Some n, None)
| n :: m :: _ -> (Some n, Some m)
in
let titles_per_level level_opt =
match level_opt with
None -> []
| Some n -> List.filter (fun (m,_,_) -> m = n) titles
in
let section_titles = titles_per_level section_level in
let subsection_titles = titles_per_level subsection_level in
let print_lines s_rel titles =
List.iter
(fun (n,lopt,t) ->
let s = Odoc_info.string_of_text t in
let label = self#create_title_label (n,lopt,t) in
bp b "<link title=\"%s\" rel=\"%s\" href=\"#%s\">\n" s s_rel label
)
titles
in
print_lines "Section" section_titles ;
print_lines "Subsection" subsection_titles
(** Html code for navigation bar.
@param pre optional name for optional previous module/class
@param post optional name for optional next module/class
@param name name of current module/class *)
method print_navbar b pre post name =
if !show_navbar then begin
bs b "<div class=\"navbar\">";
(
match pre with
None -> ()
| Some name ->
bp b "<a class=\"pre\" href=\"%s\" title=\"%s\">%s</a>\n"
(fst (Naming.html_files name))
name
Odoc_messages.previous
);
bs b " ";
let father = Name.father name in
let href = if father = "" then self#index else fst (Naming.html_files father) in
let father_name = if father = "" then "Index" else father in
bp b "<a class=\"up\" href=\"%s\" title=\"%s\">%s</a>\n" href father_name Odoc_messages.up;
bs b " ";
(
match post with
None -> ()
| Some name ->
bp b "<a class=\"post\" href=\"%s\" title=\"%s\">%s</a>\n"
(fst (Naming.html_files name))
name
Odoc_messages.next
);
bs b "</div>\n"
end
(** Return html code with the given string in the keyword style.*)
method keyword s =
"<span class=\"keyword\">"^s^"</span>"
(** Return html code with the given string in the constructor style. *)
method constructor s = "<span class=\"constructor\">"^s^"</span>"
(** Output the given ocaml code to the given file name. *)
method private output_code ?(with_pre=true) in_title file code =
try
let chanout = open_out file in
let b = new_buf () in
bs b "<html>";
self#print_header b (self#inner_title in_title);
bs b"<body>\n";
self#html_of_code ~with_pre b code;
bs b "</body></html>\n";
Buffer.output_buffer chanout b;
close_out chanout
with
Sys_error s ->
incr Odoc_info.errors ;
prerr_endline s
(** Take a string and return the string where fully qualified
type (or class or class type) idents
have been replaced by links to the type referenced by the ident.*)
method create_fully_qualified_idents_links m_name s =
let ln = !Odoc_global.library_namespace in
let f str_t =
let match_s = Str.matched_string str_t in
let known_type = String.Set.mem match_s known_types_names in
let known_class = String.Set.mem match_s known_classes_names in
let retry, match_s = if not (known_type || known_class) && ln <> "" then
true, Name.get_relative_opt ln match_s
else
false, match_s
in
let rel = Name.get_relative m_name match_s in
let s_final = Odoc_info.apply_if_equal
Odoc_info.use_hidden_modules
match_s
rel
in
if known_type ||
(retry && String.Set.mem match_s known_types_names) then
"<a href=\""^(Naming.complete_target Naming.mark_type match_s)^"\">"^
s_final^
"</a>"
else
if known_class ||
(retry && String.Set.mem match_s known_classes_names) then
let (html_file, _) = Naming.html_files match_s in
"<a href=\""^html_file^"\">"^s_final^"</a>"
else
s_final
in
Str.global_substitute
(Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)")
f
s
(** Take a string and return the string where fully qualified module idents
have been replaced by links to the module referenced by the ident.*)
method create_fully_qualified_module_idents_links m_name s =
let f str_t =
let match_s = Str.matched_string str_t in
let known_module = String.Set.mem match_s known_modules_names in
let ln = !Odoc_global.library_namespace in
let retry, match_s =
if not known_module && ln <> "" then
true, Name.get_relative_opt ln match_s
else
false, match_s in
let rel = Name.get_relative m_name match_s in
let s_final = Odoc_info.apply_if_equal
Odoc_info.use_hidden_modules
match_s
rel
in
if known_module ||
(retry && String.Set.mem match_s known_modules_names) then
let (html_file, _) = Naming.html_files match_s in
"<a href=\""^html_file^"\">"^s_final^"</a>"
else
s_final
in
Str.global_substitute
(Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\)\\(\\.[A-Z][a-zA-Z_'0-9]*\\)*")
f
s
(** Print html code to display a [Types.type_expr]. *)
method html_of_type_expr b m_name t =
let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in
let s2 = text_to_html s in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links m_name s2);
bs b "</code>"
(** Print html code to display a [Types.type_expr list]. *)
method html_of_cstr_args ?par b m_name c_name sep l =
match l with
| Cstr_tuple l ->
let s = Odoc_info.string_of_type_list ?par sep l in
let s2 = text_to_html s in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links m_name s2);
bs b "</code>"
| Cstr_record l ->
bs b "<code>";
self#html_of_record ~father:m_name ~close_env: "</code>"
(Naming.inline_recfield_target m_name c_name)
b l
(** Print html code to display a [Types.type_expr list] as type parameters
of a class of class type. *)
method html_of_class_type_param_expr_list b m_name l =
let s = Odoc_info.string_of_class_type_param_list l in
let s2 = text_to_html s in
bs b "<code class=\"type\">[";
bs b (self#create_fully_qualified_idents_links m_name s2);
bs b "]</code>"
method html_of_class_parameter_list b father c =
let s = Odoc_info.string_of_class_params c in
let s = Odoc_info.remove_ending_newline s in
let s2 = text_to_html s in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links father s2);
bs b "</code>"
(** Print html code to display a list of type parameters for the given type.*)
method html_of_type_expr_param_list b m_name t =
let s = Odoc_info.string_of_type_param_list t in
let s2 = text_to_html s in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links m_name s2);
bs b "</code>"
(** Print html code to display a [Types.module_type]. *)
method html_of_module_type b ?code m_name t =
let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_module_type ?code t) in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_module_idents_links m_name s);
bs b "</code>"
(** Print html code to display the given module kind. *)
method html_of_module_kind b father ?modu kind =
match kind with
Module_struct eles ->
self#html_of_text b [Code "sig"];
(
match modu with
None ->
(* first we close the current <pre> tag, since the following
list of module elements is not preformatted *)
bs b "</pre>";
bs b "<div class=\"sig_block\">";
List.iter (self#html_of_module_element b father) eles;
bs b "</div>";
bs b "\n<pre>"
| Some m ->
let (html_file, _) = Naming.html_files m.m_name in
bp b " <a href=\"%s\">..</a> " html_file
);
self#html_of_text b [Code "end"]
| Module_alias a ->
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_module_idents_links father a.ma_name);
bs b "</code>"
| Module_functor (p, k) ->
if !html_short_functors then
bs b " "
else
bs b "<div class=\"sig_block\">";
self#html_of_module_parameter b father p;
(
match k with
Module_functor _ -> ()
| _ when !html_short_functors ->
bs b ": "
| _ -> ()
);
self#html_of_module_kind b father ?modu k;
if not !html_short_functors then
bs b "</div>"
| Module_apply (k1, k2) ->
(* TODO: application is not correct in a .mli.
What to do -> print typedtree module_type *)
self#html_of_module_kind b father k1;
self#html_of_text b [Code "("];
self#html_of_module_kind b father k2;
self#html_of_text b [Code ")"]
| Module_apply_unit k1 ->
self#html_of_module_kind b father k1;
self#html_of_text b [Code "()"]
| Module_with (k, s) ->
(* TODO: modify when Module_with will be more detailed *)
self#html_of_module_type_kind b father ?modu k;
bs b "<code class=\"type\"> ";
bs b (self#create_fully_qualified_module_idents_links father s);
bs b "</code>"
| Module_constraint (k, _tk) ->
(* TODO: what to print ? *)
self#html_of_module_kind b father ?modu k
| Module_typeof s ->
bs b "<code class=\"type\">module type of ";
bs b (self#create_fully_qualified_module_idents_links father s);
bs b "</code>"
| Module_unpack (code, mta) ->
bs b "<code class=\"type\">";
begin
match mta.mta_module with
None ->
bs b (self#create_fully_qualified_module_idents_links father (self#escape code))
| Some mt ->
let (html_file, _) = Naming.html_files mt.mt_name in
bp b " <a href=\"%s\">%s</a> " html_file (self#escape code)
end;
bs b "</code>"
method html_of_module_parameter b father p =
let (s_functor,s_arrow) =
if !html_short_functors then
"", ""
else
"functor ", "-> "
in
self#html_of_text b
[
Code (s_functor^"(");
Code p.mp_name ;
Code " : ";
] ;
self#html_of_module_type_kind b father p.mp_kind;
self#html_of_text b [ Code (") "^s_arrow)]
method html_of_module_element b m_name ele =
match ele with
Element_module m ->
self#html_of_module b ~complete: false m
| Element_module_type mt ->
self#html_of_modtype b ~complete: false mt
| Element_included_module im ->
self#html_of_included_module b im
| Element_class c ->
self#html_of_class b ~complete: false c
| Element_class_type ct ->
self#html_of_class_type b ~complete: false ct
| Element_value v ->
self#html_of_value b v
| Element_type_extension te ->
self#html_of_type_extension b m_name te
| Element_exception e ->
self#html_of_exception b e
| Element_type t ->
self#html_of_type b t
| Element_module_comment text ->
self#html_of_module_comment b text
(** Print html code to display the given module type kind. *)
method html_of_module_type_kind b father ?modu ?mt kind =
match kind with
Module_type_struct eles ->
self#html_of_text b [Code "sig"];
(
match mt with
None ->
(
match modu with
None ->
(*close the current <pre> tag, to avoid anarchic line breaks
in the list of module elements *)
bs b "</pre>";
bs b "<div class=\"sig_block\">";
List.iter (self#html_of_module_element b father) eles;
bs b "</div>";
bs b "<pre>";
| Some m ->
let (html_file, _) = Naming.html_files m.m_name in
bp b " <a href=\"%s\">..</a> " html_file
)
| Some mt ->
let (html_file, _) = Naming.html_files mt.mt_name in
bp b " <a href=\"%s\">..</a> " html_file
);
self#html_of_text b [Code "end"]
| Module_type_functor (p, k) ->
self#html_of_module_parameter b father p;
self#html_of_module_type_kind b father ?modu ?mt k
| Module_type_alias a ->
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_module_idents_links father a.mta_name);
bs b "</code>"
| Module_type_with (k, s) ->
self#html_of_module_type_kind b father ?modu ?mt k;
bs b "<code class=\"type\"> ";
bs b (self#create_fully_qualified_module_idents_links father s);
bs b "</code>"
| Module_type_typeof s ->
bs b "<code class=\"type\">module type of ";
bs b (self#create_fully_qualified_module_idents_links father s);
bs b "</code>"
(** Print html code to display the type of a module parameter.. *)
method html_of_module_parameter_type b m_name p =
match p.mp_type with None -> bs b "<code>()</code>"
| Some mty -> self#html_of_module_type b m_name ~code: p.mp_type_code mty
(** Generate a file containing the module type in the given file name. *)
method output_module_type in_title file mtyp =
let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_module_type ~complete: true mtyp) in
self#output_code ~with_pre:false in_title file s
(** Generate a file containing the class type in the given file name. *)
method output_class_type in_title file ctyp =
let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_class_type ~complete: true ctyp) in
self#output_code ~with_pre:false in_title file s
(** Print html code for a value. *)
method html_of_value b v =
Odoc_info.reset_type_names ();
bs b "\n<pre>" ;
bp b "<span id=\"%s\">" (Naming.value_target v);
bs b (self#keyword "val");
bs b " ";
(
match v.val_code with
None -> bs b (self#escape (Name.simple v.val_name))
| Some c ->
let file = Naming.file_code_value_complete_target v in
self#output_code v.val_name (Filename.concat !Global.target_dir file) c;
bp b "<a href=\"%s\">%s</a>" file (self#escape (Name.simple v.val_name))
);
bs b "</span>";
bs b " : ";
self#html_of_type_expr b (Name.father v.val_name) v.val_type;
bs b "</pre>";
self#html_of_info b v.val_info;
(
if !with_parameter_list then
self#html_of_parameter_list b (Name.father v.val_name) v.val_parameters
else
self#html_of_described_parameter_list b (Name.father v.val_name) v.val_parameters
)
(** Print html code for a type extension. *)
method html_of_type_extension b m_name te =
Odoc_info.reset_type_names ();
bs b "<pre><code>";
bs b ((self#keyword "type")^" ");
let s = Odoc_info.string_of_type_extension_param_list te in
let s2 = text_to_html s in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links m_name s2);
bs b "</code>";
(match te.te_type_parameters with [] -> () | _ -> bs b " ");
bs b (self#create_fully_qualified_idents_links m_name te.te_type_name);
bs b " += ";
if te.te_private = Asttypes.Private then bs b "private ";
bs b "</code></pre>";
bs b "<table class=\"typetable\">\n";
let print_one x =
let father = Name.father x.xt_name in
let cname = Name.simple x.xt_name in
bs b "<tr>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code>";
bs b (self#keyword "|");
bs b "</code></td>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code>";
bp b "<span id=\"%s\">%s</span>"
(Naming.extension_target x)
cname;
(
match x.xt_args, x.xt_ret with
Cstr_tuple [], None -> ()
| l,None ->
bs b (" " ^ (self#keyword "of") ^ " ");
self#html_of_cstr_args ~par: false b father cname " * " l;
| Cstr_tuple [],Some r ->
bs b (" " ^ (self#keyword ":") ^ " ");
self#html_of_type_expr b father r;
| l,Some r ->
bs b (" " ^ (self#keyword ":") ^ " ");
self#html_of_cstr_args ~par: false b father cname " * " l;
bs b (" " ^ (self#keyword "->") ^ " ");
self#html_of_type_expr b father r;
);
(
match x.xt_alias with
None -> ()
| Some xa ->
bs b " = ";
(
match xa.xa_xt with
None -> bs b xa.xa_name
| Some x ->
bp b "<a href=\"%s\">%s</a>" (Naming.complete_extension_target x) x.xt_name
)
);
bs b "</code></td>\n";
(
match x.xt_text with
None -> ()
| Some t ->
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
bs b "<code>";
bs b "(*";
bs b "</code></td>";
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
self#html_of_info b (Some t);
bs b "</td>";
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
bs b "<code>";
bs b "*)";
bs b "</code></td>";
);
bs b "\n</tr>"
in
print_concat b "\n" print_one te.te_constructors;
bs b "</table>\n";
bs b "\n";
self#html_of_info b te.te_info;
bs b "\n"
(** Print html code for an exception. *)
method html_of_exception b e =
let cname = Name.simple e.ex_name in
Odoc_info.reset_type_names ();
bs b "\n<pre>";
bp b "<span id=\"%s\">" (Naming.exception_target e);
bs b (self#keyword "exception");
bs b " ";
bs b cname;
bs b "</span>";
(
let father = Name.father e.ex_name in
match e.ex_args, e.ex_ret with
Cstr_tuple [], None -> ()
| _,None ->
bs b (" "^(self#keyword "of")^" ");
self#html_of_cstr_args
~par:false b father cname " * " e.ex_args
| Cstr_tuple [],Some r ->
bs b (" " ^ (self#keyword ":") ^ " ");
self#html_of_type_expr b father r;
| l,Some r ->
bs b (" " ^ (self#keyword ":") ^ " ");
self#html_of_cstr_args
~par:false b father cname " * " l;
bs b (" " ^ (self#keyword "->") ^ " ");
self#html_of_type_expr b father r;
);
(
match e.ex_alias with
None -> ()
| Some ea ->
bs b " = ";
(
match ea.ea_ex with
None -> bs b ea.ea_name
| Some e ->
bp b "<a href=\"%s\">%s</a>" (Naming.complete_exception_target e) e.ex_name
)
);
bs b "</pre>\n";
self#html_of_info b e.ex_info
method html_of_record ~father ~close_env gen_name b l =
bs b "{";
bs b close_env;
bs b "<table class=\"typetable\">\n" ;
let print_one r =
bs b "<tr>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code> </code>";
bs b "</td>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code>";
if r.rf_mutable then bs b (self#keyword "mutable ") ;
bp b "<span id=\"%s\">%s</span> : " (gen_name r) r.rf_name;
self#html_of_type_expr b father r.rf_type;
bs b ";</code></td>\n";
(
match r.rf_text with
None -> ()
| Some t ->
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
bs b "<code>";
bs b "(*";
bs b "</code></td>";
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
self#html_of_info b (Some t);
bs b "</td><td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
bs b "<code>*)</code></td>";
);
bs b "\n</tr>"
in
print_concat b "\n" print_one l;
bs b "</table>\n<code>}</code>\n"
(** Print html code for a type. *)
method html_of_type b t =
Odoc_info.reset_type_names ();
let father = Name.father t.ty_name in
let print_field_prefix () =
bs b "<tr>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code> </code>";
bs b "</td>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code>";
in
let print_field_comment = function
| None -> ()
| Some t ->
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
bs b "<code>";
bs b "(*";
bs b "</code></td>";
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
self#html_of_info b (Some t);
bs b "</td><td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
bs b "<code>*)</code></td>"
in
bs b
(match t.ty_manifest, t.ty_kind with
None, Type_abstract
| None, Type_open -> "\n<pre>"
| None, Type_variant _
| None, Type_record _ -> "\n<pre><code>"
| Some _, Type_abstract
| Some _, Type_open -> "\n<pre>"
| Some _, Type_variant _
| Some _, Type_record _ -> "\n<pre>"
);
bp b "<span id=\"%s\">" (Naming.type_target t);
bs b ((self#keyword "type")^" ");
self#html_of_type_expr_param_list b father t;
(match t.ty_parameters with [] -> () | _ -> bs b " ");
bs b (Name.simple t.ty_name);
bs b "</span> ";
let priv = t.ty_private = Asttypes.Private in
(
match t.ty_manifest with
None -> ()
| Some (Object_type fields) ->
bs b "= ";
if priv then bs b "private ";
bs b "<</pre>";
bs b "<table class=\"typetable\">\n" ;
let print_one f =
print_field_prefix () ;
bp b "<span id=\"%s\">%s</span> : "
(Naming.objfield_target t f)
f.of_name;
self#html_of_type_expr b father f.of_type;
bs b ";</code></td>\n";
print_field_comment f.of_text ;
bs b "\n</tr>"
in
print_concat b "\n" print_one fields;
bs b "</table>\n>\n";
bs b " "
| Some (Other typ) ->
bs b "= ";
if priv then bs b "private ";
self#html_of_type_expr b father typ;
bs b " "
);
(match t.ty_kind with
Type_abstract -> bs b "</pre>"
| Type_variant l ->
bs b "= ";
if priv then bs b "private ";
bs b
(
match t.ty_manifest with
None -> "</code></pre>"
| Some _ -> "</pre>"
);
bs b "<table class=\"typetable\">\n";
let print_bar () =
bs b "<tr>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code>";
bs b (self#keyword "|");
bs b "</code></td>\n<td align=\"left\" valign=\"top\" >\n";
bs b "<code>" in
let print_one constr =
print_bar ();
bp b "<span id=\"%s\">%s</span>"
(Naming.const_target t constr)
(self#constructor constr.vc_name);
(
match constr.vc_args, constr.vc_ret with
Cstr_tuple [], None -> ()
| l,None ->
bs b (" " ^ (self#keyword "of") ^ " ");
self#html_of_cstr_args ~par:false b father constr.vc_name " * " l;
| Cstr_tuple [],Some r ->
bs b (" " ^ (self#keyword ":") ^ " ");
self#html_of_type_expr b father r;
| l,Some r ->
bs b (" " ^ (self#keyword ":") ^ " ");
self#html_of_cstr_args ~par: false b father constr.vc_name " * " l;
bs b (" " ^ (self#keyword "->") ^ " ");
self#html_of_type_expr b father r;
);
bs b "</code></td>\n";
(
match constr.vc_text with
None -> ()
| Some t ->
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
bs b "<code>";
bs b "(*";
bs b "</code></td>";
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
self#html_of_info b (Some t);
bs b "</td>";
bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
bs b "<code>";
bs b "*)";
bs b "</code></td>";
);
bs b "\n</tr>"
in
if l = [] then print_bar () else
print_concat b "\n" print_one l;
bs b "</table>\n"
| Type_record l ->
bs b "= ";
if priv then bs b "private " ;
let close_env = match t.ty_manifest with
None -> "</code></pre>"
| Some _ -> "</pre>" in
self#html_of_record ~father ~close_env (Naming.recfield_target t) b l
| Type_open ->
bs b "= ..";
bs b "</pre>"
);
bs b "\n";
self#html_of_info b t.ty_info;
bs b "\n"
(** Print html code for a class attribute. *)
method html_of_attribute b a =
let module_name = Name.father (Name.father a.att_value.val_name) in
bs b "\n<pre>" ;
bp b "<span id=\"%s\">" (Naming.attribute_target a);
bs b (self#keyword "val");
bs b " ";
(
if a.att_virtual then
bs b ((self#keyword "virtual")^ " ")
else
()
);
(
if a.att_mutable then
bs b ((self#keyword Odoc_messages.mutab)^ " ")
else
()
);(
match a.att_value.val_code with
None -> bs b (Name.simple a.att_value.val_name)
| Some c ->
let file = Naming.file_code_attribute_complete_target a in
self#output_code a.att_value.val_name (Filename.concat !Global.target_dir file) c;
bp b "<a href=\"%s\">%s</a>" file (Name.simple a.att_value.val_name);
);
bs b "</span>";
bs b " : ";
self#html_of_type_expr b module_name a.att_value.val_type;
bs b "</pre>";
self#html_of_info b a.att_value.val_info
(** Print html code for a class method. *)
method html_of_method b m =
let module_name = Name.father (Name.father m.met_value.val_name) in
bs b "\n<pre>";
(* html mark *)
bp b "<span id=\"%s\">" (Naming.method_target m);
bs b ((self#keyword "method")^" ");
if m.met_private then bs b ((self#keyword "private")^" ");
if m.met_virtual then bs b ((self#keyword "virtual")^" ");
(
match m.met_value.val_code with
None -> bs b (Name.simple m.met_value.val_name)
| Some c ->
let file = Naming.file_code_method_complete_target m in
self#output_code m.met_value.val_name (Filename.concat !Global.target_dir file) c;
bp b "<a href=\"%s\">%s</a>" file (Name.simple m.met_value.val_name);
);
bs b "</span>";
bs b " : ";
self#html_of_type_expr b module_name m.met_value.val_type;
bs b "</pre>";
self#html_of_info b m.met_value.val_info;
(
if !with_parameter_list then
self#html_of_parameter_list b
module_name m.met_value.val_parameters
else
self#html_of_described_parameter_list b
module_name m.met_value.val_parameters
)
(** Print html code for the description of a function parameter. *)
method html_of_parameter_description b p =
match Parameter.names p with
[] ->
()
| name :: [] ->
(
(* Only one name, no need for label for the description. *)
match Parameter.desc_by_name p name with
None -> ()
| Some t -> self#html_of_text b t
)
| l ->
(* A list of names, we display those with a description. *)
let l2 = List.filter
(fun n -> (Parameter.desc_by_name p n) <> None)
l
in
let print_one n =
match Parameter.desc_by_name p n with
None -> ()
| Some t ->
bs b "<div class=\"parameter-desc\">\n";
bs b "<code>";
bs b n;
bs b "</code> : ";
self#html_of_text b t;
bs b "</div>\n"
in
List.iter print_one l2
(** Print html code for a list of parameters. *)
method html_of_parameter_list b m_name l =
match l with
[] -> ()
| _ ->
bs b "<div class=\"param_info\">";
bs b "<table border=\"0\" cellpadding=\"3\" width=\"100%\">\n";
bs b "<tr>\n<td align=\"left\" valign=\"top\" width=\"1%\">";
bs b "<b>";
bs b Odoc_messages.parameters;
bs b ": </b></td>\n" ;
bs b "<td>\n<table class=\"paramstable\">\n";
let print_one p =
bs b "<tr>\n<td align=\"center\" valign=\"top\" width=\"15%\" class=\"code\">\n";
bs b
(
match Parameter.complete_name p with
"" -> "?"
| s -> s
);
bs b "</td>\n<td align=\"center\" valign=\"top\">:</td>\n";
bs b "<td>";
bs b "<div class=\"paramer-type\">\n";
self#html_of_type_expr b m_name (Parameter.typ p);
bs b "<div>\n";
self#html_of_parameter_description b p;
bs b "\n</tr>\n";
in
List.iter print_one l;
bs b "</table>\n</td>\n</tr>\n</table></div>\n"
(** Print html code for the parameters which have a name and description. *)
method html_of_described_parameter_list b _m_name l =
(* get the params which have a name, and at least one name described. *)
let l2 = List.filter
(fun p ->
List.exists
(fun n -> (Parameter.desc_by_name p n) <> None)
(Parameter.names p))
l
in
let f p =
bs b "<div class=\"param_info\"><code class=\"code\">";
bs b (Parameter.complete_name p);
bs b "</code> : " ;
self#html_of_parameter_description b p;
bs b "</div>\n"
in
List.iter f l2
(** Print html code for a list of module parameters. *)
method html_of_module_parameter_list b m_name l =
match l with
[] ->
()
| _ ->
bs b "<table border=\"0\" cellpadding=\"3\" width=\"100%\">\n";
bs b "<tr>\n";
bs b "<td align=\"left\" valign=\"top\" width=\"1%%\"><b>";
bs b Odoc_messages.parameters ;
bs b ": </b></td>\n<td>\n";
bs b "<table class=\"paramstable\">\n";
List.iter
(fun (p, desc_opt) ->
bs b "<tr>\n";
bs b "<td align=\"center\" valign=\"top\" width=\"15%\">\n<code>" ;
bs b p.mp_name;
bs b "</code></td>\n" ;
bs b "<td align=\"center\" valign=\"top\">:</td>\n";
bs b "<td>" ;
self#html_of_module_parameter_type b m_name p;
bs b "\n";
(
match desc_opt with
None -> ()
| Some t ->
bs b "<div class=\"parameter-desc\" >";
self#html_of_text b t;
bs b "\n</div>\n";
bs b "\n</tr>\n" ;
)
)
l;
bs b "</table>\n</td>\n</tr>\n</table>\n"
(** Print html code for a module. *)
method html_of_module b ?(info=true) ?(complete=true) ?(with_link=true) m =
let (html_file, _) = Naming.html_files m.m_name in
let father = Name.father m.m_name in
bs b "\n<pre>";
bp b "<span id=\"%s\">" (Naming.module_target m);
bs b ((self#keyword "module")^" ");
(
if with_link then
bp b "<a href=\"%s\">%s</a>" html_file (Name.simple m.m_name)
else
bs b (Name.simple m.m_name)
);
bs b "</span>" ;
(
match m.m_kind with
Module_functor _ when !html_short_functors ->
()
| _ -> bs b ": "
);
self#html_of_module_kind b father ~modu: m m.m_kind;
bs b "</pre>";
if info then
(
if complete then
self#html_of_info ~cls: "module top" ~indent: true
else
self#html_of_info_first_sentence
) b m.m_info
else
()
(** Print html code for a module type. *)
method html_of_modtype b ?(info=true) ?(complete=true) ?(with_link=true) mt =
let (html_file, _) = Naming.html_files mt.mt_name in
let father = Name.father mt.mt_name in
bs b "\n<pre>";
bp b "<span id=\"%s\">" (Naming.module_type_target mt);
bs b (self#keyword "module type" ^ " ");
(
if with_link then
bp b "<a href=\"%s\">%s</a>" html_file (Name.simple mt.mt_name)
else
bs b (Name.simple mt.mt_name)
);
bs b "</span>";
(match mt.mt_kind with
None -> ()
| Some k ->
bs b " = ";
self#html_of_module_type_kind b father ~mt k
);
bs b "</pre>";
if info then
(
if complete then
self#html_of_info ~cls: "modtype top" ~indent: true
else
self#html_of_info_first_sentence
) b mt.mt_info
else
()
(** Print html code for an included module. *)
method html_of_included_module b im =
bs b "\n<pre>";
bs b ((self#keyword "include")^" ");
(
match im.im_module with
None ->
bs b im.im_name
| Some mmt ->
let (file, name) =
match mmt with
Mod m ->
let (html_file, _) = Naming.html_files m.m_name in
(html_file, m.m_name)
| Modtype mt ->
let (html_file, _) = Naming.html_files mt.mt_name in
(html_file, mt.mt_name)
in
bp b "<a href=\"%s\">%s</a>" file name
);
bs b "</pre>\n";
self#html_of_info b im.im_info
method html_of_class_element b element =
match element with
Class_attribute a ->
self#html_of_attribute b a
| Class_method m ->
self#html_of_method b m
| Class_comment t ->
self#html_of_class_comment b t
method html_of_class_kind b father ?cl kind =
match kind with
Class_structure (inh, eles) ->
self#html_of_text b [Code "object"];
(
match cl with
None ->
bs b "\n";
(
match inh with
[] -> ()
| _ ->
self#generate_inheritance_info b inh
);
List.iter (self#html_of_class_element b) eles;
| Some cl ->
let (html_file, _) = Naming.html_files cl.cl_name in
bp b " <a href=\"%s\">..</a> " html_file
);
self#html_of_text b [Code "end"]
| Class_apply _ ->
(* TODO: display final type from typedtree *)
self#html_of_text b [Raw "class application not handled yet"]
| Class_constr cco ->
(
match cco.cco_type_parameters with
[] -> ()
| l ->
self#html_of_class_type_param_expr_list b father l;
bs b " "
);
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links father cco.cco_name);
bs b "</code>"
| Class_constraint (ck, ctk) ->
self#html_of_text b [Code "( "] ;
self#html_of_class_kind b father ck;
self#html_of_text b [Code " : "] ;
self#html_of_class_type_kind b father ctk;
self#html_of_text b [Code " )"]
method html_of_class_type_kind b father ?ct kind =
match kind with
Class_type cta ->
(
match cta.cta_type_parameters with
[] -> ()
| l ->
self#html_of_class_type_param_expr_list b father l;
bs b " "
);
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links father cta.cta_name);
bs b "</code>"
| Class_signature (inh, eles) ->
self#html_of_text b [Code "object"];
(
match ct with
None ->
bs b "\n";
(
match inh with
[] -> ()
| _ -> self#generate_inheritance_info b inh
);
List.iter (self#html_of_class_element b) eles
| Some ct ->
let (html_file, _) = Naming.html_files ct.clt_name in
bp b " <a href=\"%s\">..</a> " html_file
);
self#html_of_text b [Code "end"]
(** Print html code for a class. *)
method html_of_class b ?(complete=true) ?(with_link=true) c =
let father = Name.father c.cl_name in
Odoc_info.reset_type_names ();
let (html_file, _) = Naming.html_files c.cl_name in
bs b "\n<pre>";
(* we add a html id, the same as for a type so we can
go directly here when the class name is used as a type name *)
bp b "<span id=\"%s\">"
(Naming.type_target
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
ty_kind = Type_abstract ; ty_private = Asttypes.Public;
ty_manifest = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
);
bs b ((self#keyword "class")^" ");
if c.cl_virtual then bs b ((self#keyword "virtual")^" ");
(
match c.cl_type_parameters with
[] -> ()
| l ->
self#html_of_class_type_param_expr_list b father l;
bs b " "
);
(
if with_link then
bp b "<a href=\"%s\">%s</a>" html_file (Name.simple c.cl_name)
else
bs b (Name.simple c.cl_name)
);
bs b "</span>";
bs b " : " ;
self#html_of_class_parameter_list b father c ;
self#html_of_class_kind b father ~cl: c c.cl_kind;
bs b "</pre>" ;
(
if complete then
self#html_of_info ~cls: "class top" ~indent: true
else
self#html_of_info_first_sentence
) b c.cl_info
(** Print html code for a class type. *)
method html_of_class_type b ?(complete=true) ?(with_link=true) ct =
Odoc_info.reset_type_names ();
let father = Name.father ct.clt_name in
let (html_file, _) = Naming.html_files ct.clt_name in
bs b "\n<pre>";
(* we add a html id, the same as for a type so we can
go directly here when the class type name is used as a type name *)
bp b "<span id=\"%s\">"
(Naming.type_target
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
ty_kind = Type_abstract ; ty_private = Asttypes.Public; ty_manifest = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
);
bs b ((self#keyword "class type")^" ");
if ct.clt_virtual then bs b ((self#keyword "virtual")^" ");
(
match ct.clt_type_parameters with
[] -> ()
| l ->
self#html_of_class_type_param_expr_list b father l;
bs b " "
);
if with_link then
bp b "<a href=\"%s\">%s</a>" html_file (Name.simple ct.clt_name)
else
bs b (Name.simple ct.clt_name);
bs b "</span>";
bs b " = ";
self#html_of_class_type_kind b father ~ct ct.clt_kind;
bs b "</pre>";
(
if complete then
self#html_of_info ~cls: "classtype top" ~indent: true
else
self#html_of_info_first_sentence
) b ct.clt_info
(** Return html code to represent a dag, represented as in Odoc_dag2html. *)
method html_of_dag dag =
let f n =
let (name, cct_opt) = n.Odoc_dag2html.valu in
(* if we have a c_opt = Some class then we take its information
because we are sure the name is complete. *)
let (name2, html_file) =
match cct_opt with
None -> (name, fst (Naming.html_files name))
| Some (Cl c) -> (c.cl_name, fst (Naming.html_files c.cl_name))
| Some (Cltype (ct, _)) -> (ct.clt_name, fst (Naming.html_files ct.clt_name))
in
let new_v =
"<table border=1>\n<tr><td>"^
"<a href=\""^html_file^"\">"^name2^"</a>"^
"</td></tr>\n</table>\n"
in
{ n with Odoc_dag2html.valu = new_v }
in
let a = Array.map f dag.Odoc_dag2html.dag in
Odoc_dag2html.html_of_dag { Odoc_dag2html.dag = a }
(** Print html code for a module comment.*)
method html_of_module_comment b text =
self#html_of_text ~with_p:true b text
(** Print html code for a class comment.*)
method html_of_class_comment b text =
(* Add some style if there is no style for the first part of the text. *)
let text2 =
match text with
| (Odoc_info.Raw s) :: q ->
(Odoc_info.Title (1, None, [Odoc_info.Raw s])) :: q
| _ -> text
in
self#html_of_text ~with_p:true b text2
(** Generate html code for the given list of inherited classes.*)
method generate_inheritance_info b inher_l =
let f inh =
match inh.ic_class with
None -> (* we can't make the link. *)
(Odoc_info.Code inh.ic_name) ::
(match inh.ic_text with
None -> []
| Some t -> (Odoc_info.Raw " ") :: t)
| Some cct ->
(* we can create the link. *)
let real_name = (* even if it should be the same *)
match cct with
Cl c -> c.cl_name
| Cltype (ct, _) -> ct.clt_name
in
let (class_file, _) = Naming.html_files real_name in
(Odoc_info.Link (class_file, [Odoc_info.Code real_name])) ::
(match inh.ic_text with
None -> []
| Some t -> (Odoc_info.Raw " ") :: t)
in
let text = [
Odoc_info.Bold [Odoc_info.Raw Odoc_messages.inherits] ;
Odoc_info.List (List.map f inher_l)
]
in
self#html_of_text b text
(** Generate html code for the inherited classes of the given class. *)
method generate_class_inheritance_info b cl =
let rec iter_kind k =
match k with
Class_structure ([], _) ->
()
| Class_structure (l, _) ->
self#generate_inheritance_info b l
| Class_constraint (k, _) ->
iter_kind k
| Class_apply _
| Class_constr _ ->
()
in
iter_kind cl.cl_kind
(** Generate html code for the inherited classes of the given class type. *)
method generate_class_type_inheritance_info b clt =
match clt.clt_kind with
Class_signature ([], _) ->
()
| Class_signature (l, _) ->
self#generate_inheritance_info b l
| Class_type _ ->
()
(** A method to create index files. *)
method generate_elements_index :
'a.
?strip_libname:bool ->
'a list ->
('a -> Odoc_info.Name.t) ->
('a -> Odoc_info.info option) ->
('a -> string) -> string -> string -> unit =
fun ?(strip_libname=false) elements name info target title simple_file ->
try
let chanout = open_out (Filename.concat !Global.target_dir simple_file) in
let b = new_buf () in
bs b "<html>\n";
self#print_header b (self#inner_title title);
bs b "<body>\n";
self#print_navbar b None None "";
bs b "<h1>";
bs b title;
bs b "</h1>\n" ;
let sorted_elements = List.sort
(fun e1 e2 -> compare (Name.simple (name e1)) (Name.simple (name e2)))
elements
in
let groups = Odoc_info.create_index_lists sorted_elements (fun e -> Name.simple (name e)) in
let f_ele e =
let simple_name = Name.simple (name e) in
let father_name = Name.father (name e) in
if strip_libname &&
!Odoc_global.library_namespace <> "" &&
father_name = !Odoc_global.library_namespace &&
father_name <> simple_name then
(* avoid duplicata *) ()
else
begin
bp b "<tr><td><a href=\"%s\">%s</a> " (target e) (self#escape simple_name);
if simple_name <> father_name && father_name <> "" then
bp b "[<a href=\"%s\">%s</a>]" (fst (Naming.html_files father_name)) father_name;
bs b "</td>\n<td>";
self#html_of_info_first_sentence b (info e);
bs b "</td></tr>\n"
end
in
let f_group l =
match l with
[] -> ()
| e :: _ ->
let s =
match (Char.uppercase_ascii (Name.simple (name e)).[0]) with
'A'..'Z' as c -> String.make 1 c
| _ -> ""
in
bs b "<tr><td align=\"left\"><div>";
bs b s ;
bs b "</div></td></tr>\n" ;
List.iter f_ele l
in
bs b "<table>\n";
List.iter f_group groups ;
bs b "</table>\n" ;
bs b "</body>\n</html>\n";
Buffer.output_buffer chanout b;
close_out chanout
with
Sys_error s ->
raise (Failure s)
(** A method to generate a list of module/class files. *)
method generate_elements :
'a. ('a option -> 'a option -> 'a -> unit) -> 'a list -> unit =
fun f_generate l ->
let rec iter pre_opt = function
[] -> ()
| ele :: [] -> f_generate pre_opt None ele
| ele1 :: ele2 :: q ->
f_generate pre_opt (Some ele2) ele1 ;
iter (Some ele1) (ele2 :: q)
in
iter None l
(** Generate the code of the html page for the given class.*)
method generate_for_class pre post cl =
Odoc_info.reset_type_names ();
let (html_file, _) = Naming.html_files cl.cl_name in
let type_file = Naming.file_type_class_complete_target cl.cl_name in
try
let chanout = open_out (Filename.concat !Global.target_dir html_file) in
let b = new_buf () in
let pre_name = opt (fun c -> c.cl_name) pre in
let post_name = opt (fun c -> c.cl_name) post in
bs b doctype ;
bs b "<html>\n";
self#print_header b
~nav: (Some (pre_name, post_name, cl.cl_name))
~comments: (Class.class_comments cl)
(self#inner_title cl.cl_name);
bs b "<body>\n";
self#print_navbar b pre_name post_name cl.cl_name;
bs b "<h1>";
bs b (Odoc_messages.clas^" ");
if cl.cl_virtual then bs b "virtual " ;
bp b "<a href=\"%s\">%s</a>" type_file cl.cl_name;
bs b "</h1>\n";
self#html_of_class b ~with_link: false cl;
(* parameters *)
self#html_of_described_parameter_list b
(Name.father cl.cl_name) cl.cl_parameters;
(* class inheritance *)
self#generate_class_inheritance_info b cl;
(* a horizontal line *)
bs b "<hr width=\"100%\">\n";
(* the various elements *)
List.iter (self#html_of_class_element b)
(Class.class_elements ~trans:false cl);
bs b "</body></html>\n";
Buffer.output_buffer chanout b;
close_out chanout;
(* generate the file with the complete class type *)
self#output_class_type
cl.cl_name
(Filename.concat !Global.target_dir type_file)
cl.cl_type
with
Sys_error s ->
raise (Failure s)
(** Generate the code of the html page for the given class type.*)
method generate_for_class_type pre post clt =
Odoc_info.reset_type_names ();
let (html_file, _) = Naming.html_files clt.clt_name in
let type_file = Naming.file_type_class_complete_target clt.clt_name in
try
let chanout = open_out (Filename.concat !Global.target_dir html_file) in
let b = new_buf () in
let pre_name = opt (fun ct -> ct.clt_name) pre in
let post_name = opt (fun ct -> ct.clt_name) post in
bs b doctype ;
bs b "<html>\n";
self#print_header b
~nav: (Some (pre_name, post_name, clt.clt_name))
~comments: (Class.class_type_comments clt)
(self#inner_title clt.clt_name);
bs b "<body>\n";
self#print_navbar b pre_name post_name clt.clt_name;
bs b "<h1>";
bs b (Odoc_messages.class_type^" ");
if clt.clt_virtual then bs b "virtual ";
bp b "<a href=\"%s\">%s</a>" type_file clt.clt_name;
bs b "</h1>\n";
self#html_of_class_type b ~with_link: false clt;
(* class inheritance *)
self#generate_class_type_inheritance_info b clt;
(* a horizontal line *)
bs b "<hr width=\"100%\">\n";
(* the various elements *)
List.iter (self#html_of_class_element b)
(Class.class_type_elements ~trans: false clt);
bs b "</body></html>\n";
Buffer.output_buffer chanout b;
close_out chanout;
(* generate the file with the complete class type *)
self#output_class_type
clt.clt_name
(Filename.concat !Global.target_dir type_file)
clt.clt_type
with
Sys_error s ->
raise (Failure s)
(** Generate the html file for the given module type.
@raise Failure if an error occurs.*)
method generate_for_module_type pre post mt =
try
let (html_file, _) = Naming.html_files mt.mt_name in
let type_file = Naming.file_type_module_complete_target mt.mt_name in
let chanout = open_out (Filename.concat !Global.target_dir html_file) in
let b = new_buf () in
let pre_name = opt (fun mt -> mt.mt_name) pre in
let post_name = opt (fun mt -> mt.mt_name) post in
bs b doctype ;
bs b "<html>\n";
self#print_header b
~nav: (Some (pre_name, post_name, mt.mt_name))
~comments: (Module.module_type_comments mt)
(self#inner_title mt.mt_name);
bs b "<body>\n";
self#print_navbar b pre_name post_name mt.mt_name;
bp b "<h1>";
bs b (Odoc_messages.module_type^" ");
(
match mt.mt_type with
Some _ -> bp b "<a href=\"%s\">%s</a>" type_file mt.mt_name
| None-> bs b mt.mt_name
);
bs b "</h1>\n" ;
self#html_of_modtype b ~with_link: false mt;
(* parameters for functors *)
self#html_of_module_parameter_list b
(Name.father mt.mt_name)
(Module.module_type_parameters mt);
(* a horizontal line *)
bs b "<hr width=\"100%\">\n";
(* module elements *)
List.iter
(self#html_of_module_element b mt.mt_name)
(Module.module_type_elements mt);
bs b "</body></html>\n";
Buffer.output_buffer chanout b;
close_out chanout;
(* generate html files for submodules *)
self#generate_elements self#generate_for_module (Module.module_type_modules mt);
(* generate html files for module types *)
self#generate_elements self#generate_for_module_type (Module.module_type_module_types mt);
(* generate html files for classes *)
self#generate_elements self#generate_for_class (Module.module_type_classes mt);
(* generate html files for class types *)
self#generate_elements self#generate_for_class_type (Module.module_type_class_types mt);
(* generate the file with the complete module type *)
(
match mt.mt_type with
None -> ()
| Some mty ->
self#output_module_type
mt.mt_name
(Filename.concat !Global.target_dir type_file)
mty
)
with
Sys_error s ->
raise (Failure s)
(** Generate the html file for the given module.
@raise Failure if an error occurs.*)
method generate_for_module pre post modu =
try
Odoc_info.verbose ("Generate for module "^modu.m_name);
let (html_file, _) = Naming.html_files modu.m_name in
let type_file = Naming.file_type_module_complete_target modu.m_name in
let code_file = Naming.file_code_module_complete_target modu.m_name in
let chanout = open_out (Filename.concat !Global.target_dir html_file) in
let b = new_buf () in
let pre_name = opt (fun m -> m.m_name) pre in
let post_name = opt (fun m -> m.m_name) post in
bs b doctype ;
bs b "<html>\n";
self#print_header b
~nav: (Some (pre_name, post_name, modu.m_name))
~comments: (Module.module_comments modu)
(self#inner_title modu.m_name);
bs b "<body>\n" ;
self#print_navbar b pre_name post_name modu.m_name ;
bs b "<h1>";
if modu.m_text_only then
bs b modu.m_name
else
(
bs b
(
if Module.module_is_functor modu then
Odoc_messages.functo
else
Odoc_messages.modul
);
bp b " <a href=\"%s\">%s</a>" type_file modu.m_name;
(
match modu.m_code with
None -> ()
| Some _ -> bp b " (<a href=\"%s\">.ml</a>)" code_file
)
);
bs b "</h1>\n";
if not modu.m_text_only then
self#html_of_module b ~with_link: false modu
else
self#html_of_info ~indent:false b modu.m_info;
(* parameters for functors *)
self#html_of_module_parameter_list b
(Name.father modu.m_name)
(Module.module_parameters modu);
(* a horizontal line *)
if not modu.m_text_only then bs b "<hr width=\"100%\">\n";
(* module elements *)
List.iter
(self#html_of_module_element b modu.m_name)
(Module.module_elements modu);
bs b "</body></html>\n";
Buffer.output_buffer chanout b;
close_out chanout;
(* generate html files for submodules *)
self#generate_elements self#generate_for_module (Module.module_modules modu);
(* generate html files for module types *)
self#generate_elements self#generate_for_module_type (Module.module_module_types modu);
(* generate html files for classes *)
self#generate_elements self#generate_for_class (Module.module_classes modu);
(* generate html files for class types *)
self#generate_elements self#generate_for_class_type (Module.module_class_types modu);
(* generate the file with the complete module type *)
self#output_module_type
modu.m_name
(Filename.concat !Global.target_dir type_file)
modu.m_type;
match modu.m_code with
None -> ()
| Some code ->
self#output_code ~with_pre:false
modu.m_name
(Filename.concat !Global.target_dir code_file)
code
with
Sys_error s ->
raise (Failure s)
(** Generate the [<index_prefix>.html] file corresponding to the given module list.
@raise Failure if an error occurs.*)
method generate_index module_list =
try
let chanout = open_out (Filename.concat !Global.target_dir self#index) in
let b = new_buf () in
bs b doctype ;
bs b "<html>\n";
self#print_header b self#title;
bs b "<body>\n";
(
match !Global.title with
| None -> ()
| Some t ->
bs b "<h1>";
bs b (self#escape t);
bs b "</h1>\n"
);
let info = Odoc_info.apply_opt
(Odoc_info.info_of_comment_file module_list)
!Odoc_info.Global.intro_file
in
(
match info with
None ->
bs b "<div class = \"index-list\">\n";
self#html_of_Index_list b;
bs b "</div>\n";
self#html_of_Module_list b
(List.map (fun m -> m.m_name) module_list);
| Some _ -> self#html_of_info ~indent: false b info
);
bs b "</body>\n</html>\n";
Buffer.output_buffer chanout b;
close_out chanout
with
Sys_error s ->
raise (Failure s)
(** Generate the values index in the file [index_values.html]. *)
method generate_values_index _module_list =
self#generate_elements_index
self#list_values
(fun v -> v.val_name)
(fun v -> v.val_info)
Naming.complete_value_target
Odoc_messages.index_of_values
self#index_values
(** Generate the extensions index in the file [index_extensions.html]. *)
method generate_extensions_index _module_list =
self#generate_elements_index
self#list_extensions
(fun x -> x.xt_name)
(fun x -> x.xt_type_extension.te_info)
(fun x -> Naming.complete_extension_target x)
Odoc_messages.index_of_extensions
self#index_extensions
(** Generate the exceptions index in the file [index_exceptions.html]. *)
method generate_exceptions_index _module_list =
self#generate_elements_index
self#list_exceptions
(fun e -> e.ex_name)
(fun e -> e.ex_info)
Naming.complete_exception_target
Odoc_messages.index_of_exceptions
self#index_exceptions
(** Generate the types index in the file [index_types.html]. *)
method generate_types_index _module_list =
self#generate_elements_index
self#list_types
(fun t -> t.ty_name)
(fun t -> t.ty_info)
Naming.complete_type_target
Odoc_messages.index_of_types
self#index_types
(** Generate the attributes index in the file [index_attributes.html]. *)
method generate_attributes_index _module_list =
self#generate_elements_index
self#list_attributes
(fun a -> a.att_value.val_name)
(fun a -> a.att_value.val_info)
Naming.complete_attribute_target
Odoc_messages.index_of_attributes
self#index_attributes
(** Generate the methods index in the file [index_methods.html]. *)
method generate_methods_index _module_list =
self#generate_elements_index
self#list_methods
(fun m -> m.met_value.val_name)
(fun m -> m.met_value.val_info)
Naming.complete_method_target
Odoc_messages.index_of_methods
self#index_methods
(** Generate the classes index in the file [index_classes.html]. *)
method generate_classes_index _module_list =
self#generate_elements_index
self#list_classes
(fun c -> c.cl_name)
(fun c -> c.cl_info)
(fun c -> fst (Naming.html_files c.cl_name))
Odoc_messages.index_of_classes
self#index_classes
(** Generate the class types index in the file [index_class_types.html]. *)
method generate_class_types_index _module_list =
self#generate_elements_index
self#list_class_types
(fun ct -> ct.clt_name)
(fun ct -> ct.clt_info)
(fun ct -> fst (Naming.html_files ct.clt_name))
Odoc_messages.index_of_class_types
self#index_class_types
(** Generate the modules index in the file [index_modules.html]. *)
method generate_modules_index _module_list =
self#generate_elements_index
~strip_libname:true
self#list_modules
(fun m -> m.m_name)
(fun m -> m.m_info)
(fun m -> fst (Naming.html_files m.m_name))
Odoc_messages.index_of_modules
self#index_modules
(** Generate the module types index in the file [index_module_types.html]. *)
method generate_module_types_index _module_list =
self#generate_elements_index
self#list_module_types
(fun mt -> mt.mt_name)
(fun mt -> mt.mt_info)
(fun mt -> fst (Naming.html_files mt.mt_name))
Odoc_messages.index_of_module_types
self#index_module_types
(** Generate all the html files from a module list. The main
file is [<index_prefix>.html]. *)
method generate module_list =
(* init the style *)
self#init_style ;
(* init the lists of elements *)
list_values <- Odoc_info.Search.values module_list ;
list_extensions <- Odoc_info.Search.extensions module_list ;
list_exceptions <- Odoc_info.Search.exceptions module_list ;
list_types <- Odoc_info.Search.types module_list ;
list_attributes <- Odoc_info.Search.attributes module_list ;
list_methods <- Odoc_info.Search.methods module_list ;
list_classes <- Odoc_info.Search.classes module_list ;
list_class_types <- Odoc_info.Search.class_types module_list ;
list_modules <- Odoc_info.Search.modules module_list ;
list_module_types <- Odoc_info.Search.module_types module_list ;
(* prepare the page header *)
self#prepare_header module_list ;
(* Get the names of all known types. *)
let types = Odoc_info.Search.types module_list in
known_types_names <-
List.fold_left
(fun acc t -> String.Set.add t.ty_name acc)
known_types_names
types ;
(* Get the names of all class and class types. *)
let classes = Odoc_info.Search.classes module_list in
let class_types = Odoc_info.Search.class_types module_list in
known_classes_names <-
List.fold_left
(fun acc c -> String.Set.add c.cl_name acc)
known_classes_names
classes ;
known_classes_names <-
List.fold_left
(fun acc ct -> String.Set.add ct.clt_name acc)
known_classes_names
class_types ;
(* Get the names of all known modules and module types. *)
let module_types = Odoc_info.Search.module_types module_list in
let modules = Odoc_info.Search.modules module_list in
known_modules_names <-
List.fold_left
(fun acc m -> String.Set.add m.m_name acc)
known_modules_names
modules ;
known_modules_names <-
List.fold_left
(fun acc mt -> String.Set.add mt.mt_name acc)
known_modules_names
module_types ;
(* generate html for each module *)
if not !index_only then
self#generate_elements self#generate_for_module module_list ;
try
self#generate_index module_list;
self#generate_values_index module_list ;
self#generate_extensions_index module_list ;
self#generate_exceptions_index module_list ;
self#generate_types_index module_list ;
self#generate_attributes_index module_list ;
self#generate_methods_index module_list ;
self#generate_classes_index module_list ;
self#generate_class_types_index module_list ;
self#generate_modules_index module_list ;
self#generate_module_types_index module_list ;
with
Failure s ->
prerr_endline s ;
incr Odoc_info.errors
initializer
Odoc_ocamlhtml.html_of_comment :=
(fun s ->
let b = new_buf () in
self#html_of_text b (Odoc_text.Texter.text_of_string s);
Buffer.contents b
)
end
end
module type Html_generator = module type of Generator
|