Skip to content
Open
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
46 changes: 46 additions & 0 deletions src/Components/Components/src/AcceptsAssetPathAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Components;

/// <summary>
/// Declares an HTML element and attribute combination that accepts static asset-path expansion.
/// </summary>
/// <remarks>
/// The Razor compiler discovers this metadata on public classes named <c>AssetPathAttributes</c>.
/// </remarks>
/// <example>
/// <code>
/// [AcceptsAssetPath("img", "src")]
/// public static class AssetPathAttributes
/// {
/// }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class AcceptsAssetPathAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of <see cref="AcceptsAssetPathAttribute"/>.
/// </summary>
/// <param name="elementName">The HTML element name.</param>
/// <param name="attributeName">The HTML attribute name.</param>
public AcceptsAssetPathAttribute(string elementName, string attributeName)
{
ArgumentNullException.ThrowIfNull(elementName);
ArgumentNullException.ThrowIfNull(attributeName);

ElementName = elementName;
AttributeName = attributeName;
}

/// <summary>
/// Gets the HTML element name.
/// </summary>
public string ElementName { get; }

/// <summary>
/// Gets the HTML attribute name.
/// </summary>
public string AttributeName { get; }
}
22 changes: 22 additions & 0 deletions src/Components/Components/src/AssetPathAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Components;

/// <summary>
/// Indicates that a component parameter accepts a static asset path that the Razor compiler can expand.
/// </summary>
/// <remarks>
/// This attribute is valid only on properties that are also marked with <see cref="ParameterAttribute"/>.
/// </remarks>
Comment on lines +9 to +11
/// <example>
/// <code>
/// [Parameter]
/// [AssetPath]
/// public string? Source { get; set; }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class AssetPathAttribute : Attribute
{
}
6 changes: 6 additions & 0 deletions src/Components/Components/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#nullable enable
Microsoft.AspNetCore.Components.AcceptsAssetPathAttribute
Microsoft.AspNetCore.Components.AcceptsAssetPathAttribute.AcceptsAssetPathAttribute(string! elementName, string! attributeName) -> void
Microsoft.AspNetCore.Components.AcceptsAssetPathAttribute.AttributeName.get -> string!
Microsoft.AspNetCore.Components.AcceptsAssetPathAttribute.ElementName.get -> string!
Microsoft.AspNetCore.Components.AssetPathAttribute
Microsoft.AspNetCore.Components.AssetPathAttribute.AssetPathAttribute() -> void
Microsoft.AspNetCore.Components.CacheBehavior
Microsoft.AspNetCore.Components.CacheBehavior.Rerender = 0 -> Microsoft.AspNetCore.Components.CacheBehavior
Microsoft.AspNetCore.Components.CacheBehavior.Throw = 1 -> Microsoft.AspNetCore.Components.CacheBehavior
Expand Down
1 change: 1 addition & 0 deletions src/Components/Web/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
Microsoft.AspNetCore.Components.Web.AssetPathAttributes
Microsoft.AspNetCore.Components.Web.EnvironmentView
Microsoft.AspNetCore.Components.Web.EnvironmentView.ChildContent.get -> Microsoft.AspNetCore.Components.RenderFragment?
Microsoft.AspNetCore.Components.Web.EnvironmentView.ChildContent.set -> void
Expand Down
24 changes: 24 additions & 0 deletions src/Components/Web/src/Web/AssetPathAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Components.Web;

/// <summary>
/// Infrastructure for the discovery of HTML attributes that accept static asset-path expansion.
/// </summary>
/// <remarks>
/// To extend the supported element and attribute combinations, define a public class named
/// <c>AssetPathAttributes</c> and annotate it with <see cref="AcceptsAssetPathAttribute"/>.
/// </remarks>
[AcceptsAssetPath("audio", "src")]
[AcceptsAssetPath("img", "src")]
[AcceptsAssetPath("input", "src")]
[AcceptsAssetPath("link", "href")]
[AcceptsAssetPath("script", "src")]
[AcceptsAssetPath("source", "src")]
[AcceptsAssetPath("track", "src")]
[AcceptsAssetPath("video", "poster")]
[AcceptsAssetPath("video", "src")]
public static class AssetPathAttributes
{
}
Loading