Skip to content

Commit

Permalink
Update Sample App Documentation page source and package links
Browse files Browse the repository at this point in the history
Source code button navigates to component folder on GitHub (main branch)
Most likely namespace is shown (hard-coded logic for now) - unoplatform/uno#8750
Shows and links to Uwp/WinUI packages on NuGet
  • Loading branch information
michael-hawker committed Aug 30, 2023
1 parent ce58fc8 commit 68cb0cf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
</StackPanel>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Click">
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('issues', Metadata.IssueId), Mode=OneWay}" />
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToComponentUri(Metadata.ComponentName), Mode=OneWay}" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
Expand All @@ -251,21 +251,23 @@
Text="Namespace" />
<TextBlock FontFamily="Consolas"
IsTextSelectionEnabled="True"
Text="CommunityToolkit.WinUI.Behaviors" />
Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageNamespace(Metadata.CsProjName), Mode=OneWay}" />
<TextBlock Margin="0,24,0,0"
Foreground="{StaticResource TextFillColorSecondaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="NuGet package" />
<TextBlock IsTextSelectionEnabled="True">
<Hyperlink FontFamily="Consolas"
NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageUri('Uwp', Metadata.CsProjName), Mode=OneWay}"
TextDecorations="None">
CommunityToolkit.Uwp.Behaviors
<Run Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageName('Uwp', Metadata.CsProjName), Mode=OneWay}" />
</Hyperlink>
</TextBlock>
<TextBlock IsTextSelectionEnabled="True">
<Hyperlink FontFamily="Consolas"
NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageUri('WinUI', Metadata.CsProjName), Mode=OneWay}"
TextDecorations="None">
CommunityToolkit.WinUI.Behaviors
<Run Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageName('WinUI', Metadata.CsProjName), Mode=OneWay}" />
</Hyperlink>
</TextBlock>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CommunityToolkit.Tooling.SampleGen.Metadata;
using Windows.Storage;
using Windows.System;
using static System.Net.WebRequestMethods;

#if !HAS_UNO
#if !WINAPPSDK
Expand Down Expand Up @@ -215,6 +216,24 @@ private async void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEvent

public static Uri? ToGitHubUri(string path, int id) => IsProjectPathValid() ? new Uri($"{ProjectUrl}/{path}/{id}") : null;

public static Uri? ToComponentUri(string name) => IsProjectPathValid() ? new Uri($"{ProjectUrl}/tree/main/components/{name}") : null;

public static Uri? ToPackageUri(string platform, string projectFileName) => new Uri($"https://www.nuget.org/packages/{RemoveFileExtension(projectFileName).Replace("WinUI", platform)}");

public static string ToPackageName(string platform, string projectFileName) => RemoveFileExtension(projectFileName).Replace("WinUI", platform);

// TODO: Think this is most of the special cases with Controls and the Extensions/Triggers using the base namespace
// See: https://github.com/CommunityToolkit/Tooling-Windows-Submodule/issues/105#issuecomment-1698306420
// And: https://github.com/unoplatform/uno/issues/8750 - otherwise we could use csproj data and inject with SG.
public static string ToPackageNamespace(string projectFileName) => RemoveFileExtension(projectFileName) switch
{
string c when c.Contains("Controls") => "CommunityToolkit.WinUI.Controls",
string e when e.Contains("Extensions") || e.Contains("Triggers") => "CommunityToolkit.WinUI",
_ => RemoveFileExtension(projectFileName)
};

private static string RemoveFileExtension(string filename) => filename.Replace(".csproj", "");

public static Visibility IsIdValid(int id) => id switch
{
<= 0 => Visibility.Collapsed,
Expand Down
2 changes: 2 additions & 0 deletions ProjectHeads/App.Head.props
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

<!-- Include markdown files from all samples so the head can access them in the source generator -->
<AdditionalFiles Include="$(RepositoryDirectory)components\**\samples\**\*.md" Exclude="$(RepositoryDirectory)**\**\samples\**\obj\**\*.md;$(RepositoryDirectory)**\**\samples\**\bin\**\*.md"/>
<AdditionalFiles Include="$(RepositoryDirectory)components\**\src\**\*.csproj" />
</ItemGroup>

<!-- See https://github.com/CommunityToolkit/Labs-Windows/issues/142 -->
Expand All @@ -109,6 +110,7 @@

<!-- Include markdown files from all samples so the head can access them in the source generator -->
<AdditionalFiles Include="$(MSBuildProjectDirectory)\..\..\samples\*.md" Exclude="$(MSBuildProjectDirectory)\..\..\**\obj\**\*.md;$(MSBuildProjectDirectory)\..\..\**\bin\**\*.md"/>
<AdditionalFiles Include="$(MSBuildProjectDirectory)\..\..\src\**\*.csproj" />
</ItemGroup>

<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions ToolkitComponent.SampleProject.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@

<!-- Enable reading Markdown files from source generator -->
<AdditionalFiles Include="**\*.md" Exclude="bin\**\*.md;obj\**\*.md" />
<AdditionalFiles Include="$(MSBuildProjectDirectory)\..\src\*.csproj" />
</ItemGroup>
</Project>

0 comments on commit 68cb0cf

Please sign in to comment.