diff --git a/Sources/Vaux/Attributes.swift b/Sources/Vaux/Attributes.swift index f2697cb..71e8f7e 100644 --- a/Sources/Vaux/Attributes.swift +++ b/Sources/Vaux/Attributes.swift @@ -101,13 +101,11 @@ extension HTML { /// - attributes: An array of structs typed `StyleAttribute` that contain a key and value for inline styling. public func style(_ attributes: [StyleAttribute]) -> HTML { var inlineStyle = String() - for (index, attribute) in attributes.enumerated() { + for attribute in attributes { inlineStyle.write(attribute.key) inlineStyle.write(":") inlineStyle.write(attribute.value) - if index == 0, attributes.count > 1, index != attributes.count - 1 { - inlineStyle.write(";") - } + inlineStyle.write(";") } return attr("style", inlineStyle) } diff --git a/Tests/VauxTests/VauxTests.swift b/Tests/VauxTests/VauxTests.swift index f9df6ba..5c7ef2f 100644 --- a/Tests/VauxTests/VauxTests.swift +++ b/Tests/VauxTests/VauxTests.swift @@ -259,7 +259,7 @@ final class VauxTests: XCTestCase {
When I was
-
+
a young boy,
my father took me into the city.
@@ -790,7 +790,7 @@ final class VauxTests: XCTestCase {
let correctHTML = """
-
+
+ This is a paragraph.
+
This is a heading of weight 1
@@ -1311,8 +1311,8 @@ final class VauxTests: XCTestCase {
@@ -3125,6 +3125,45 @@ final class VauxTests: XCTestCase {
}
}
+ func testStyles() {
+ func pageWithHeading() -> HTML {
+ html {
+ body {
+ heading(.h1) {
+ "This is a heading"
+ }.style([StyleAttribute(key: "color", value: "blue"),
+ StyleAttribute(key: "font-family", value: "verdana")])
+ paragraph {
+ "This is a paragraph."
+ }.style([StyleAttribute(key: "font-family", value: "courier"),
+ StyleAttribute(key: "font-size", value: "160%"),
+ StyleAttribute(key: "color", value: "blue")])
+ }.style([StyleAttribute(key: "background-color", value: "powderblue")])
+ }
+ }
+ let correctHTML = """
+
+
+
+
+ This is a heading
+
+