From 92b55c633c9f4f31b1f0ea0e6d35ee3db7538214 Mon Sep 17 00:00:00 2001 From: bgisme <55024704+bgisme@users.noreply.github.com> Date: Mon, 2 Jan 2023 12:07:48 -0500 Subject: [PATCH 001/141] Tag subclasses can customize html name --- Sources/SwiftHtml/Tags/Comment.swift | 6 +++--- Sources/SwiftRss/LastBuildDate.swift | 6 ++---- Sources/SwiftRss/PubDate.swift | 4 +--- Sources/SwiftSgml/EmptyTag.swift | 6 ++---- Sources/SwiftSgml/GroupTag.swift | 6 +++--- Sources/SwiftSgml/Tag.swift | 25 ++++++++++++++----------- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Sources/SwiftHtml/Tags/Comment.swift b/Sources/SwiftHtml/Tags/Comment.swift index f6c00bd..21be1ab 100644 --- a/Sources/SwiftHtml/Tags/Comment.swift +++ b/Sources/SwiftHtml/Tags/Comment.swift @@ -14,9 +14,9 @@ /// This is especially useful if you have a lot of code. open class Comment: Tag { - open override class func createNode() -> Node { - Node(type: .comment) - } + open class override var name: String? { nil } + + open class override var type: Node.NodeType { .comment } public init(_ contents: String) { super.init() diff --git a/Sources/SwiftRss/LastBuildDate.swift b/Sources/SwiftRss/LastBuildDate.swift index ab35883..c5eb9e2 100644 --- a/Sources/SwiftRss/LastBuildDate.swift +++ b/Sources/SwiftRss/LastBuildDate.swift @@ -7,8 +7,6 @@ open class LastBuildDate: Tag { - - open override class func createNode() -> Node { - Node(type: .standard, name: "lastBuildDate") - } + + open class override var name: String? { "lastBuildDate" } } diff --git a/Sources/SwiftRss/PubDate.swift b/Sources/SwiftRss/PubDate.swift index 872905c..d826191 100644 --- a/Sources/SwiftRss/PubDate.swift +++ b/Sources/SwiftRss/PubDate.swift @@ -7,7 +7,5 @@ open class PubDate: Tag { - open override class func createNode() -> Node { - Node(type: .standard, name: "pubDate") - } + open class override var name: String? { "pubDate" } } diff --git a/Sources/SwiftSgml/EmptyTag.swift b/Sources/SwiftSgml/EmptyTag.swift index 2083a29..cea900b 100644 --- a/Sources/SwiftSgml/EmptyTag.swift +++ b/Sources/SwiftSgml/EmptyTag.swift @@ -6,11 +6,9 @@ // open class EmptyTag: Tag { - - open override class func createNode() -> Node { - Node(type: .empty, name: String(describing: self).lowercased()) - } + open class override var type: Node.NodeType { .empty } + public init() { super.init() } diff --git a/Sources/SwiftSgml/GroupTag.swift b/Sources/SwiftSgml/GroupTag.swift index 41f3b36..9bc6b78 100644 --- a/Sources/SwiftSgml/GroupTag.swift +++ b/Sources/SwiftSgml/GroupTag.swift @@ -7,8 +7,8 @@ open class GroupTag: Tag { + + open class override var name: String? { nil } - open override class func createNode() -> Node { - .init(type: .group) - } + open class override var type: Node.NodeType { .group } } diff --git a/Sources/SwiftSgml/Tag.swift b/Sources/SwiftSgml/Tag.swift index 7464a64..4efaed0 100644 --- a/Sources/SwiftSgml/Tag.swift +++ b/Sources/SwiftSgml/Tag.swift @@ -11,25 +11,29 @@ open class Tag { public private(set) var children: [Tag] // MARK: - init + + open class var name: String? { String(describing: self).lowercased() } + + open class var type: Node.NodeType { .standard } - open class func createNode() -> Node { - Node(type: .standard, name: String(describing: self).lowercased()) + open class func createNode(_ type: Node.NodeType, _ name: String?) -> Node { + Node(type: type, name: name) } /// initialize a new Tag with child tags - public init(_ children: [Tag] = []) { - self.node = Self.createNode() + public init(name: String? = nil, type: Node.NodeType? = nil, _ children: [Tag] = []) { + self.node = Self.createNode(type ?? Self.type, name ?? Self.name) self.children = children } /// initialize a new Tag with a single child tag - public convenience init(_ child: Tag) { - self.init([child]) + public convenience init(name: String? = nil, type: Node.NodeType? = nil, _ child: Tag) { + self.init(name: name, type: type, [child]) } /// initialize a new Tag with children using a builder - public convenience init(@TagBuilder _ builder: () -> [Tag]) { - self.init(builder()) + public convenience init(name: String? = nil, type: Node.NodeType? = nil, @TagBuilder _ builder: () -> [Tag]) { + self.init(name: name, type: type, builder()) } // /// initialize a new Tag with children using an async throwing builder @@ -37,10 +41,9 @@ open class Tag { // self.init(try await builder()) // } - /// initialize a new Tag with some contents - public convenience init(_ contents: String?) { - self.init() + public convenience init(name: String? = nil, type: Node.NodeType? = nil, _ contents: String?) { + self.init(name: name, type: type) if let contents = contents { setContents(contents) } From e0d330ca8b6e34d5a90f771db22b2e8c005d1c2f Mon Sep 17 00:00:00 2001 From: bgisme <55024704+bgisme@users.noreply.github.com> Date: Mon, 2 Jan 2023 12:49:34 -0500 Subject: [PATCH 002/141] name lowercased() --- Sources/SwiftSgml/Tag.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftSgml/Tag.swift b/Sources/SwiftSgml/Tag.swift index 4efaed0..36a1b81 100644 --- a/Sources/SwiftSgml/Tag.swift +++ b/Sources/SwiftSgml/Tag.swift @@ -12,7 +12,7 @@ open class Tag { // MARK: - init - open class var name: String? { String(describing: self).lowercased() } + open class var name: String? { String(describing: self) } open class var type: Node.NodeType { .standard } @@ -22,7 +22,8 @@ open class Tag { /// initialize a new Tag with child tags public init(name: String? = nil, type: Node.NodeType? = nil, _ children: [Tag] = []) { - self.node = Self.createNode(type ?? Self.type, name ?? Self.name) + let name = name ?? Self.name + self.node = Self.createNode(type ?? Self.type, name?.lowercased()) self.children = children } From afcbf3e83e87f72e655e7774cd3350b89d9bb46b Mon Sep 17 00:00:00 2001 From: bgisme <55024704+bgisme@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:10:32 -0500 Subject: [PATCH 003/141] Need to make rawValue public so any Tag can set the attribute --- Sources/SwiftHtml/Attributes/Target.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftHtml/Attributes/Target.swift b/Sources/SwiftHtml/Attributes/Target.swift index b02493d..558d8b7 100644 --- a/Sources/SwiftHtml/Attributes/Target.swift +++ b/Sources/SwiftHtml/Attributes/Target.swift @@ -28,7 +28,7 @@ public enum TargetFrame { /// Opens the linked document in the named iframe case frame(String) - var rawValue: String { + public var rawValue: String { switch self { case .blank: return "_blank" From 6344acef0190c61c38618db7a86a9c300b3d6f7e Mon Sep 17 00:00:00 2001 From: bgisme <55024704+bgisme@users.noreply.github.com> Date: Tue, 14 Feb 2023 10:29:39 -0500 Subject: [PATCH 004/141] Class name var --- Sources/SwiftHtml/Tags/H6.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftHtml/Tags/H6.swift b/Sources/SwiftHtml/Tags/H6.swift index a15b271..735a345 100644 --- a/Sources/SwiftHtml/Tags/H6.swift +++ b/Sources/SwiftHtml/Tags/H6.swift @@ -12,5 +12,6 @@ /// **Note:** Only use one `