Repository: sahandnayebaziz/Hypertext
Branch: master
Commit: fc367154c79a
Files: 13
Total size: 27.9 KB
Directory structure:
gitextract_nugr38gz/
├── .gitignore
├── .travis.sh
├── .travis.yml
├── CHANGELOG.md
├── Hypertext.podspec
├── LICENSE
├── Package.swift
├── README.md
├── Sources/
│ ├── Doctype.swift
│ ├── Hypertext.swift
│ └── Tags.swift
└── Tests/
├── HypertextTests/
│ └── HypertextTests.swift
└── LinuxMain.swift
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xcuserstate
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
================================================
FILE: .travis.sh
================================================
#!/usr/bin/env bash
# adapted from https://github.com/vapor/swift/blob/master/ci
echo "Hypertext Continuous Integration";
UBUNTU_RELEASE=`lsb_release -a 2>/dev/null`;
if [[ $UBUNTU_RELEASE == *"15.10"* ]];
then
OS="ubuntu1510";
else
OS="ubuntu1404";
fi
echo "Installing Dependencies"
sudo apt-get install -y clang libicu-dev uuid-dev
echo "Installing Swift";
if [[ $OS == "ubuntu1510" ]];
then
SWIFTFILE="swift-3.0-RELEASE-ubuntu15.10";
else
SWIFTFILE="swift-3.0-RELEASE-ubuntu14.04";
fi
wget https://swift.org/builds/swift-3.0-release/$OS/swift-3.0-RELEASE/$SWIFTFILE.tar.gz
tar -zxf $SWIFTFILE.tar.gz
export PATH=$PWD/$SWIFTFILE/usr/bin:"${PATH}"
echo "Version: `swift --version`";
echo "Building";
swift build
if [[ $? != 0 ]];
then
echo "Build failed";
exit 1;
fi
echo "🔎 Testing";
swift test
if [[ $? != 0 ]];
then
echo "Tests failed";
exit 1;
fi
echo "Done."
================================================
FILE: .travis.yml
================================================
os:
- linux
language: generic
sudo: required
dist: trusty
osx_image: xcode8
script:
- eval "$(curl -sL https://raw.githubusercontent.com/sahandnayebaziz/Hypertext/master/.travis.sh)"
================================================
FILE: CHANGELOG.md
================================================
# Changelog
## [2.1.1](https://github.com/sahandnayebaziz/Hypertext/releases/tag/2.1.1)
September 22, 2017
#### Fixed
- Fixed an extension that was adding a `description` property to all types that conformed to `Renderable`, instead of just to `tag`, that was causing duplication in standard types like `String` and `Int`
thank you @briancprice for [#28](https://github.com/sahandnayebaziz/Hypertext/pull/28)
## [2.1.0](https://github.com/sahandnayebaziz/Hypertext/releases/tag/2.1.0)
January 21st, 2017
#### Added
- Custom tags now, by default, render their tags with HTML-appropriate hyphenation if given a camel case name.
```swift
public class myNewTag: tag {}
myNewTag().render()
// <my-new-tag/>
```
thank you @stupergenius for [#23](https://github.com/sahandnayebaziz/Hypertext/pull/23)
## [2.0.0](https://github.com/sahandnayebaziz/Hypertext/releases/tag/2.0.0)
November 9th, 2016
#### Improved
- Creating a custom tag is easier. The `name` and `isSelfClosing` attributes of `tag` have been changed to computed properties. By default, `name` takes the name of the subclass and `isSelfClosing` returns false. To override either, like we do to create the `img` tag, is simple:
```swift
public class img : tag {
override public var isSelfClosing: Bool {
return true
}
}
```
thank you @Evertt for [#6](https://github.com/sahandnayebaziz/Hypertext/pull/6)
- Initializing a tag with both attributes and children is easier. The order of attributes and children has been flipped so that you can set the attributes first and then set the children off the end of the initializer. Initializing a tag with both attributes and children now looks like:
```swift
p(["class": "greeting"]) { "Well hello there..." }
```
thank you @Evertt for [#10](https://github.com/sahandnayebaziz/Hypertext/pull/10)
- Anything that is `Renderable` now also conforms to `CustomStringConvertible` so you can print and use `tag` subclasses and your own `Renderable` types in String outputs and see them rendered automatically.
thank you @Evertt for [#9](https://github.com/sahandnayebaziz/Hypertext/pull/9)/[#17](https://github.com/sahandnayebaziz/Hypertext/pull/17)
- The `Renderable` protocol's method for rendering formatted, indented HTML has a new signature takes an integer value that lets you specify the number of spaces to use when indenting.
```swift
func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String
```
thank you @Evertt for [#9](https://github.com/sahandnayebaziz/Hypertext/pull/9)/[#18](https://github.com/sahandnayebaziz/Hypertext/pull/18)
#### Added
- A new class called `doctype` that can be used to render the most common HTML doctypes. To render a doctype:
```swift
doctype(.html5).render()
// used in context
let document: Renderable = [
doctype(.html5),
html {[
head {
title { "Hello there" }
},
body { "blabla" }
]}
]
```
thank you @Evertt for [#16](https://github.com/sahandnayebaziz/Hypertext/pull/16)
---
## [1.0.1](https://github.com/sahandnayebaziz/Hypertext/releases/tag/1.0.1)
October 31st, 2016
#### Fixed
- `attributes` being optional, even though it was being initialized to an empty dictionary. It is now guaranteed to be there and still initialized empty. thank you @Evertt for [#7](https://github.com/sahandnayebaziz/Hypertext/pull/7)
#### Updated
- code around rendering `children` in `tag` to use the nil-coalescing operator. thank you @Evertt for [#7](https://github.com/sahandnayebaziz/Hypertext/pull/7)
================================================
FILE: Hypertext.podspec
================================================
Pod::Spec.new do |s|
s.name = "Hypertext"
s.version = "2.1.1"
s.summary = "Compose valid HTML in Swift any way you want to."
s.description = "Hypertext provides a simple, powerful set of classes for composing HTML, including all standard HTML elements, and rendering composed HTML to a string. Best used with a Swift Server."
s.homepage = "https://github.com/sahandnayebaziz/Hypertext"
s.license = 'MIT'
s.author = { "sahandnayebaziz" => "sahand@sahand.me" }
s.source = { :git => "https://github.com/sahandnayebaziz/Hypertext.git", :tag => s.version.to_s }
s.ios.deployment_target = '10.0'
s.osx.deployment_target = '10.12'
s.source_files = 'Sources/*.swift'
end
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2016 Sahand Nayebaziz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: Package.swift
================================================
import PackageDescription
let package = Package(
name: "Hypertext"
)
================================================
FILE: README.md
================================================

Compose valid HTML in Swift any way you want to.
### Usage
````swift
import Hypertext
title { "hello world." }.render()
// <title>hello world.</title>
head { title { "hello world." } }.render()
// <head><title>hello world.</title></head>
head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
// <head>
// <title>
// hello world.
// </title>
// </head>
````
### Requirements
- Swift 3.0+
### Full usage
1. Rendering a tag
```swift
div().render()
// <div></div>
```
2. Rendering a tag with child text
```swift
div { "hello world." }.render()
// <div>hello world.</div>
```
3. Rendering a tag with a child tag
```swift
div { img() }.render()
// <div><img/></div>
```
4. Rendering a tag with multiple child tags
```swift
div { [img(), img(), img()] }.render()
// <div><img/><img/><img/></div>
```
5. Rendering a tag with attributes
```swift
link(["rel": "stylesheet", "type":"text/css", "href":"./style.css"]).render()
// <link rel="stylesheet" type="text/css" href="./style.css"/>
```
6. Rendering a tag with attributes and children
```swift
div(["class": "container"]) { "hello world." }
// <div class="container">hello world.</div>
```
7. Rendering a doctype declaration
```swift
doctype(.html5).render()
// <!DOCTYPE html>
```
8. Rendering unminified, with newlines and indentation
```swift
head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
// <head>
// <title>
// hello world.
// </title>
// </head>
```
9. Rendering a tag in a novel way, any way you want to
```swift
func createTitleTag(forPageNamed pageName: String) -> title {
return title { "Hypertext - \(pageName)" }
}
head { createTitleTag(forPageNamed: "Documentation") }.render()
// <head><title>Hypertext - Documentation</title></head>
```
10. Rendering a custom tag
```swift
public class myNewTag: tag {
override public var isSelfClosing: Bool {
return true
}
}
myNewTag().render()
// <my-new-tag/>
```
11. Rendering a custom type by adopting the protocol `Renderable`
```swift
extension MyType: Renderable {
public func render() -> String { ... }
public func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String { ... }
}
```
================================================
FILE: Sources/Doctype.swift
================================================
public class doctype: Renderable {
public enum Doctype: String {
case html5 = "<!DOCTYPE html>"
case html4Strict = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
case html4Transitional = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
case html4Frameset = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">"
case xhtml1Strict = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
case xhtml1Transitional = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
case xhtml1Frameset = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"
case xhtml11 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"
}
let docType: Doctype
public var description: String { return docType.rawValue }
public init(_ docType: Doctype) { self.docType = docType }
}
================================================
FILE: Sources/Hypertext.swift
================================================
//
// Hypertext.swift
// Hypertext
//
// Created by Sahand Nayebaziz on 10/29/16.
// Copyright © 2016 Sahand Nayebaziz. All rights reserved.
//
import Foundation
public protocol Renderable: CustomStringConvertible {
func render() -> String
func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String
}
public extension CustomStringConvertible {
public func render() -> String {
return String(describing: self)
}
public func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String {
return String(repeating: " ", count: startingWithSpaces) + render()
}
}
extension String: Renderable {}
extension Int: Renderable {}
extension Double: Renderable {}
extension Float: Renderable {}
extension Array: Renderable {
public func render() -> String {
return self.reduce("") { renderedSoFar, item in
guard let renderableItem = item as? Renderable else {
print("Tried to render an item in an array that does not conform to Renderable.")
return renderedSoFar
}
return renderedSoFar + renderableItem.render()
}
}
public func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String {
return self.reduce("") { renderedSoFar, item in
guard let renderableItem = item as? Renderable else {
print("Tried to render an item in an array that does not conform to Renderable.")
return renderedSoFar
}
return renderedSoFar + (renderedSoFar != "" ? "\n" : "") + renderableItem.render(startingWithSpaces: startingWithSpaces, indentingWithSpaces: indentingWithSpaces)
}
}
}
enum TagFormatter {
static func dashed(_ tag: String) -> String {
return delimited(tag, delimiter: "-")
}
static func snaked(_ tag: String) -> String {
return delimited(tag, delimiter: "_")
}
static private func delimited(_ tag: String, delimiter: String) -> String {
let range = NSMakeRange(0, tag.characters.count)
let pattern = "(.)(?=[A-Z])"
#if !os(Linux)
let regex = try! NSRegularExpression(pattern: pattern, options: [])
#else
let regex = try! RegularExpression(pattern: pattern, options: [])
#endif
return regex.stringByReplacingMatches(in: tag, options: [], range: range, withTemplate: "$1\(delimiter)").lowercased()
}
}
open class tag: Renderable {
open var isSelfClosing: Bool { return false }
open var name: String {
let typeName = String(describing: type(of: self))
return TagFormatter.dashed(typeName)
}
public var children: Renderable? = nil
public var attributes: [String: String] = [:]
public var description: String {
return render()
}
public init(_ attributes: [String: String] = [:], setChildren: (() -> Renderable?) = { nil }) {
self.attributes = attributes
self.children = setChildren()
}
public func render() -> String {
if isSelfClosing {
return "<\(name)\(renderAttributes())/>"
} else {
return "<\(name)\(renderAttributes())>\(children?.render() ?? "")</\(name)>"
}
}
public func render(startingWithSpaces: Int, indentingWithSpaces: Int) -> String {
let leadingSpaces = String(repeating: " ", count: startingWithSpaces)
if isSelfClosing {
return "\(leadingSpaces)<\(name)\(renderAttributes())/>"
}
guard let children = children else {
return "\(leadingSpaces)<\(name)\(renderAttributes())></\(name)>"
}
return "\(leadingSpaces)<\(name)\(renderAttributes())>\("\n\(children.render(startingWithSpaces: startingWithSpaces + indentingWithSpaces, indentingWithSpaces: indentingWithSpaces))\n")\(leadingSpaces)</\(name)>"
}
private func renderAttributes() -> String {
return attributes.keys.reduce("") { renderedSoFar, attributeKey in
return "\(renderedSoFar) \(attributeKey)=\"\(attributes[attributeKey]!)\""
}
}
}
================================================
FILE: Sources/Tags.swift
================================================
//
// Tags.swift
// Hypertext
//
// Created by Sahand Nayebaziz on 10/30/16.
// Copyright © 2016 Sahand Nayebaziz. All rights reserved.
//
public class a : tag {}
public class abbr : tag {}
public class address : tag {}
public class article : tag {}
public class aside : tag {}
public class audio : tag {}
public class b : tag {}
public class bb : tag {}
public class bdo : tag {}
public class blockquote : tag {}
public class body : tag {}
public class button : tag {}
public class canvas : tag {}
public class caption : tag {}
public class cite : tag {}
public class code : tag {}
public class colgroup : tag {}
public class datagrid : tag {}
public class datalist : tag {}
public class dd : tag {}
public class del : tag {}
public class detail : tag {}
public class dfn : tag {}
public class dialog : tag {}
public class div : tag {}
public class dl : tag {}
public class em : tag {}
public class fieldset : tag {}
public class figure : tag {}
public class footer : tag {}
public class form : tag {}
public class h1 : tag {}
public class h2 : tag {}
public class h3 : tag {}
public class h4 : tag {}
public class h5 : tag {}
public class h6 : tag {}
public class head : tag {}
public class header : tag {}
public class html : tag {}
public class i : tag {}
public class iframe : tag {}
public class ins : tag {}
public class kbd : tag {}
public class label : tag {}
public class legend : tag {}
public class li : tag {}
public class map : tag {}
public class mark : tag {}
public class menu : tag {}
public class meter : tag {}
public class nav : tag {}
public class noscript : tag {}
public class object : tag {}
public class ol : tag {}
public class optgroup : tag {}
public class option : tag {}
public class output : tag {}
public class p : tag {}
public class pre : tag {}
public class progress : tag {}
public class q : tag {}
public class rp : tag {}
public class rt : tag {}
public class ruby : tag {}
public class samp : tag {}
public class script : tag {}
public class section : tag {}
public class select : tag {}
public class small : tag {}
public class span : tag {}
public class strong : tag {}
public class style : tag {}
public class sub : tag {}
public class sup : tag {}
public class table : tag {}
public class tbody : tag {}
public class td : tag {}
public class textarea : tag {}
public class tfoot : tag {}
public class th : tag {}
public class thead : tag {}
public class time : tag {}
public class title : tag {}
public class tr : tag {}
public class ul : tag {}
public class `var` : tag {}
public class video : tag {}
public class area : tag { override public var isSelfClosing: Bool { return true } }
public class base : tag { override public var isSelfClosing: Bool { return true } }
public class br : tag { override public var isSelfClosing: Bool { return true } }
public class col : tag { override public var isSelfClosing: Bool { return true } }
public class command : tag { override public var isSelfClosing: Bool { return true } }
public class dt : tag { override public var isSelfClosing: Bool { return true } }
public class embed : tag { override public var isSelfClosing: Bool { return true } }
public class hr : tag { override public var isSelfClosing: Bool { return true } }
public class img : tag { override public var isSelfClosing: Bool { return true } }
public class input : tag { override public var isSelfClosing: Bool { return true } }
public class link : tag { override public var isSelfClosing: Bool { return true } }
public class meta : tag { override public var isSelfClosing: Bool { return true } }
public class param : tag { override public var isSelfClosing: Bool { return true } }
public class source : tag { override public var isSelfClosing: Bool { return true } }
================================================
FILE: Tests/HypertextTests/HypertextTests.swift
================================================
import XCTest
@testable import Hypertext
//MARK: Test Tags
class materialButton: tag {}
class camelButton: tag {
override public var name: String {
return String(describing: type(of: self))
}
}
//MARK: Test Cases
class HypertextTests: XCTestCase {
func testCanRenderString() {
let expected = "hello world."
let actual = "hello world.".render()
XCTAssertEqual(expected, actual)
}
func testCanRenderIntRenderable() {
let expected = "<div>2</div>"
let actual = div { 2 }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderDoubleRenderable() {
let expected = "<div>2.0</div>"
let actual = div { 2.0 }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderFloatRenderable() {
let expected = "<div>2.0</div>"
let actual = div { Float(2.0) }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTag() {
let expected = "<title></title>"
let actual = title().render()
XCTAssertEqual(expected, actual)
}
func testCanRenderSelfClosingTag() {
let expected = "<img/>"
let actual = img().render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithStringChild() {
let expected = "<title>hello world.</title>"
let actual = title { "hello world." }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderSelfClosingTagWithoutRenderingChild() {
let expected = "<img/>"
let actual = img { "hello world." }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithChildTag() {
let expected = "<div><img/></div>"
let actual = div { img() }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithMultipleChildTags() {
let expected = "<div><img/><img/><img/></div>"
let actual = div { [img(), img(), img()] }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithChildWithNestedChild() {
let expected = "<div><div><img/></div></div>"
let actual = div { div { img() } }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithChildWithNestedChildAbusingRender() {
let expected = "<div><div><img/></div></div>"
let actual = div { div { img().render() }.render() }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithManyNestedChildren() {
let expected = "<div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div>"
let actual = div { div { div { div { div { div { div { div() } } } } } } }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderAttributeOnTag() {
let expected = "<link href=\"./style.css\"/>"
let actual = link(["href":"./style.css"]).render()
XCTAssertEqual(expected, actual)
}
func testCanRenderAttributeOnNestedTag() {
let expected = "<head><link href=\"./style.css\"/></head>"
let actual = head { link(["href":"./style.css"]) }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithAttributesAndChildren() {
let expected = "<div class=\"container\"><p>Well hello there...</p></div>"
let actual = div(["class":"container"]) { p { "Well hello there..." } }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagsWithFormatting() {
let expected = "<head>\n <title>\n hello world.\n </title>\n</head>"
let actual = head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
XCTAssertEqual(expected, actual)
let expectedFourSpaces = "<head>\n <title>\n hello world.\n </title>\n</head>"
let actualFourSpaces = head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 4)
XCTAssertEqual(expectedFourSpaces, actualFourSpaces)
}
func testCanRenderTagsWithFormattingWithMultipleSiblings() {
let expected = "<div>\n <img/>\n <img/>\n <img/>\n <h1></h1>\n</div>"
let actual = div { [ img(), img(), img(), h1() ] }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
XCTAssertEqual(expected, actual)
}
func testCanCreateCustomTagWithOverridenName() {
let expected = "<mycustomtagname></mycustomtagname>"
class mycustomtag : tag {
override public var name: String {
return "mycustomtagname"
}
}
let actual = mycustomtag().render()
XCTAssertEqual(expected, actual)
}
func testCanDescribeTagAsCustomStringConvertible() {
let expected = "<div>hello world.</div>"
let actual = "\(div { "hello world." })"
XCTAssertEqual(expected, actual)
}
func testCanRenderDoctype() {
let expected = "<!DOCTYPE html>"
let actual = doctype(.html5).render()
XCTAssertEqual(expected, actual)
let expectedHtml4 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
let actualHtml4 = doctype(.html4Strict).render()
XCTAssertEqual(expectedHtml4, actualHtml4)
}
func testSnakeDelimiter() {
let expected = "material_button"
let actual = TagFormatter.snaked("materialButton")
XCTAssertEqual(expected, actual)
let expectedNoOp = "materialbutton"
let actualNoOp = TagFormatter.snaked("materialbutton")
XCTAssertEqual(expectedNoOp, actualNoOp)
}
func testDashDelimiter() {
let expected = "material-button"
let actual = TagFormatter.dashed("materialButton")
XCTAssertEqual(expected, actual)
let expectedNoOp = "materialbutton"
let actualNoOp = TagFormatter.dashed("materialbutton")
XCTAssertEqual(expectedNoOp, actualNoOp)
}
func testDefaultTagFormatIsDashed() {
let expected = "<material-button></material-button>"
let actual = materialButton().render()
XCTAssertEqual(expected, actual)
}
func testCanOverrideDefaultTagFormat() {
let expected = "<camelButton></camelButton>"
let actual = camelButton().render()
XCTAssertEqual(expected, actual)
}
static var allTests : [(String, (HypertextTests) -> () throws -> Void)] {
return [
("testCanRenderString", testCanRenderString),
("testCanRenderIntRenderable", testCanRenderIntRenderable),
("testCanRenderDoubleRenderable", testCanRenderDoubleRenderable),
("testCanRenderFloatRenderable", testCanRenderFloatRenderable),
("testCanRenderTag", testCanRenderTag),
("testCanRenderSelfClosingTag", testCanRenderSelfClosingTag),
("testCanRenderTagWithStringChild", testCanRenderTagWithStringChild),
("testCanRenderSelfClosingTagWithoutRenderingChild", testCanRenderSelfClosingTagWithoutRenderingChild),
("testCanRenderTagWithChildTag", testCanRenderTagWithChildTag),
("testCanRenderTagWithMultipleChildTags", testCanRenderTagWithMultipleChildTags),
("testCanRenderTagWithChildWithNestedChild", testCanRenderTagWithChildWithNestedChild),
("testCanRenderTagWithChildWithNestedChildAbusingRender", testCanRenderTagWithChildWithNestedChildAbusingRender),
("testCanRenderTagWithManyNestedChildren", testCanRenderTagWithManyNestedChildren),
("testCanRenderAttributeOnTag", testCanRenderAttributeOnTag),
("testCanRenderAttributeOnNestedTag", testCanRenderAttributeOnNestedTag),
("testCanRenderTagsWithFormatting", testCanRenderTagsWithFormatting),
("testCanRenderTagsWithFormattingWithMultipleSiblings", testCanRenderTagsWithFormattingWithMultipleSiblings),
("testCanCreateCustomTagWithOverridenName", testCanCreateCustomTagWithOverridenName),
("testCanRenderTagWithAttributesAndChildren", testCanRenderTagWithAttributesAndChildren),
("testCanDescribeTagAsCustomStringConvertible", testCanDescribeTagAsCustomStringConvertible),
("testCanRenderDoctype", testCanRenderDoctype),
("testSnakeDelimiter", testSnakeDelimiter),
("testDashDelimiter", testDashDelimiter),
("testDefaultTagFormatIsDashed", testDefaultTagFormatIsDashed),
("testCanOverrideDefaultTagFormat", testCanOverrideDefaultTagFormat)
]
}
}
================================================
FILE: Tests/LinuxMain.swift
================================================
import XCTest
@testable import HypertextTests
XCTMain([
testCase(HypertextTests.allTests),
])
gitextract_nugr38gz/
├── .gitignore
├── .travis.sh
├── .travis.yml
├── CHANGELOG.md
├── Hypertext.podspec
├── LICENSE
├── Package.swift
├── README.md
├── Sources/
│ ├── Doctype.swift
│ ├── Hypertext.swift
│ └── Tags.swift
└── Tests/
├── HypertextTests/
│ └── HypertextTests.swift
└── LinuxMain.swift
Condensed preview — 13 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (31K chars).
[
{
"path": ".gitignore",
"chars": 1419,
"preview": "# Xcode\n#\n# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore\n\n"
},
{
"path": ".travis.sh",
"chars": 906,
"preview": "#!/usr/bin/env bash\n# adapted from https://github.com/vapor/swift/blob/master/ci\n\necho \"Hypertext Continuous Integration"
},
{
"path": ".travis.yml",
"chars": 185,
"preview": "os:\n - linux\nlanguage: generic\nsudo: required\ndist: trusty\nosx_image: xcode8\nscript:\n- eval \"$(curl -sL https://raw.git"
},
{
"path": "CHANGELOG.md",
"chars": 3529,
"preview": "# Changelog\n\n## [2.1.1](https://github.com/sahandnayebaziz/Hypertext/releases/tag/2.1.1)\nSeptember 22, 2017\n\n#### Fixed\n"
},
{
"path": "Hypertext.podspec",
"chars": 762,
"preview": "Pod::Spec.new do |s|\n s.name = \"Hypertext\"\n s.version = \"2.1.1\"\n s.summary = \"Compose v"
},
{
"path": "LICENSE",
"chars": 1073,
"preview": "MIT License\n\nCopyright (c) 2016 Sahand Nayebaziz\n\nPermission is hereby granted, free of charge, to any person obtaining "
},
{
"path": "Package.swift",
"chars": 74,
"preview": "import PackageDescription\n\nlet package = Package(\n name: \"Hypertext\"\n)\n"
},
{
"path": "README.md",
"chars": 2607,
"preview": "\n\nCompose valid HTML in Swift any way you want to.\n\n### Usage\n\n````swift\n\nimport Hypertext\n\ntitle {"
},
{
"path": "Sources/Doctype.swift",
"chars": 1258,
"preview": "public class doctype: Renderable {\n public enum Doctype: String {\n case html5 = \"<!DOCTYPE html>\"\n case"
},
{
"path": "Sources/Hypertext.swift",
"chars": 4160,
"preview": "//\n// Hypertext.swift\n// Hypertext\n//\n// Created by Sahand Nayebaziz on 10/29/16.\n// Copyright © 2016 Sahand Nayebaz"
},
{
"path": "Sources/Tags.swift",
"chars": 4309,
"preview": "//\n// Tags.swift\n// Hypertext\n//\n// Created by Sahand Nayebaziz on 10/30/16.\n// Copyright © 2016 Sahand Nayebaziz. A"
},
{
"path": "Tests/HypertextTests/HypertextTests.swift",
"chars": 8215,
"preview": "import XCTest\n@testable import Hypertext\n\n//MARK: Test Tags\n\nclass materialButton: tag {}\nclass camelButton: tag {\n ove"
},
{
"path": "Tests/LinuxMain.swift",
"chars": 100,
"preview": "import XCTest\n@testable import HypertextTests\n\nXCTMain([\n testCase(HypertextTests.allTests),\n])\n"
}
]
About this extraction
This page contains the full source code of the sahandnayebaziz/Hypertext GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 13 files (27.9 KB), approximately 7.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.