Swiftpack.co -  coe/MarkUpDynamic as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
coe/MarkUpDynamic
Markup generator for Swift.
.package(url: "https://github.com/coe/MarkUpDynamic.git", from: "2.1.0")

MarkUpDynamic

Markup generator for Swift that like a DSL.

BASIC HTML

let m = MarkUp()

let htmlString = m.html.children {
    m.head.children {
        m.meta(charset: "UTF-8").doNotSpecifyEndTag()
        m.meta(name: "description",
               content: "Free Web tutorials").doNotSpecifyEndTag()
        m.meta(name: "keywords",
               content: "HTML, CSS, JavaScript").doNotSpecifyEndTag()
        m.meta(name: "author",
               content: "John Doe").doNotSpecifyEndTag()
    }
    m.body.children {
        m.p.children {
            "All meta information goes inside the head section."
        }
    }
}
.toString()
<html>
<head>
  <meta charset="UTF-8">
  <meta name="description" content="Free Web tutorials">
  <meta name="keywords" content="HTML, CSS, JavaScript">
  <meta name="author" content="John Doe">
</head>
<body>
  <p>All meta information goes inside the head section.</p>
</body>
</html>

DOCTYPE HTML

let m = MarkUp()
let htmlString = m.children {
    m[dynamicMember: "!DOCTYPE"](https://raw.github.com/coe/MarkUpDynamic/main/html: nil).doNotSpecifyEndTag()
    m.html.children {
        m.head.children {
            m.meta(charset: "UTF-8").doNotSpecifyEndTag()
            m.meta(name: "description",
                   content: "Free Web tutorials").doNotSpecifyEndTag()
            m.meta(name: "keywords",
                   content: "HTML, CSS, JavaScript").doNotSpecifyEndTag()
            m.meta(name: "author",
                   content: "John Doe").doNotSpecifyEndTag()
        }
        m.body.children {
            m.p.children {
                "All meta information goes inside the head section."
            }
        }
    }
}
.toString()
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="description" content="Free Web tutorials">
  <meta name="keywords" content="HTML, CSS, JavaScript">
  <meta name="author" content="John Doe">
</head>
<body>
  <p>All meta information goes inside the head section.</p>
</body>
</html>

BASIC XML

let m = MarkUp()

let htmlString = m.書籍目録.children {
    m.書名.children {
        "XML入門"
    }
    m.著者.children {
        "筒井"
    }
    m.書名.children {
        "続・XML入門"
    }
    m.著者.children {
        "小松"
    }
}
.toString()
<書籍目録>
  <書名>XML入門</書名>
  <著者>筒井</著者>
  <書名>続・XML入門</書名>
  <著者>小松</著者>
</書籍目録>

XML declaration

let m = MarkUp()

let htmlString = m.children {
    m[dynamicMember: "?xml"](https://raw.github.com/coe/MarkUpDynamic/main/version: "1.0",
                             encoding: "UTF-8").doNotSpecifyEndTag(instead: "?")
    m.書籍(出版日: "2007-10-31").children {
        "これは書籍です.... "
    }
}
.toString()
<?xml version="1.0" encoding="UTF-8"?>
<書籍 出版日="2007-10-31">これは書籍です.... </書籍>

Hyphened-Attribute

Use dynamicallyCall.

let m = MarkUp()

let htmlString = m.form.dynamicallyCall(withKeywordArguments: ["accept-charset": "UTF-8"]).toString()
<form accept-charset="UTF-8"></form>

GitHub

link
Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API