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()
//
```
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()
//
hello world.
head { title { "hello world." } }.render()
// hello world.
head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
//
//
// hello world.
//
//
````
### Requirements
- Swift 3.0+
### Full usage
1. Rendering a tag
```swift
div().render()
//
```
2. Rendering a tag with child text
```swift
div { "hello world." }.render()
//
hello world.
```
3. Rendering a tag with a child tag
```swift
div { img() }.render()
//
```
4. Rendering a tag with multiple child tags
```swift
div { [img(), img(), img()] }.render()
//
```
5. Rendering a tag with attributes
```swift
link(["rel": "stylesheet", "type":"text/css", "href":"./style.css"]).render()
//
```
6. Rendering a tag with attributes and children
```swift
div(["class": "container"]) { "hello world." }
//
"
let actual = div { 2 }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderDoubleRenderable() {
let expected = "
2.0
"
let actual = div { 2.0 }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderFloatRenderable() {
let expected = "
2.0
"
let actual = div { Float(2.0) }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTag() {
let expected = ""
let actual = title().render()
XCTAssertEqual(expected, actual)
}
func testCanRenderSelfClosingTag() {
let expected = ""
let actual = img().render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithStringChild() {
let expected = "hello world."
let actual = title { "hello world." }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderSelfClosingTagWithoutRenderingChild() {
let expected = ""
let actual = img { "hello world." }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithChildTag() {
let expected = "
"
let actual = div { img() }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithMultipleChildTags() {
let expected = "
"
let actual = div { [img(), img(), img()] }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithChildWithNestedChild() {
let expected = "
"
let actual = div { div { img() } }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithChildWithNestedChildAbusingRender() {
let expected = "
"
let actual = div { div { img().render() }.render() }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithManyNestedChildren() {
let expected = "
"
let actual = div { div { div { div { div { div { div { div() } } } } } } }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderAttributeOnTag() {
let expected = ""
let actual = link(["href":"./style.css"]).render()
XCTAssertEqual(expected, actual)
}
func testCanRenderAttributeOnNestedTag() {
let expected = ""
let actual = head { link(["href":"./style.css"]) }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagWithAttributesAndChildren() {
let expected = "
Well hello there...
"
let actual = div(["class":"container"]) { p { "Well hello there..." } }.render()
XCTAssertEqual(expected, actual)
}
func testCanRenderTagsWithFormatting() {
let expected = "\n \n hello world.\n \n"
let actual = head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
XCTAssertEqual(expected, actual)
let expectedFourSpaces = "\n \n hello world.\n \n"
let actualFourSpaces = head { title { "hello world." } }.render(startingWithSpaces: 0, indentingWithSpaces: 4)
XCTAssertEqual(expectedFourSpaces, actualFourSpaces)
}
func testCanRenderTagsWithFormattingWithMultipleSiblings() {
let expected = "
\n \n \n \n \n
"
let actual = div { [ img(), img(), img(), h1() ] }.render(startingWithSpaces: 0, indentingWithSpaces: 2)
XCTAssertEqual(expected, actual)
}
func testCanCreateCustomTagWithOverridenName() {
let expected = ""
class mycustomtag : tag {
override public var name: String {
return "mycustomtagname"
}
}
let actual = mycustomtag().render()
XCTAssertEqual(expected, actual)
}
func testCanDescribeTagAsCustomStringConvertible() {
let expected = "
hello world.
"
let actual = "\(div { "hello world." })"
XCTAssertEqual(expected, actual)
}
func testCanRenderDoctype() {
let expected = ""
let actual = doctype(.html5).render()
XCTAssertEqual(expected, actual)
let expectedHtml4 = ""
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 = ""
let actual = materialButton().render()
XCTAssertEqual(expected, actual)
}
func testCanOverrideDefaultTagFormat() {
let expected = ""
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),
])