Add XML docs to core packages

This commit is contained in:
SteveSandersonMS
2016-11-29 16:03:15 +00:00
parent 3b91ad9b39
commit 3ff4447924
24 changed files with 448 additions and 10 deletions

View File

@@ -1,14 +1,36 @@
using System;
namespace Microsoft.AspNetCore.SpaServices.Prerendering
{
/// <summary>
/// Describes how to find the JavaScript code that performs prerendering.
/// </summary>
public class JavaScriptModuleExport
{
/// <summary>
/// Creates a new instance of <see cref="JavaScriptModuleExport"/>.
/// </summary>
/// <param name="moduleName">The path to the JavaScript module containing prerendering code.</param>
public JavaScriptModuleExport(string moduleName)
{
ModuleName = moduleName;
}
/// <summary>
/// Specifies the path to the JavaScript module containing prerendering code.
/// </summary>
public string ModuleName { get; private set; }
/// <summary>
/// If set, specifies the name of the CommonJS export that is the prerendering function to execute.
/// If not set, the JavaScript module's default CommonJS export must itself be the prerendering function.
/// </summary>
public string ExportName { get; set; }
/// <summary>
/// Obsolete. Do not use. Instead, configure Webpack to build a Node.js-compatible bundle and reference that directly.
/// </summary>
[Obsolete("Do not use. This feature will be removed. Instead, configure Webpack to build a Node.js-compatible bundle and reference that directly.")]
public string WebpackConfig { get; set; }
}
}

View File

@@ -11,6 +11,9 @@ using Newtonsoft.Json;
namespace Microsoft.AspNetCore.SpaServices.Prerendering
{
/// <summary>
/// A tag helper for prerendering JavaScript applications on the server.
/// </summary>
[HtmlTargetElement(Attributes = PrerenderModuleAttributeName)]
public class PrerenderTagHelper : TagHelper
{
@@ -24,6 +27,10 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
private readonly string _applicationBasePath;
private readonly INodeServices _nodeServices;
/// <summary>
/// Creates a new instance of <see cref="PrerenderTagHelper"/>.
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
public PrerenderTagHelper(IServiceProvider serviceProvider)
{
var hostEnv = (IHostingEnvironment) serviceProvider.GetService(typeof(IHostingEnvironment));
@@ -39,25 +46,51 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
}
}
/// <summary>
/// Specifies the path to the JavaScript module containing prerendering code.
/// </summary>
[HtmlAttributeName(PrerenderModuleAttributeName)]
public string ModuleName { get; set; }
/// <summary>
/// If set, specifies the name of the CommonJS export that is the prerendering function to execute.
/// If not set, the JavaScript module's default CommonJS export must itself be the prerendering function.
/// </summary>
[HtmlAttributeName(PrerenderExportAttributeName)]
public string ExportName { get; set; }
/// <summary>
/// Obsolete. Do not use. Instead, configure Webpack to build a Node.js-compatible bundle and reference that directly.
/// </summary>
[Obsolete("Do not use. This feature will be removed. Instead, configure Webpack to build a Node.js-compatible bundle and reference that directly.")]
[HtmlAttributeName(PrerenderWebpackConfigAttributeName)]
public string WebpackConfigPath { get; set; }
/// <summary>
/// An optional JSON-serializable parameter to be supplied to the prerendering code.
/// </summary>
[HtmlAttributeName(PrerenderDataAttributeName)]
public object CustomDataParameter { get; set; }
/// <summary>
/// The maximum duration to wait for prerendering to complete.
/// </summary>
[HtmlAttributeName(PrerenderTimeoutAttributeName)]
public int TimeoutMillisecondsParameter { get; set; }
/// <summary>
/// The <see cref="ViewContext"/>.
/// </summary>
[HtmlAttributeNotBound]
[ViewContext]
public ViewContext ViewContext { get; set; }
/// <summary>
/// Executes the tag helper to perform server-side prerendering.
/// </summary>
/// <param name="context">The <see cref="TagHelperContext"/>.</param>
/// <param name="output">The <see cref="TagHelperOutput"/>.</param>
/// <returns>A <see cref="Task"/> representing the operation.</returns>
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
// We want to pass the original, unencoded incoming URL data through to Node, so that
@@ -79,7 +112,9 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
new JavaScriptModuleExport(ModuleName)
{
ExportName = ExportName,
#pragma warning disable CS0618 // Type or member is obsolete
WebpackConfig = WebpackConfigPath
#pragma warning restore CS0618 // Type or member is obsolete
},
unencodedAbsoluteUrl,
unencodedPathAndQuery,

View File

@@ -4,6 +4,9 @@ using Microsoft.AspNetCore.NodeServices;
namespace Microsoft.AspNetCore.SpaServices.Prerendering
{
/// <summary>
/// Performs server-side prerendering by invoking code in Node.js.
/// </summary>
public static class Prerenderer
{
private static readonly Lazy<StringAsTempFile> NodeScript;
@@ -17,6 +20,17 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
});
}
/// <summary>
/// Performs server-side prerendering by invoking code in Node.js.
/// </summary>
/// <param name="applicationBasePath">The root path to your application. This is used when resolving project-relative paths.</param>
/// <param name="nodeServices">The instance of <see cref="INodeServices"/> that will be used to invoke JavaScript code.</param>
/// <param name="bootModule">The path to the JavaScript file containing the prerendering logic.</param>
/// <param name="requestAbsoluteUrl">The URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param>
/// <param name="requestPathAndQuery">The path and query part of the URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param>
/// <param name="customDataParameter">An optional JSON-serializable parameter to be supplied to the prerendering code.</param>
/// <param name="timeoutMilliseconds">The maximum duration to wait for prerendering to complete.</param>
/// <returns></returns>
public static Task<RenderToStringResult> RenderToString(
string applicationBasePath,
INodeServices nodeServices,

View File

@@ -2,10 +2,28 @@ using Newtonsoft.Json.Linq;
namespace Microsoft.AspNetCore.SpaServices.Prerendering
{
/// <summary>
/// Describes the prerendering result returned by JavaScript code.
/// </summary>
public class RenderToStringResult
{
/// <summary>
/// If set, specifies JSON-serializable data that should be added as a set of global JavaScript variables in the document.
/// This can be used to transfer arbitrary data from server-side prerendering code to client-side code (for example, to
/// transfer the state of a Redux store).
/// </summary>
public JObject Globals { get; set; }
/// <summary>
/// The HTML generated by the prerendering logic.
/// </summary>
public string Html { get; set; }
/// <summary>
/// If set, specifies that instead of rendering HTML, the response should be an HTTP redirection to this URL.
/// This can be used if the prerendering code determines that the requested URL would lead to a redirection according
/// to the SPA's routing configuration.
/// </summary>
public string RedirectUrl { get; set; }
}
}

View File

@@ -7,10 +7,22 @@ using Microsoft.AspNetCore.SpaServices;
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Extension methods useful for configuring routing in a single-page application (SPA).
/// </summary>
public static class SpaRouteExtensions
{
private const string ClientRouteTokenName = "clientRoute";
/// <summary>
/// Configures a route that is automatically bypassed if the requested URL appears to be for a static file
/// (e.g., if it has a filename extension).
/// </summary>
/// <param name="routeBuilder">The <see cref="IRouteBuilder"/>.</param>
/// <param name="name">The route name.</param>
/// <param name="defaults">Default route parameters.</param>
/// <param name="constraints">Route constraints.</param>
/// <param name="dataTokens">Route data tokens.</param>
public static void MapSpaFallbackRoute(
this IRouteBuilder routeBuilder,
string name,
@@ -27,6 +39,16 @@ namespace Microsoft.AspNetCore.Builder
dataTokens);
}
/// <summary>
/// Configures a route that is automatically bypassed if the requested URL appears to be for a static file
/// (e.g., if it has a filename extension).
/// </summary>
/// <param name="routeBuilder">The <see cref="IRouteBuilder"/>.</param>
/// <param name="name">The route name.</param>
/// <param name="templatePrefix">The template prefix.</param>
/// <param name="defaults">Default route parameters.</param>
/// <param name="constraints">Route constraints.</param>
/// <param name="dataTokens">Route data tokens.</param>
public static void MapSpaFallbackRoute(
this IRouteBuilder routeBuilder,
string name,

View File

@@ -8,16 +8,29 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json;
// Putting in this namespace so it's always available whenever MapRoute is
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Extension methods that can be used to enable Webpack dev middleware support.
/// </summary>
public static class WebpackDevMiddleware
{
private const string WebpackDevMiddlewareScheme = "http";
private const string WebpackHotMiddlewareEndpoint = "/__webpack_hmr";
private const string DefaultConfigFile = "webpack.config.js";
/// <summary>
/// Enables Webpack dev middleware support. This hosts an instance of the Webpack compiler in memory
/// in your application so that you can always serve up-to-date Webpack-built resources without having
/// to run the compiler manually. Since the Webpack compiler instance is retained in memory, incremental
/// compilation is vastly faster that re-running the compiler from scratch.
///
/// Incoming requests that match Webpack-built files will be handled by returning the Webpack compiler
/// output directly, regardless of files on disk. If compilation is in progress when the request arrives,
/// the response will pause until updated compiler output is ready.
/// </summary>
/// <param name="appBuilder">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="options">Options for configuring the Webpack compiler instance.</param>
public static void UseWebpackDevMiddleware(
this IApplicationBuilder appBuilder,
WebpackDevMiddlewareOptions options = null)

View File

@@ -2,13 +2,42 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.SpaServices.Webpack
{
/// <summary>
/// Options for configuring a Webpack dev middleware compiler.
/// </summary>
public class WebpackDevMiddlewareOptions
{
/// <summary>
/// If true, hot module replacement (HMR) will be enabled. This automatically updates Webpack-built
/// resources (such as JavaScript, CSS, or images) in your web browser whenever source files are changed.
/// </summary>
public bool HotModuleReplacement { get; set; }
/// <summary>
/// Overrides the internal port number that client-side HMR code will connect to.
/// </summary>
public int HotModuleReplacementServerPort { get; set; }
/// <summary>
/// If true, enables React-specific extensions to Webpack's hot module replacement (HMR) feature.
/// This enables React components to be updated without losing their in-memory state.
/// </summary>
public bool ReactHotModuleReplacement { get; set; }
/// <summary>
/// Specifies the Webpack configuration file to be used. If not set, defaults to 'webpack.config.js'.
/// </summary>
public string ConfigFile { get; set; }
/// <summary>
/// The root path of your project. Webpack runs in this context.
/// </summary>
public string ProjectPath { get; set; }
/// <summary>
/// Specifies additional environment variables to be passed to the Node instance hosting
/// the webpack compiler.
/// </summary>
public IDictionary<string, string> EnvironmentVariables { get; set; }
}
}

View File

@@ -17,7 +17,8 @@
"keyFile": "../../tools/Key.snk",
"embed": [
"Content/**/*"
]
],
"xmlDoc": true
},
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.1",