Skip to content

Commit

Permalink
Add multi-line support for install instruction commands
Browse files Browse the repository at this point in the history
  • Loading branch information
augustoproiete committed Mar 21, 2021
1 parent 1819c08 commit bbee7cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/NuGetGallery/ViewModels/PackageManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public PackageManagerViewModel(string name)
public string CommandPrefix { get; set; }

/// <summary>
/// A string that represents the command used to install a specific package.
/// One or more strings that represent the command(s) used to install a specific package.
/// </summary>
public string InstallPackageCommand { get; set; }
public string[] InstallPackageCommands { get; set; }

/// <summary>
/// The alert message that contains clarifications about the command/scenario
Expand Down
40 changes: 23 additions & 17 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{
Id = "dotnet-cli-global",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("dotnet tool install --global {0} --version {1}", Model.Id, Model.Version),
InstallPackageCommands = new [] { string.Format("dotnet tool install --global {0} --version {1}", Model.Id, Model.Version) },
AlertLevel = AlertLevel.Info,
AlertMessage = "This package contains a <a href='https://aka.ms/global-tools'>.NET tool</a> you can call from the shell/command line.",
},
Expand All @@ -41,19 +41,19 @@
{
Id = "dotnet-cli-local",
CommandPrefix = "> ",
InstallPackageCommand = string.Join
(Environment.NewLine,
"dotnet new tool-manifest # if you are setting up this repo",
string.Format(" dotnet tool install --local {0} --version {1}", Model.Id, Model.Version)
),
InstallPackageCommands = new []
{
"dotnet new tool-manifest # if you are setting up this repo",
string.Format("dotnet tool install --local {0} --version {1}", Model.Id, Model.Version),
},
AlertLevel = AlertLevel.Info,
AlertMessage = "This package contains a <a href='https://aka.ms/global-tools'>.NET tool</a> you can call from the shell/command line.",
},

new ThirdPartyPackageManagerViewModel("Cake", "https://cakebuild.net/support/nuget")
{
Id = "cake-dotnet-tool",
InstallPackageCommand = Model.GetCakeInstallPackageCommand(),
InstallPackageCommands = new [] { Model.GetCakeInstallPackageCommand() },
},
};
}
Expand All @@ -65,7 +65,7 @@
{
Id = "dotnet-cli",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("dotnet new --install {0}::{1}", Model.Id, Model.Version),
InstallPackageCommands = new [] { string.Format("dotnet new --install {0}::{1}", Model.Id, Model.Version) },
AlertLevel = AlertLevel.Info,
AlertMessage = "This package contains a <a href='https://aka.ms/dotnet-new'>.NET Core Template Package</a> you can call from the shell/command line.",
}
Expand All @@ -79,26 +79,26 @@
{
Id = "package-manager",
CommandPrefix = "PM> ",
InstallPackageCommand = string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version)
InstallPackageCommands = new [] { string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version) },
},

new PackageManagerViewModel(".NET CLI")
{
Id = "dotnet-cli",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("dotnet add package {0} --version {1}", Model.Id, Model.Version)
InstallPackageCommands = new [] { string.Format("dotnet add package {0} --version {1}", Model.Id, Model.Version) },
},

new PackageManagerViewModel("PackageReference")
{
Id = "package-reference",
InstallPackageCommand = Model.DevelopmentDependency
InstallPackageCommands = new [] { Model.DevelopmentDependency
? string.Format(string.Join(Environment.NewLine,
"<PackageReference Include=\"{0}\" Version=\"{1}\">",
" <PrivateAssets>all</PrivateAssets>",
" <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>",
"</PackageReference>"), Model.Id, Model.Version)
: string.Format("<PackageReference Include=\"{0}\" Version=\"{1}\" />", Model.Id, Model.Version),
: string.Format("<PackageReference Include=\"{0}\" Version=\"{1}\" />", Model.Id, Model.Version) },
AlertLevel = AlertLevel.Info,
AlertMessage = string.Format("For projects that support <a href=\"{0}\">PackageReference</a>, copy this XML node into the project file to reference the package.",
"https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files"),
Expand All @@ -109,14 +109,14 @@
{
Id = "paket-cli",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("paket add {0} --version {1}", Model.Id, Model.Version),
InstallPackageCommands = new [] { string.Format("paket add {0} --version {1}", Model.Id, Model.Version) },
},

new PackageManagerViewModel("F# Interactive")
{
Id = "fsharp-interactive",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("#r \"nuget: {0}, {1}\"", Model.Id, Model.Version),
InstallPackageCommands = new [] { string.Format("#r \"nuget: {0}, {1}\"", Model.Id, Model.Version) },
AlertLevel = AlertLevel.Info,
AlertMessage = string.Format(
"For F# scripts that support <a href=\"{0}\">#r syntax</a>, copy this into the source code to reference the package.",
Expand All @@ -126,7 +126,7 @@
new ThirdPartyPackageManagerViewModel("Cake", "https://cakebuild.net/support/nuget")
{
Id = Model.IsCakeExtension() ? "cake-extension" : "cake",
InstallPackageCommand = Model.GetCakeInstallPackageCommand()
InstallPackageCommands = new [] { Model.GetCakeInstallPackageCommand() },
},
};
}
Expand Down Expand Up @@ -179,10 +179,16 @@
{
var thirdPartyPackageManager = packageManager as ThirdPartyPackageManagerViewModel;

var encodedInstallPackageCommands = packageManager.InstallPackageCommands.Select(c => Html.Encode(c));

var htmlInstallPackageCommandSeparator = string.Format("{0}</span><span class=\"install-command-row\">", Environment.NewLine);
var htmlInstallPackageCommands = "<span class=\"install-command-row\">" +
string.Join(htmlInstallPackageCommandSeparator, encodedInstallPackageCommands) + "</span>";

<div role="tabpanel" class="tab-pane @(active ? "active" : string.Empty)" id="@packageManager.Id">
<div>
<div class="install-script-row">
<pre class="install-script" id="@packageManager.Id-text">@packageManager.InstallPackageCommand</pre>
<pre class="install-script" id="@packageManager.Id-text">@Html.Raw(htmlInstallPackageCommands)</pre>
<div class="copy-button">
<!--In order to statisfy the requirement to announce button status both on NVDA/Narrator, other screen reader like NVDA will
announce the data-content "Copied" everytime when we press button, however, it won't work with Narrator when we use bootstrap popover
Expand Down Expand Up @@ -1197,7 +1203,7 @@
continue;
}

packageManagersCss += "#" + packageManager.Id + " .install-script::before {";
packageManagersCss += "#" + packageManager.Id + " .install-command-row::before {";
packageManagersCss += " content: \"" + packageManager.CommandPrefix + "\"";
packageManagersCss += "}";
}
Expand Down

0 comments on commit bbee7cf

Please sign in to comment.