-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 650a9e3
Showing
98 changed files
with
1,512 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
tests: | ||
name: Run Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checking out code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run tests | ||
run: swift test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.DS_Store | ||
|
||
# vim swap files | ||
*.sw[nop] | ||
|
||
# Swift Package Manager | ||
/.build | ||
.swiftpm/xcode/xcuserdata | ||
*.xcuserstate | ||
*.xcworkspacedata | ||
*.orig | ||
_site/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--disable wrapMultilineStatementBraces | ||
--enable isEmpty | ||
--header strip | ||
--commas always | ||
--indent 4 |
5 changes: 5 additions & 0 deletions
5
...xcode/package.xcworkspace/xcuserdata/jasonzurita.xcuserdatad/IDEFindNavigatorScopes.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<array/> | ||
</plist> |
103 changes: 103 additions & 0 deletions
103
.swiftpm/xcode/xcshareddata/xcschemes/SwiftWebsiteDSL.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1500" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "ExampleSwiftWebsite" | ||
BuildableName = "ExampleSwiftWebsite" | ||
BlueprintName = "ExampleSwiftWebsite" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "SwiftWebsiteDSLTest" | ||
BuildableName = "SwiftWebsiteDSLTest" | ||
BlueprintName = "SwiftWebsiteDSLTest" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "SwiftWebsiteDSLTest" | ||
BuildableName = "SwiftWebsiteDSLTest" | ||
BlueprintName = "SwiftWebsiteDSLTest" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "ExampleSwiftWebsite" | ||
BuildableName = "ExampleSwiftWebsite" | ||
BlueprintName = "ExampleSwiftWebsite" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "ExampleSwiftWebsite" | ||
BuildableName = "ExampleSwiftWebsite" | ||
BlueprintName = "ExampleSwiftWebsite" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import SwiftWebsiteDSL | ||
|
||
struct SiteHeader: HtmlProvider { | ||
public let html: HtmlNode = { | ||
Header { | ||
Img(src: "images/logo.svg", alt: "let hello = \"world\"") | ||
.padding([.top], 50) | ||
.width(500) | ||
P("One minute Swift reads to get Swifty-er") | ||
.color(.white) | ||
Div { | ||
// TODO: pull the swift value in from .swift-version | ||
P("Updated for Swift 5.8") | ||
} | ||
.textAlign(.right) | ||
.color(.lightGray) | ||
.padding([.bottom], 1) | ||
.padding([.top], 25) | ||
.padding([.trailing], 18) | ||
} | ||
.background( | ||
.linearGradient(.init(degree: 180, first: (.headerTopBlue, 0), second: (.headerBottomBlue, 100))) | ||
) | ||
// TODO: work on this quirk where we shouldn't need to call `.html` after | ||
.html | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import SwiftWebsiteDSL | ||
|
||
// TODO: custom style guide for code | ||
|
||
func renderHtml() -> String { | ||
let site = | ||
Html { | ||
Head(title: "ExampleSwiftWebsite", cssStyleFileName: "") | ||
Body { | ||
H1("Hello World!") | ||
.padding([.top], 48) | ||
.color(.white) | ||
Footer { | ||
P("Built using the Swift Language and is ") { | ||
A(copy: "open source.", url: "https://github.com/jasonzurita/swift-website-dsl") | ||
} | ||
} | ||
.textAlign(.center) | ||
.color(.lightGray) | ||
} | ||
.font(.apple) | ||
.textAlign(.center) | ||
.margin(0) | ||
.padding(0) | ||
.background( | ||
.linearGradient(.init(degree: 180, first: (.headerTopBlue, 0), second: (.headerBottomBlue, 100))) | ||
) | ||
} | ||
return site.html.render | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import SwiftWebsiteDSL | ||
|
||
// https://rgbacolorpicker.com/rgba-to-hex | ||
extension Color { | ||
static let white = Color(hex: "FFFFFF") | ||
static let lightGray = Color(hex: "F2F2F2") | ||
static let mediumGray = Color(hex: "8a8a8a") | ||
static let darkGray = Color(hex: "333333") | ||
static let headerTopBlue = Color(hex: "459bd0a8") | ||
static let headerBottomBlue = Color(hex: "2F80ED") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Usage: Go to root directory then `swift run` | ||
import Foundation | ||
|
||
let siteDirectory = FileManager.default.currentDirectoryPath + "/_site" | ||
let outputFilePath = siteDirectory + "/index.html" | ||
|
||
print("🛠️ Starting to generate the example website...") | ||
|
||
do { | ||
print("🖍️ Generating HTML...") | ||
let html = renderHtml() // This is a free function from this module | ||
if let data = html.data(using: .utf8) { | ||
try data.write(to: URL(fileURLWithPath: outputFilePath), options: []) | ||
print("🚀 Finished generating site! Output is in: \(siteDirectory)") | ||
} else { | ||
print("❌ Failed to write generated site out to: \(outputFilePath)") | ||
exit(1) | ||
} | ||
} catch { | ||
print("❌ Failed to build and generate site. Error: \(error)") | ||
exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import Foundation | ||
import SnapshotTesting | ||
@testable import SwiftWebsiteDSL | ||
import XCTest | ||
|
||
final class AnyElementTests: XCTestCase { | ||
// MARK: - Styles | ||
|
||
func testWidthStyle() { | ||
// given | ||
let element = AnyElement(element: "fake-element", attrs: [:], copy: "", nodes: []) | ||
.width(789) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testColorStyle() { | ||
// given | ||
let element = AnyElement(element: "fake-element", attrs: [:], copy: "", nodes: []) | ||
.color(.init(hex: "123456")) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testMarginAutoStyle() { | ||
// given | ||
let element = AnyElement(element: "fake-margin-auto-element", attrs: [:], copy: "", nodes: []) | ||
.margin([.leading, .top], .auto) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testBackgroundColor() { | ||
// given | ||
let element = AnyElement(element: "fake-background-color-element", attrs: [:], copy: "", nodes: []) | ||
.background(.color(.init(hex: "123456"))) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testBackgroundLinearGradient() { | ||
// given | ||
let gradient: BackgroundType.LinearGradient = .init( | ||
degree: 77, | ||
first: (.init(hex: "ASDFGH"), 4), | ||
second: (.init(hex: "QWERTY"), 99) | ||
) | ||
|
||
let element = AnyElement(element: "fake-background-linear-gradient-element", attrs: [:], copy: "", nodes: []) | ||
.background(.linearGradient(gradient)) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testBorderRadius() { | ||
// given | ||
let element = AnyElement(element: "fake-border-radius-element", attrs: [:], copy: "", nodes: []) | ||
.borderRadius(px: 16) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testLineHeight() { | ||
// given | ||
let element = AnyElement(element: "fake-line-height-element", attrs: [:], copy: "", nodes: []) | ||
.lineHeight(2.3) | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testMostGeneralStylesWithPElement() { | ||
// given | ||
let element = P("Super cool copy here") | ||
.color(.init(hex: "1234567")) | ||
.margin(0) | ||
.padding([.top], 7) | ||
// .width(13) // TODO: this fails because width for a p element should be in the style section | ||
|
||
// when | ||
let rendered = element.html.render | ||
|
||
// then | ||
assertSnapshot(matching: rendered, as: .lines) | ||
} | ||
|
||
func testCopyIsNotLostWithModifiers() { | ||
// given | ||
let copy = "mic test" | ||
let element = P(copy) | ||
// when | ||
.color(.init(hex: "1234567")) | ||
.margin(1) | ||
.padding([.top], 0) | ||
|
||
switch element.html { | ||
case let .element(tag, attrs: _, copy, _): | ||
// then | ||
XCTAssertEqual(tag, "p") | ||
XCTAssertFalse(copy.isEmpty) | ||
} | ||
} | ||
} |
Oops, something went wrong.