Skip to content

Commit

Permalink
feat (Builders): image builder logic is now split into separate inter…
Browse files Browse the repository at this point in the history
…faces

This is to add with future extension methods creation.
  • Loading branch information
jamiepollock committed Jan 16, 2024
1 parent 191d839 commit 5bd1d02
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// <summary>
/// An image builder with a URL and Alt Text.
/// </summary>
public interface IUrlAndAltTextImageBuilder
public interface IUrlAndAltTextImageBuilder : IAddImageSourcesImageBuilder<IUrlAndAltTextImageBuilder>, IAddDimensionsImageBuilder<IUrlAndAltTextWithDimensionsImageBuilder>
{
/// <summary>
/// Gets the URL of the builder.
Expand All @@ -22,28 +22,6 @@ public interface IUrlAndAltTextImageBuilder
/// </summary>
public IReadOnlyCollection<IImageSource> Sources { get; }

/// <summary>
/// Adds a source to the builder.
/// </summary>
/// <param name="source">The source.</param>
/// <returns></returns>
IUrlAndAltTextImageBuilder AddSource(IImageSource source);

/// <summary>
/// Adds multiple sources to the builder.
/// </summary>
/// <param name="sources">The sources.</param>
/// <returns></returns>
IUrlAndAltTextImageBuilder AddSources(IReadOnlyCollection<IImageSource> sources);

/// <summary>
/// Adds dimensions to the builder.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>A <see cref="IUrlAndAltTextWithDimensionsImageBuilder"/>.</returns>
IUrlAndAltTextWithDimensionsImageBuilder AddDimensions(int width, int height);

/// <summary>
/// Attempts to build a <see cref="IImage"/> if the input is valid.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ public interface IUrlAndAltTextWithDimensionsImageBuilder
/// </summary>
IReadOnlyCollection<IImageSource> Sources { get; }

/// <summary>
/// Adds a source to the builder.
/// </summary>
/// <param name="source">The source.</param>
/// <returns>A <see cref="IUrlAndAltTextWithDimensionsImageBuilder"/>.</returns>
IUrlAndAltTextWithDimensionsImageBuilder AddSource(IImageSource source);

/// <summary>
/// Adds multiple sources to the builder.
/// </summary>
/// <param name="sources">The sources.</param>
/// <returns>A <see cref="IUrlAndAltTextWithDimensionsImageBuilder"/>.</returns>
IUrlAndAltTextWithDimensionsImageBuilder AddSources(IReadOnlyCollection<IImageSource> sources);

/// <summary>
/// Attempts to build an <see cref="IImage"/> if the current input is valid.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/Rhythm.Drop.Builders/Images/IAddDimensionsImageBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Rhythm.Drop.Builders.Images;

/// <summary>
/// A contract for creating an image builder that can add dimensions.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder to return after adding dimensions.</typeparam>
public interface IAddDimensionsImageBuilder<TBuilder>
{
/// <summary>
/// Adds dimensions to the builder.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>A <typeparamref name="TBuilder"/>.</returns>
TBuilder AddDimensions(int width, int height);
}
25 changes: 25 additions & 0 deletions src/Rhythm.Drop.Builders/Images/IAddImageSourcesImageBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Rhythm.Drop.Builders.Images;

using Rhythm.Drop.Models.Images;
using System.Collections.Generic;

/// <summary>
/// A contract for creating an image builder that can add <see cref="IImageSource"/> objects.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder to return after adding <see cref="IImageSource"/> objects.</typeparam>
public interface IAddImageSourcesImageBuilder<TBuilder>
{
/// <summary>
/// Adds a source to the builder.
/// </summary>
/// <param name="source">The source.</param>
/// <returns>A <typeparamref name="TBuilder"/>.</returns>
TBuilder AddSource(IImageSource source);

/// <summary>
/// Adds multiple sources to the builder.
/// </summary>
/// <param name="sources">The sources.</param>
/// <returns>A <typeparamref name="TBuilder"/>.</returns>
TBuilder AddSources(IReadOnlyCollection<IImageSource> sources);
}
9 changes: 1 addition & 8 deletions src/Rhythm.Drop.Builders/Images/IAltTextImageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
/// <summary>
/// An image builder with alt text.
/// </summary>
public interface IAltTextImageBuilder
public interface IAltTextImageBuilder : IAndUrlImageBuilder<IUrlAndAltTextImageBuilder>
{
/// <summary>
/// Gets the alt text of the builder.
/// </summary>
string? AltText { get; }

/// <summary>
/// Adds a URL to the builder.
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>A <see cref="IUrlAndAltTextImageBuilder"/>.</returns>
IUrlAndAltTextImageBuilder AndUrl(string? url);
}
15 changes: 15 additions & 0 deletions src/Rhythm.Drop.Builders/Images/IAndUrlImageBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Rhythm.Drop.Builders.Images;

/// <summary>
/// A contract for creating an image builder that can add a URL.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder to return after adding a URL.</typeparam>
public interface IAndUrlImageBuilder<TBuilder>
{
/// <summary>
/// Adds a URL to the builder.
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>A <typeparamref name="TBuilder"/>.</returns>
TBuilder AndUrl(string? url);
}

0 comments on commit 5bd1d02

Please sign in to comment.