From 1f7d5b39d1b59eb11523b9b50d034a492a4a0800 Mon Sep 17 00:00:00 2001 From: JPToroDev Date: Tue, 24 Dec 2024 18:04:10 -0500 Subject: [PATCH] Fix bug where `ForEach` generates empty `
  • ` tags. Add `InlineHTML` support to `fontWeight()` modifier. --- Sources/Ignite/Framework/ForEach.swift | 10 +++++++++- Sources/Ignite/Modifiers/FontWeightModifier.swift | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/Ignite/Framework/ForEach.swift b/Sources/Ignite/Framework/ForEach.swift index 42a77ab1..7e71bdfa 100644 --- a/Sources/Ignite/Framework/ForEach.swift +++ b/Sources/Ignite/Framework/ForEach.swift @@ -6,7 +6,7 @@ // /// A structure that creates HTML content by mapping over a sequence of data. -public struct ForEach: InlineHTML, BlockHTML { +public struct ForEach: InlineHTML, BlockHTML, ListableElement { /// The body content created by mapping over the data sequence. public var body: some HTML { self } @@ -46,4 +46,12 @@ public struct ForEach: InlineHTML, BlockHTML { return output } + + /// Renders the ForEach content when this isn't part of a list. + /// - Parameter context: The current publishing context. + /// - Returns: The rendered HTML string. + func renderInList(context: PublishingContext) -> String { + // ListableElement conformance ensures other views never wrap ForEach in
  • tags. + render(context: context) + } } diff --git a/Sources/Ignite/Modifiers/FontWeightModifier.swift b/Sources/Ignite/Modifiers/FontWeightModifier.swift index a6b2efe3..82e2c7f4 100644 --- a/Sources/Ignite/Modifiers/FontWeightModifier.swift +++ b/Sources/Ignite/Modifiers/FontWeightModifier.swift @@ -26,3 +26,12 @@ public extension HTML { modifier(FontWeightModifier(weight: newWeight)) } } + +public extension InlineHTML { + /// Adjusts the font weight (boldness) of this font. + /// - Parameter newWeight: The new font weight. + /// - Returns: A new `Text` instance with the updated weight. + func fontWeight(_ newWeight: Font.Weight) -> some InlineHTML { + modifier(FontWeightModifier(weight: newWeight)) + } +}