Skip to content

Commit

Permalink
Make Label() a mutable attribute, get rid of additional_label
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jan 12, 2024
1 parent 2081cc5 commit 9ec210f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gap/DocumentationTree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DeclareCategory( "IsTreeForDocumentationNode", IsObject );

DeclareOperation( "IsEmptyNode", [ IsTreeForDocumentationNode ] );
DeclareOperation( "IsEmptyNode", [ IsString ] );
DeclareAttribute( "Label", IsTreeForDocumentationNode );
DeclareAttribute( "Label", IsTreeForDocumentationNode, "mutable" );
DeclareAttribute( "ChapterInfo", IsTreeForDocumentationNode );
DeclareAttribute( "GroupName", IsTreeForDocumentationNode );

Expand Down
31 changes: 7 additions & 24 deletions gap/DocumentationTree.gi
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,14 @@ end );
##
InstallMethod( WriteDocumentation, [ IsTreeForDocumentationNodeForChapterRep, IsStream, IsDirectory, IsInt ],
function( node, stream, path_to_xmlfiles, level_value )
local filename, chapter_stream, label, replaced_name, additional_label;
local filename, chapter_stream, replaced_name;

if node!.level > level_value then
return;
fi;
if ForAll( node!.content, IsEmptyNode ) then
return;
fi;
label := Label( node );
if IsBound( node!.additional_label ) then
additional_label := node!.additional_label;
else
additional_label := label;
fi;

if IsBound( node!.title_string ) then
replaced_name := NormalizedWhitespace( node!.title_string );
Expand All @@ -463,13 +457,12 @@ InstallMethod( WriteDocumentation, [ IsTreeForDocumentationNodeForChapterRep, Is

# Remove any characters outside of A-Za-z0-9 and -, +, _ from the filename.
# See issues #77 and #78
filename := Filtered( additional_label, x -> x in AUTODOC_IdentifierLetters);
filename := Filtered( Label( node ), x -> x in AUTODOC_IdentifierLetters);
filename := Concatenation( "_", filename, ".xml" );

chapter_stream := AUTODOC_OutputTextFile( path_to_xmlfiles, filename );
AppendTo( stream, "<#Include SYSTEM \"", filename, "\">\n" );
AppendTo( chapter_stream, AUTODOC_XML_HEADER );
AppendTo( chapter_stream, "<Chapter Label=\"", additional_label ,"\">\n" );
AppendTo( chapter_stream, "<Chapter Label=\"", Label( node ) ,"\">\n" );
AppendTo( chapter_stream, Concatenation( [ "<Heading>", replaced_name, "</Heading>\n\n" ] ) );
WriteDocumentation( node!.content, chapter_stream, level_value );
AppendTo( chapter_stream, "</Chapter>\n\n" );
Expand Down Expand Up @@ -518,27 +511,22 @@ end );
##
InstallMethod( WriteDocumentation, [ IsTreeForDocumentationNodeForSectionRep, IsStream, IsInt ],
function( node, filestream, level_value )
local replaced_name, label, additional_label;
local replaced_name;

if node!.level > level_value then
return;
fi;
if ForAll( node!.content, IsEmptyNode ) then
return;
fi;
if IsBound( node!.additional_label ) then
label := node!.additional_label;
else
label := Label( node );;
fi;

if IsBound( node!.title_string ) then
replaced_name := NormalizedWhitespace( node!.title_string );
else
replaced_name := ReplacedString( node!.name, "_", " " );
fi;

AppendTo( filestream, "<Section Label=\"", label, "\">\n" );
AppendTo( filestream, "<Section Label=\"", Label( node ), "\">\n" );
AppendTo( filestream, Concatenation( [ "<Heading>", replaced_name, "</Heading>\n\n" ] ) );
WriteDocumentation( node!.content, filestream, level_value );
AppendTo( filestream, "</Section>\n\n" );
Expand All @@ -547,27 +535,22 @@ end );
##
InstallMethod( WriteDocumentation, [ IsTreeForDocumentationNodeForSubsectionRep, IsStream, IsInt ],
function( node, filestream, level_value )
local replaced_name, label, additional_label;
local replaced_name;

if node!.level > level_value then
return;
fi;
if ForAll( node!.content, IsEmptyNode ) then
return;
fi;
if IsBound( node!.additional_label ) then
label := node!.additional_label;
else
label := Label( node );
fi;

if IsBound( node!.title_string ) then
replaced_name := NormalizedWhitespace( node!.title_string );
else
replaced_name := ReplacedString( node!.name, "_", " " );
fi;

AppendTo( filestream, "<Subsection Label=\"", label, "\">\n" );
AppendTo( filestream, "<Subsection Label=\"", Label( node ), "\">\n" );
AppendTo( filestream, Concatenation( [ "<Heading>", replaced_name, "</Heading>\n\n" ] ) );
WriteDocumentation( node!.content, filestream, level_value );
AppendTo( filestream, "</Subsection>\n\n" );
Expand Down
6 changes: 3 additions & 3 deletions gap/Parser.gi
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
fi;
label_name := ReplacedString( current_command[ 2 ], " ", "_" );
scope_chapter := ChapterInTree( tree, chapter_info[ 1 ] );
scope_chapter!.additional_label := Concatenation( "Chapter_", label_name );
SetLabel( scope_chapter, Concatenation( "Chapter_", label_name ) );

Check warning on line 546 in gap/Parser.gi

View check run for this annotation

Codecov / codecov/patch

gap/Parser.gi#L546

Added line #L546 was not covered by tests
end,
@ChapterTitle := function()
local scope_chapter;
Expand Down Expand Up @@ -571,7 +571,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
fi;
label_name := ReplacedString( current_command[ 2 ], " ", "_" );
scope_section := SectionInTree( tree, chapter_info[ 1 ], chapter_info[ 2 ] );
scope_section!.additional_label := Concatenation( "Section_", label_name );
SetLabel( scope_section, Concatenation( "Section_", label_name ) );

Check warning on line 574 in gap/Parser.gi

View check run for this annotation

Codecov / codecov/patch

gap/Parser.gi#L574

Added line #L574 was not covered by tests
end,
@SectionTitle := function()
local scope_section;
Expand Down Expand Up @@ -606,7 +606,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
fi;
label_name := ReplacedString( current_command[ 2 ], " ", "_" );
scope_subsection := SubsectionInTree( tree, chapter_info[ 1 ], chapter_info[ 2 ], chapter_info[ 3 ] );
scope_subsection!.additional_label := Concatenation( "Subsection_", label_name );
SetLabel( scope_subsection, Concatenation( "Subsection_", label_name ) );

Check warning on line 609 in gap/Parser.gi

View check run for this annotation

Codecov / codecov/patch

gap/Parser.gi#L609

Added line #L609 was not covered by tests
end,
@SubsectionTitle := function()
local scope_subsection;
Expand Down

0 comments on commit 9ec210f

Please sign in to comment.