Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Source Folder external URL #73

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
26 changes: 25 additions & 1 deletion Engine/Source/Config/ConfigFiles/TextFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ public bool Load (Path path, out ProjectConfig projectConfig, ErrorList errorLis
}


else if (lcIdentifier == "url")
{
if (inputTarget is Targets.SourceFolder &&
(inputTarget as Targets.SourceFolder).Type == Files.InputType.Source)
{
(inputTarget as Targets.SourceFolder).Url = value;
(inputTarget as Targets.SourceFolder).UrlPropertyLocation = propertyLocation;
}
else
{
errorList.Add( Locale.Get("NaturalDocs.Engine", "Project.txt.UrlOnlyAppliesToSourceFolders"),
propertyLocation.FileName, propertyLocation.LineNumber );
}

return true;
}

// Encoding

else if (encodingRegex.IsMatch(lcIdentifier))
Expand Down Expand Up @@ -942,6 +959,10 @@ protected void AppendSourceFolder (Targets.SourceFolder target, StringBuilder ou
bool hasName = (target.NamePropertyLocation.IsDefined &&
target.NamePropertyLocation.Source != PropertySource.SystemDefault);


bool hasUrl = (target.UrlPropertyLocation.IsDefined &&
target.UrlPropertyLocation.Source != PropertySource.SystemDefault);

int encodingRules = 0;
if (projectConfig.InputSettings.HasCharacterEncodingRules)
{
Expand Down Expand Up @@ -970,7 +991,10 @@ protected void AppendSourceFolder (Targets.SourceFolder target, StringBuilder ou
if (hasName)
{ output.AppendLine(" Name: " + target.Name); }

if (hasName && encodingRules > 1)
if (hasUrl)
{ output.AppendLine(" Url: " + target.Url); }

if ((hasName||hasUrl) && encodingRules > 1)
{ output.AppendLine(); }

AppendOverriddenInputSettings(target, output);
Expand Down
26 changes: 26 additions & 0 deletions Engine/Source/Config/Targets/SourceFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ public SourceFolder (PropertyLocation propertyLocation) : base (Files.InputType.
{
folder = null;
name = null;
url = null;

folderPropertyLocation = PropertySource.NotDefined;
namePropertyLocation = PropertySource.NotDefined;
urlPropertyLocation = PropertySource.NotDefined;
}

public SourceFolder (SourceFolder toCopy) : base (toCopy)
{
folder = toCopy.folder;
name = toCopy.name;
url = toCopy.url;

folderPropertyLocation = toCopy.folderPropertyLocation;
namePropertyLocation = toCopy.namePropertyLocation;
urlPropertyLocation = toCopy.urlPropertyLocation;
}

override public Input Duplicate ()
Expand Down Expand Up @@ -149,6 +153,16 @@ public string Name
{ name = value; }
}

/* Property: Url
*
*/
public string Url
{
get
{ return url; }
set
{ url = value; }
}


// Group: Property Locations
Expand Down Expand Up @@ -178,6 +192,16 @@ public PropertyLocation NamePropertyLocation
{ namePropertyLocation = value; }
}

/* Property: UrlPropertyLocation
* Where <Url> is defined, or <PropertySource.NotDefined> if it isn't.
*/
public PropertyLocation UrlPropertyLocation
{
get
{ return urlPropertyLocation; }
set
{ urlPropertyLocation = value; }
}


// Group: Variables
Expand All @@ -186,9 +210,11 @@ public PropertyLocation NamePropertyLocation

protected AbsolutePath folder;
protected string name;
protected string url;

protected PropertyLocation folderPropertyLocation;
protected PropertyLocation namePropertyLocation;
protected PropertyLocation urlPropertyLocation;

}
}
9 changes: 9 additions & 0 deletions Engine/Source/Files/FileSources/SourceFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ override public string Name
}


/* Property: Url
* The url of the FileSource's folder.
*/
public string Url
{
get
{ return config.Url; }
}


// Group: Variables
// __________________________________________________________________________
Expand Down
11 changes: 11 additions & 0 deletions Engine/Source/Output/HTML/Components/Topic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using CodeClear.NaturalDocs.Engine.Links;
using CodeClear.NaturalDocs.Engine.Prototypes;
using CodeClear.NaturalDocs.Engine.Tokenization;
using CodeClear.NaturalDocs.Engine.Files;


namespace CodeClear.NaturalDocs.Engine.Output.HTML.Components
Expand Down Expand Up @@ -188,8 +189,18 @@ protected void AppendTitle (StringBuilder output)
else
{ mode = WrappedTitleMode.None; }

File file = EngineInstance.Files.FromID(context.Topic.FileID);
var fileSource = EngineInstance.Files.FileSourceOf(file);
string fileUrl = (fileSource as Files.FileSources.SourceFolder).Url;
string filePath = fileSource.MakeRelative(file.FileName);
int lineNum = context.Topic.CommentLineNumber;

output.Append("<div class=\"CTitle\">");
AppendWrappedTitle(context.Topic.Title, mode, output);
if (fileUrl != null && lineNum != 0) {
string url = fileUrl.Replace("{filePath}", filePath).Replace("{lineNum}", lineNum.ToString());
output.Append("<a class=\"ExternalFileUrl\" target=\"_blank\" href=\""+url+"\">🡕</a>");
}
output.Append("</div>");
}

Expand Down