Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
/doc/*.tex
/doc/*.toc
/doc/*.txt
/doc/*Bib.xml
/doc/*.xml.bib
/doc/AutoDoc.xml
/doc/_AutoDocMainFile.xml
/doc/_Chapter*xml
/doc/_*.xml
/doc/maketest.g
/doc/manual.lab
/doc/manual.six
Expand Down
41 changes: 34 additions & 7 deletions gap/DocumentationTree.gi
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ InstallMethod( DocumentationTree, [ ],
nodes_by_label := rec( ),
node_name_iterator := 0,
current_level := 0,
TitlePage := rec( )
TitlePage := rec( ),
chunks := rec( ),
);
ObjectifyWithAttributes( tree, TheTypeOfDocumentationTrees );
return tree;
Expand Down Expand Up @@ -246,15 +247,14 @@ InstallMethod( DocumentationDummy, [ IsTreeForDocumentation, IsString ],
function( tree, name )
local node;

name := Concatenation( "System_", name );
if IsBound( tree!.nodes_by_label.( name ) ) then
return tree!.nodes_by_label.( name );
if IsBound( tree!.chunks.( name ) ) then
return tree!.chunks.( name );
Comment thread
fingolfin marked this conversation as resolved.
fi;
node := rec( content := [ ],
level := tree!.current_level );
ObjectifyWithAttributes( node, TheTypeOfDocumentationTreeDummyNodes,
Label, name );
tree!.nodes_by_label.( name ) := node;
tree!.chunks.( name ) := node;
return node;
end );

Expand Down Expand Up @@ -449,6 +449,29 @@ end );
##
#############################################

BindGlobal( "WriteChunks",
function( tree, path_to_xmlfiles )
local chunks_stream, filename, chunk_names, current_chunk_name,
current_chunk;

filename := "_Chunks.xml";

chunks_stream := AUTODOC_OutputTextFile( path_to_xmlfiles, filename );
chunk_names := RecNames( tree!.chunks );

for current_chunk_name in chunk_names do
current_chunk := tree!.chunks.( current_chunk_name );
AppendTo( chunks_stream, "<#GAPDoc Label=\"", current_chunk_name, "\">\n" );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ensure that current_chunk_name cannot contain e.g. quotes "? As that would break stuff. Of course that's the user shooting themselves into their foot, but of course it'd be great if we caught that.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't. I will add this. I am not super sure which characters are allowed, so I would probably restrict it to alphanumeric, possibly also allowing _.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also spaces? Not sure if anybody uses those, but it should be no problem to allow them either.

if IsBound( current_chunk!.content ) then
WriteDocumentation( current_chunk!.content, chunks_stream );
fi;
AppendTo( chunks_stream, "\n<#/GAPDoc>\n" );
od;

CloseStream( chunks_stream );

end );

##
InstallMethod( WriteDocumentation, [ IsTreeForDocumentation, IsDirectory ],
function( tree, path_to_xmlfiles )
Expand All @@ -463,6 +486,9 @@ InstallMethod( WriteDocumentation, [ IsTreeForDocumentation, IsDirectory ],
## FIXME: If there is anything else than a chapter, this will break!
WriteDocumentation( i, stream, path_to_xmlfiles );
od;

WriteChunks( tree, path_to_xmlfiles );

# Workaround for issue #65
if IsEmpty( tree!.content ) then
AppendTo( stream, "&nbsp;\n" );
Expand Down Expand Up @@ -632,9 +658,10 @@ end );
##
InstallMethod( WriteDocumentation, [ IsTreeForDocumentationDummyNodeRep, IsStream ],
function( node, filestream )
if IsBound( node!.content ) then
WriteDocumentation( node!.content, filestream );
if node!.level > ValueOption( "level_value" ) then
return;
Comment thread
fingolfin marked this conversation as resolved.
fi;
WriteDocumentation( Concatenation( "<#Include Label=\"", Label( node ), "\">" ), filestream );
end );

##
Expand Down
2 changes: 2 additions & 0 deletions gap/Magic.gi
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,15 @@ function( arg )
tmp := Number( Filename( doc_dir_rel, "" ), x -> x = '/' );
tmp := Concatenation( ListWithIdenticalEntries(tmp, "../") );
gapdoc.files := List( gapdoc.files, f -> Concatenation( tmp, f ) );
Add( gapdoc.files, "_Chunks.xml" );
else
# Here presumably the doc_dir was given by an absolute path that
# does not lie below the package dir. In that case, we can't make
# the gapdoc.files relative to the doc dir, but rather we have no
# choice but to make them absolute, which MakeGAPDocDoc can handle,
# even if perhaps less gracefully/portably.
gapdoc.files := List( gapdoc.files, f -> Filename( pkgdir, f ) );
Add( gapdoc.files, Filename( doc_dir, "_Chunks.xml" ) );
fi;
fi;

Expand Down
10 changes: 10 additions & 0 deletions tst/worksheets/general.expected/_Chapter_SomeChapter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,15 @@ Third sentence.
</Section>


<Section Label="Chapter_SomeChapter_Section_Testing_chunks">
<Heading>Testing chunks</Heading>

This test comes after the chunk is declared, but before it is inserted.
<#Include Label="MyChunk">

The text "Hello, world." is inserted right before this.
</Section>


</Chapter>

4 changes: 4 additions & 0 deletions tst/worksheets/general.expected/_Chunks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<#GAPDoc Label="MyChunk">
Hello, world.

<#/GAPDoc>
13 changes: 13 additions & 0 deletions tst/worksheets/general.sheet/worksheet.g
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,16 @@ DeclareOperation( "SecondOperation", [ IsInt, IsGroup ] );
#! Third sentence.
#! @Group Group1
KeyDependentOperation( "ThirdOperation", IsGroup, IsInt, "prime );

#############################################################################
#! @Section Testing chunks

#! @BeginChunk MyChunk
#! Hello, world.
#! @EndChunk

#! This test comes after the chunk is declared, but before it is inserted.

#! @InsertChunk MyChunk

#! The text "Hello, world." is inserted right before this.