1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999-2000, Ericsson
14
%% Utvecklings AB. All Rights Reserved.''
18
-module(docb_tr_part2html).
20
-export([extension/0, transform/3, rule/2, rule/3]).
25
transform(File, {part, _Attrs, [Header| Rest]}, Opts0) ->
27
%% Extract header data
28
Title = docb_html_util:extract_header_data(title, Header),
30
%% Create the framing HTML document
31
OutFile = docb_util:outfile(File ++ "_frame", ".html", Opts0),
32
case file:open(OutFile, [write]) of
35
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
36
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">
37
<!-- This document was generated using DocBuilder-" ++ docb_util:version() ++ " -->
38
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
41
" ++ docb_util:html_snippet(head, Opts0) ++ "
43
<frameset cols=\"200, *\">
44
<frame src=\"~s\" name=\"toc\"/>
45
<frame src=\"~s\" name=\"document\"/>
47
<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\"
48
vlink=\"#FF00FF\" alink=\"#FF0000\">
49
<p>This documentation requires a browser that can handle frames</p>
55
[Title, File ++ ".html", File ++ "_first.html"]),
59
%% Create the front HTML document
60
docb_main:transform(first, html, Opts0, File ++ "_first",
61
{first, [], [Header| Rest]}),
63
%% Extract files to include
66
[{description, _, _}| NewRest] ->
67
lists:map(fun({include, [{_, _, F}], _}) -> filename:rootname(F) end,
69
[{include, _, _}| _NewRest] ->
70
lists:map(fun({include, [{_, _, F}], _}) -> filename:rootname(F) end, Rest)
73
%% Concat all chapters into a *big* parse tree
74
%% Also transform them to HTML
75
TransformP = not docb_util:an_option(framework_only, Opts0),
76
TOpts = [dict, {part_application,File}],
77
ConcatTree = concat_files(Files, Opts0, TransformP, TOpts),
79
%% Create a cites dictionary
80
docb_main:transform(cite, html, Opts0, File ++ "_cite",
81
{cite, [], [Header| ConcatTree]}),
83
%% Create a terms dictionary
84
docb_main:transform(term, html, Opts0, File ++ "_term",
85
{term, [], [Header| ConcatTree]}),
87
%% Find all fascicules to be put in the top menu of the table of
89
Ext = docb_util:lookup_option(src_type, Opts0),
91
case filelib:is_regular("fascicules"++Ext) of
93
case docb_main:parse1("fascicules", Opts0) of
95
FascData = get_fasc_data(Parse),
96
case lists:keyfind(File, 1, FascData) of
99
docb_util:outfile(File++"_frame",
102
docb_util:outfile("index",
104
docb_util:message(info,
106
[OrigFile,EntryFile]),
107
file:copy(OrigFile, EntryFile);
111
[{fascdata, FascData}| Opts0];
116
"fascicules~s could not be parsed,"
117
" no index.html created~n", [Ext]),
122
docb_util:message(warning,
123
"fascicules~s not found, "
124
"no index.html created~n",
129
%% Create ToC parse tree
130
{{toc, [{"FILE", "CDATA", File}], [Header| ConcatTree]}, Opts2}.
132
concat_files(Files, Opts, TransformP, TOpts) ->
133
Ext = docb_util:lookup_option(src_type, Opts),
134
concat_files(Files, [], 1, Opts, TransformP, TOpts, Ext).
136
concat_files([File | Rest], Body, ChLevel, Opts, TP, TOpts, Ext) ->
137
case docb_main:parse1(File, Opts) of
139
{TopTag, Attrs, [Header = {header, _, HeaderContents} | More]} = Parse,
140
{title,_,Title} = lists:keyfind(title,1,HeaderContents),
141
NewMore = [{section, [], [{title, [], Title}| More]}],
142
NewParse = {TopTag, Attrs, [Header| NewMore]},
145
docb_util:message(info,
146
"Processing \"~s~s\"",
149
[html, {number,integer_to_list(ChLevel)}] ++
151
docb_main:transform(TopTag, html, Opts2, File,
156
docb_html_util:number(NewParse,
157
integer_to_list(ChLevel), File),
158
{_, [], [_| NewBody]} = NumberTree,
159
Body ++ concat_files(Rest, NewBody, ChLevel+1, Opts,
162
throw({error,"Parse error when building chapter "++File})
164
concat_files([], Body, _ChLevel, _Opts, _TP, _TOpts, _Ext) ->
167
rule([section| _], _) ->
173
rule([toc| _], {_Depth, [File], [Header| _]}, Opts) ->
174
case docb_util:lookup_option(fascdata, Opts) of
176
{{docb_html_layout:part_toc_top(
177
docb_html_util:all_header_data(Header), File, Opts),
178
docb_html_layout:part_toc_bot()}, Opts};
182
fun({_File, HRef, _Entry, PCText}) ->
183
{HRef, docb_html_util:pcdata_to_html(PCText)}
186
{{docb_html_layout:part_toc_top(
187
docb_html_util:all_header_data(Header),
188
File, Opts, HRefTexts),
189
docb_html_layout:part_toc_bot()}, Opts}
192
rule([title| Rest], {_, [Number, File], [{pcdata, _, Title}]}, Opts) ->
193
N = docb_html_util:count_sections(Rest),
194
OutFile = docb_html_util:make_anchor_href(File),
200
" <a target=\"document\" href=\"" ++ OutFile ++ "#" ++
202
docb_html_util:pcdata_to_html(Title) ++
203
"</a></small><br/>\n"},
209
" <a target=\"document\" href=\"" ++ OutFile ++ "#" ++
211
docb_html_util:pcdata_to_html(Title) ++
212
"</a></small><br/>\n"},
218
%% Parsed fascicules:
220
%% [{fascicule, [{"FILE","CDATA","refman"},
221
%% {"HREF","CDATA","refman_frame.html"},
222
%% {"ENTRY","TOKEN","YES"}],
223
%% [{pcdata, [], "" Reference Manual\\n \n"}]},
224
%% Returns: [{File, HRef, Entry, Text}].
225
get_fasc_data({fascicules, _, Fascs}) ->
227
fun({fascicule, Atts, Trees}) ->
228
AVals = get_avals(Atts),
229
PCText = get_pc_text(Trees),
230
list_to_tuple(lists:append([AVals, [PCText]])) end,
234
[element(3, Tuple) || Tuple <- Atts].
236
get_pc_text([{pcdata, _, Text}]) ->