Swiftpack.co - coe/MarkUpDynamic as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by coe.
coe/MarkUpDynamic 2.1.0
Markup generator for Swift.
โญ๏ธ 0
๐Ÿ•“ 2 years ago
.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: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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