Skip to content

Commit 46702be

Browse files
authored
SGML, HTML, Sitemap, RSS, SVG targets (#2)
- New libraries (SwiftSgml, SwiftSitemap, SwiftRss, SwiftSvg) - Unspecified document type is the default - New SVG tags (ellipse, path, polygon, polyline, rect) - New RSS tags - New Sitemap tags
1 parent ebf9092 commit 46702be

File tree

171 files changed

+775
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+775
-196
lines changed

Package.swift

+24-1
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,41 @@ let package = Package(
77
.macOS(.v10_15)
88
],
99
products: [
10+
.library(name: "SwiftSgml", targets: ["SwiftSgml"]),
1011
.library(name: "SwiftHtml", targets: ["SwiftHtml"]),
12+
.library(name: "SwiftSvg", targets: ["SwiftSvg"]),
13+
.library(name: "SwiftSitemap", targets: ["SwiftSitemap"]),
14+
.library(name: "SwiftRss", targets: ["SwiftRss"]),
1115
],
1216
dependencies: [
1317

1418
],
1519
targets: [
20+
.target(name: "SwiftSgml", dependencies: []),
1621
.target(name: "SwiftHtml", dependencies: [
17-
22+
.target(name: "SwiftSgml")
23+
]),
24+
.target(name: "SwiftSvg", dependencies: [
25+
.target(name: "SwiftSgml")
26+
]),
27+
.target(name: "SwiftSitemap", dependencies: [
28+
.target(name: "SwiftSgml")
29+
]),
30+
.target(name: "SwiftRss", dependencies: [
31+
.target(name: "SwiftSgml")
1832
]),
1933
.testTarget(name: "SwiftHtmlTests", dependencies: [
2034
.target(name: "SwiftHtml"),
2135
]),
36+
.testTarget(name: "SwiftSvgTests", dependencies: [
37+
.target(name: "SwiftSvg"),
38+
]),
39+
.testTarget(name: "SwiftSitemapTests", dependencies: [
40+
.target(name: "SwiftSitemap"),
41+
]),
42+
.testTarget(name: "SwiftRssTests", dependencies: [
43+
.target(name: "SwiftRss"),
44+
]),
2245
]
2346
)
2447

README.md

+1-1

Sources/SwiftHtml/Exported.swift

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Exported.swift
3+
// SwiftHtml
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
@_exported import SwiftSgml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Sources/SwiftHtml/Text.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
2-
// File.swift
3-
//
2+
// Text.swift
3+
// SwiftHtml
44
//
55
// Created by Tibor Bodecs on 2021. 11. 29..
66
//
77

8-
8+
/// a plain text node to write simple textual content into the html tree
99
public final class Text: Tag {
1010

1111
public init(_ contents: String) {

Sources/SwiftRss/Channel.swift

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// Channel.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public class Channel: Tag {
9+
public init(@TagBuilder _ builder: () -> [Tag]) {
10+
super.init(Node(type: .standard, name: "channel"), children: builder())
11+
}
12+
}

Sources/SwiftRss/Description.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Description.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Description: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "description", contents: "<![CDATA[" + contents + "]]>"))
12+
}
13+
}

Sources/SwiftRss/Exported.swift

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Exported.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
@_exported import SwiftSgml

Sources/SwiftRss/Guid.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Guid.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Guid: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "guid", contents: contents))
12+
}
13+
}
14+
15+
public extension Guid {
16+
17+
func isPermalink(_ value: Bool = true) -> Self {
18+
node.upsert(Attribute(key: "isPermalink", value: String(value)))
19+
return self
20+
}
21+
}

Sources/SwiftRss/Item.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Item.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
9+
public class Item: Tag {
10+
public init(@TagBuilder _ builder: () -> [Tag]) {
11+
super.init(Node(type: .standard, name: "item"), children: builder())
12+
}
13+
}

Sources/SwiftRss/Language.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Language.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Language: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "language", contents: contents))
12+
}
13+
}

Sources/SwiftRss/LastBuildDate.swift

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// LastBuildDate.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
9+
public final class LastBuildDate: Tag {
10+
11+
public init(_ contents: String) {
12+
super.init(Node(type: .standard, name: "lastBuildDate", contents: contents))
13+
}
14+
}

Sources/SwiftRss/Link.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Link.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Link: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "link", contents: contents))
12+
}
13+
}

Sources/SwiftRss/PubDate.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// PubDate.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class PubDate: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "pubDate", contents: contents))
12+
}
13+
}

Sources/SwiftRss/Rss.swift

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Rss.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
// https://validator.w3.org/feed/docs/rss2.html#ltttlgtSubelementOfLtchannelgt
9+
public final class Rss: Tag {
10+
11+
public init(@TagBuilder _ builder: () -> [Tag]) {
12+
super.init(Node(type: .standard, name: "rss", attributes: [
13+
.init(key: "version", value: "2.0"),
14+
// .init(key: "xmlns:atom", value: "http://www.w3.org/2005/Atom"),
15+
]), children: builder())
16+
}
17+
}

Sources/SwiftRss/Title.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Title.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Title: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "title", contents: "<![CDATA[" + contents + "]]>"))
12+
}
13+
}

Sources/SwiftRss/Ttl.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Ttl.swift
3+
// SwiftRss
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Ttl: Tag {
9+
10+
public init(_ value: Int) {
11+
super.init(Node(type: .standard, name: "ttl", contents: String(value)))
12+
}
13+
}

Sources/SwiftHtml/Components/Attribute.swift renamed to Sources/SwiftSgml/Attribute.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Attribute.swift
3-
// SwiftHtml
3+
// SwiftSgml
44
//
55
// Created by Tibor Bodecs on 2021. 07. 19..
66
//

Sources/SwiftHtml/Components/Document.swift renamed to Sources/SwiftSgml/Document.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Document.swift
3-
// SwiftHtml
3+
// SwiftSgml
44
//
55
// Created by Tibor Bodecs on 2021. 07. 19..
66
//
@@ -17,7 +17,7 @@ public struct Document {
1717
public let type: `Type`
1818
public let root: Tag
1919

20-
public init(_ type: `Type` = .html, _ builder: () -> Tag) {
20+
public init(_ type: `Type` = .unspecified, _ builder: () -> Tag) {
2121
self.type = type
2222
self.root = builder()
2323
}

Sources/SwiftHtml/Components/DocumentRenderer.swift renamed to Sources/SwiftSgml/DocumentRenderer.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// DocumentRenderer.swift
3-
// SwiftHtml
3+
// SwiftSgml
44
//
55
// Created by Tibor Bodecs on 2021. 11. 19..
66
//
@@ -24,7 +24,6 @@ public struct DocumentRenderer {
2424
// MARK: - private render methods
2525

2626
private func renderDocumentType(_ type: Document.`Type`) -> String {
27-
2827
switch type {
2928
case .unspecified:
3029
return ""

Sources/SwiftHtml/Components/Node.swift renamed to Sources/SwiftSgml/Node.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Node.swift
3-
// SwiftHtml
3+
// SwiftSgml
44
//
55
// Created by Tibor Bodecs on 2021. 07. 19..
66
//

Sources/SwiftHtml/Components/Tag.swift renamed to Sources/SwiftSgml/Tag.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Tag.swift
3-
// SwiftHtml
3+
// SwiftSgml
44
//
55
// Created by Tibor Bodecs on 2021. 11. 19..
66
//

Sources/SwiftHtml/Components/TagBuilder.swift renamed to Sources/SwiftSgml/TagBuilder.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// TagBuilder.swift
3-
// SwiftHtml
3+
// SwiftSgml
44
//
55
// Created by Tibor Bodecs on 2021. 07. 19..
66
//

Sources/SwiftSitemap/ChangeFreq.swift

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Changefreq.swift
3+
// SwiftSitemap
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class ChangeFreq: Tag {
9+
10+
public enum Value: String {
11+
case always
12+
case hourly
13+
case daily
14+
case weekly
15+
case monthly
16+
case yearly
17+
case never
18+
}
19+
20+
public init(_ value: Value) {
21+
super.init(Node(type: .standard, name: "changefreq", contents: value.rawValue))
22+
}
23+
}

Sources/SwiftSitemap/Exported.swift

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Exported.swift
3+
// SwiftSitemap
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
@_exported import SwiftSgml

Sources/SwiftSitemap/LastMod.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// LastMod.swift
3+
// SwiftSitemap
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class LastMod: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "lastmod", contents: contents))
12+
}
13+
}

Sources/SwiftSitemap/Loc.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Loc.swift
3+
// SwiftSitemap
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Loc: Tag {
9+
10+
public init(_ contents: String) {
11+
super.init(Node(type: .standard, name: "loc", contents: contents))
12+
}
13+
}

Sources/SwiftSitemap/Priority.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Priority.swift
3+
// SwiftSitemap
4+
//
5+
// Created by Tibor Bodecs on 2021. 12. 19..
6+
//
7+
8+
public final class Priority: Tag {
9+
10+
public init(_ value: Double) {
11+
super.init(Node(type: .standard, name: "priority", contents: String(value)))
12+
}
13+
}

0 commit comments

Comments
 (0)