| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TextSlugificationExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Globalization; |
| | | 9 | | using MyNet.Primitives; |
| | | 10 | | using MyNet.Text.Slugification; |
| | | 11 | | |
| | | 12 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 13 | | namespace MyNet.Text; |
| | | 14 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 15 | | |
| | | 16 | | public static class TextSlugificationExtensions |
| | | 17 | | { |
| | | 18 | | extension(TextPipeline pipeline) |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Applies a slugification transform to the pipeline. |
| | | 22 | | /// </summary> |
| | | 23 | | public TextPipeline Slugify(ITextSlugifierTransform transform) |
| | | 24 | | { |
| | 0 | 25 | | ArgumentNullException.ThrowIfNull(transform); |
| | 0 | 26 | | return pipeline.Apply(transform); |
| | | 27 | | } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | extension(string input) |
| | | 31 | | { |
| | | 32 | | /// <summary> |
| | | 33 | | /// Applies a slugification transform. |
| | | 34 | | /// </summary> |
| | | 35 | | public string Slugify(ITextSlugifierTransform transform, CultureInfo? culture = null) |
| | | 36 | | { |
| | 15 | 37 | | ArgumentNullException.ThrowIfNull(transform); |
| | 15 | 38 | | return transform.Apply(input, culture.OrCurrent()); |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Converts text to a URL-friendly slug. |
| | | 43 | | /// </summary> |
| | | 44 | | public string Slugify(TextSlugifierOptions? options = null, CultureInfo? culture = null) |
| | 9 | 45 | | => input.Slugify(new SlugifyTransform(options ?? new TextSlugifierOptions()), culture); |
| | | 46 | | } |
| | | 47 | | } |
| | | 48 | | |