Skip to content

Commit

Permalink
SGML, HTML, Sitemap, RSS, SVG targets (#2)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tib authored Dec 21, 2021
1 parent ebf9092 commit 46702be
Show file tree
Hide file tree
Showing 171 changed files with 775 additions and 196 deletions.
25 changes: 24 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,41 @@ let package = Package(
.macOS(.v10_15)
],
products: [
.library(name: "SwiftSgml", targets: ["SwiftSgml"]),
.library(name: "SwiftHtml", targets: ["SwiftHtml"]),
.library(name: "SwiftSvg", targets: ["SwiftSvg"]),
.library(name: "SwiftSitemap", targets: ["SwiftSitemap"]),
.library(name: "SwiftRss", targets: ["SwiftRss"]),
],
dependencies: [

],
targets: [
.target(name: "SwiftSgml", dependencies: []),
.target(name: "SwiftHtml", dependencies: [

.target(name: "SwiftSgml")
]),
.target(name: "SwiftSvg", dependencies: [
.target(name: "SwiftSgml")
]),
.target(name: "SwiftSitemap", dependencies: [
.target(name: "SwiftSgml")
]),
.target(name: "SwiftRss", dependencies: [
.target(name: "SwiftSgml")
]),
.testTarget(name: "SwiftHtmlTests", dependencies: [
.target(name: "SwiftHtml"),
]),
.testTarget(name: "SwiftSvgTests", dependencies: [
.target(name: "SwiftSvg"),
]),
.testTarget(name: "SwiftSitemapTests", dependencies: [
.target(name: "SwiftSitemap"),
]),
.testTarget(name: "SwiftRssTests", dependencies: [
.target(name: "SwiftRss"),
]),
]
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An awesome Swift HTML DSL library using result builders.
```swift
import SwiftHtml

let doc = Document {
let doc = Document(.html) {
Html {
Head {
Title("Hello Swift HTML DSL")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions Sources/SwiftHtml/Exported.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Exported.swift
// SwiftHtml
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

@_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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions Sources/SwiftHtml/Text.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// File.swift
//
// Text.swift
// SwiftHtml
//
// Created by Tibor Bodecs on 2021. 11. 29..
//


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

public init(_ contents: String) {
Expand Down
12 changes: 12 additions & 0 deletions Sources/SwiftRss/Channel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Channel.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public class Channel: Tag {
public init(@TagBuilder _ builder: () -> [Tag]) {
super.init(Node(type: .standard, name: "channel"), children: builder())
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/Description.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Description.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Description: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "description", contents: "<![CDATA[" + contents + "]]>"))
}
}
8 changes: 8 additions & 0 deletions Sources/SwiftRss/Exported.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Exported.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

@_exported import SwiftSgml
21 changes: 21 additions & 0 deletions Sources/SwiftRss/Guid.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Guid.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Guid: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "guid", contents: contents))
}
}

public extension Guid {

func isPermalink(_ value: Bool = true) -> Self {
node.upsert(Attribute(key: "isPermalink", value: String(value)))
return self
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/Item.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Item.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//


public class Item: Tag {
public init(@TagBuilder _ builder: () -> [Tag]) {
super.init(Node(type: .standard, name: "item"), children: builder())
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/Language.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Language.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Language: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "language", contents: contents))
}
}
14 changes: 14 additions & 0 deletions Sources/SwiftRss/LastBuildDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// LastBuildDate.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//


public final class LastBuildDate: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "lastBuildDate", contents: contents))
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/Link.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Link.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Link: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "link", contents: contents))
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/PubDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// PubDate.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class PubDate: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "pubDate", contents: contents))
}
}
17 changes: 17 additions & 0 deletions Sources/SwiftRss/Rss.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Rss.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

// https://validator.w3.org/feed/docs/rss2.html#ltttlgtSubelementOfLtchannelgt
public final class Rss: Tag {

public init(@TagBuilder _ builder: () -> [Tag]) {
super.init(Node(type: .standard, name: "rss", attributes: [
.init(key: "version", value: "2.0"),
// .init(key: "xmlns:atom", value: "http://www.w3.org/2005/Atom"),
]), children: builder())
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/Title.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Title.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Title: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "title", contents: "<![CDATA[" + contents + "]]>"))
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftRss/Ttl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Ttl.swift
// SwiftRss
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Ttl: Tag {

public init(_ value: Int) {
super.init(Node(type: .standard, name: "ttl", contents: String(value)))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Attribute.swift
// SwiftHtml
// SwiftSgml
//
// Created by Tibor Bodecs on 2021. 07. 19..
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Document.swift
// SwiftHtml
// SwiftSgml
//
// Created by Tibor Bodecs on 2021. 07. 19..
//
Expand All @@ -17,7 +17,7 @@ public struct Document {
public let type: `Type`
public let root: Tag

public init(_ type: `Type` = .html, _ builder: () -> Tag) {
public init(_ type: `Type` = .unspecified, _ builder: () -> Tag) {
self.type = type
self.root = builder()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// DocumentRenderer.swift
// SwiftHtml
// SwiftSgml
//
// Created by Tibor Bodecs on 2021. 11. 19..
//
Expand All @@ -24,7 +24,6 @@ public struct DocumentRenderer {
// MARK: - private render methods

private func renderDocumentType(_ type: Document.`Type`) -> String {

switch type {
case .unspecified:
return ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Node.swift
// SwiftHtml
// SwiftSgml
//
// Created by Tibor Bodecs on 2021. 07. 19..
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Tag.swift
// SwiftHtml
// SwiftSgml
//
// Created by Tibor Bodecs on 2021. 11. 19..
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// TagBuilder.swift
// SwiftHtml
// SwiftSgml
//
// Created by Tibor Bodecs on 2021. 07. 19..
//
Expand Down
23 changes: 23 additions & 0 deletions Sources/SwiftSitemap/ChangeFreq.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Changefreq.swift
// SwiftSitemap
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class ChangeFreq: Tag {

public enum Value: String {
case always
case hourly
case daily
case weekly
case monthly
case yearly
case never
}

public init(_ value: Value) {
super.init(Node(type: .standard, name: "changefreq", contents: value.rawValue))
}
}
8 changes: 8 additions & 0 deletions Sources/SwiftSitemap/Exported.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Exported.swift
// SwiftSitemap
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

@_exported import SwiftSgml
13 changes: 13 additions & 0 deletions Sources/SwiftSitemap/LastMod.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// LastMod.swift
// SwiftSitemap
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class LastMod: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "lastmod", contents: contents))
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftSitemap/Loc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Loc.swift
// SwiftSitemap
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Loc: Tag {

public init(_ contents: String) {
super.init(Node(type: .standard, name: "loc", contents: contents))
}
}
13 changes: 13 additions & 0 deletions Sources/SwiftSitemap/Priority.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Priority.swift
// SwiftSitemap
//
// Created by Tibor Bodecs on 2021. 12. 19..
//

public final class Priority: Tag {

public init(_ value: Double) {
super.init(Node(type: .standard, name: "priority", contents: String(value)))
}
}
Loading

0 comments on commit 46702be

Please sign in to comment.