Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from jumpper/feature/CompositeElements
Browse files Browse the repository at this point in the history
Add Composite Elements, Factory Texts and new UnitTests
  • Loading branch information
micheltlutz authored Dec 22, 2020
2 parents 35a1882 + e4db130 commit 5c448b4
Show file tree
Hide file tree
Showing 143 changed files with 2,973 additions and 778 deletions.
94 changes: 94 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/jumpper.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "jumpper"
BuildableName = "jumpper"
BlueprintName = "jumpper"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "jumpperTests"
BuildableName = "jumpperTests"
BlueprintName = "jumpperTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
enableThreadSanitizer = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "jumpperTests"
BuildableName = "jumpperTests"
BlueprintName = "jumpperTests"
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">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "jumpper"
BuildableName = "jumpper"
BlueprintName = "jumpper"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 1 addition & 7 deletions Sources/jumpper/HTML/Base/ContainerElementBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ContainerElementBase: GenericElement {
/// - Parameter element: Generic Type `ElementProtocol` or `String`
public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)
let text = FactoryElements.textWith(textElement)

objects.append(text)
} else {
Expand All @@ -28,10 +28,4 @@ public class ContainerElementBase: GenericElement {
objects.append(genericElement)
}
}
/// This method create a `Text` element to user when element T String is passed on add method
/// - Parameter text: `String` to create `Text` element
/// - Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
4 changes: 2 additions & 2 deletions Sources/jumpper/HTML/Base/GenericElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public class GenericElement: ElementProtocol {

if objects.count > 0 {
for obj in objects {
code += obj.getString()
code.append(obj.getString())
}
}

if container {
code += closeTag()
code.append(closeTag())
}

return code
Expand Down
9 changes: 1 addition & 8 deletions Sources/jumpper/HTML/Base/TableColumnBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TableColumnBase: GenericElement {
/// Parameter element: Generic Type `ElementProtocol` or `String`
public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)
let text = FactoryElements.textWith(textElement)

objects.append(text)
} else {
Expand All @@ -45,11 +45,4 @@ public class TableColumnBase: GenericElement {
objects.append(genericElement)
}
}

/// This method create a `Text` element to user when element T String is passed on add method
/// Parameter text: `String` to create `Text` element
/// Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
9 changes: 1 addition & 8 deletions Sources/jumpper/HTML/Base/TypographyElementBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class TypographyElementBase: GenericElement {
/// - Parameter element: Generic Type `ElementProtocol` or `String`
public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)
let text = FactoryElements.textWith(textElement)

objects.append(text)
} else {
Expand All @@ -53,11 +53,4 @@ public class TypographyElementBase: GenericElement {
objects.append(genericElement)
}
}

/// This method create a `Text` element to user when element T String is passed on add method
/// - Parameter text: `String` to create `Text` element
/// - Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
9 changes: 1 addition & 8 deletions Sources/jumpper/HTML/Elements/Lists/LI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class LI: GenericElement {
public init<T>(_ element: T) {
super.init()
if let textElement = element as? String {
let text = factoryTextWith(textElement)
let text = FactoryElements.textWith(textElement)

objects.append(text)
} else {
Expand All @@ -53,11 +53,4 @@ public class LI: GenericElement {
objects.append(genericElement)
}
}

/// This method create a `Text` element to user when element T String is passed on add method
/// - Parameter text: `String` to create `Text` element
/// - Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
65 changes: 65 additions & 0 deletions Sources/jumpper/HTML/Helpers/CompositeElements.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// MIT License
//
// Copyright (c) 2020 micheltlutz
//
// 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.
//

import Foundation

public final class CompositeElements: ElementProtocol {
public var objects: [ElementProtocol] = [ElementProtocol]()

///This method append a new element in objects list
/// - Parameter element: Generic Type `ElementProtocol` or `String`
public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = FactoryElements.textWith(textElement)

objects.append(text)
} else {
guard let genericElement = element as? ElementProtocol else { return }

objects.append(genericElement)
}
}

/// This method return tag and all elements
/// - Returns: `String` tag and all elements
public func getString() -> String {
var code = ""
if objects.count > 0 {
for obj in objects {
code.append(obj.getString())
}
}

return code
}

/// This method print tag and all elements
public func generate() {
if objects.count > 0 {
for obj in objects {
obj.generate()
}
}
}
}
34 changes: 34 additions & 0 deletions Sources/jumpper/HTML/Helpers/FactoryElements.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// MIT License
//
// Copyright (c) 2020 micheltlutz
//
// 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.
//

import Foundation

public struct FactoryElements {
// This method create a `Text` element to user when element T String is passed on add method
/// - Parameter text: `String` to create `Text` element
/// - Returns: `Text` Element with string passed
public static func textWith(_ text: String) -> Text {
return Text(text)
}
}
2 changes: 1 addition & 1 deletion Sources/jumpper/jumpper.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
struct jumpper {
var version = "1.0.0 alpha"
var version = "0.0.6"
}
4 changes: 4 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import LabelTests
import MainTests
import PreTests
import PTests
import CompositeElementsTests
import FactoryElementsTests

var tests = [XCTestCaseEntry]()
tests += DivTests.allTests()
Expand All @@ -44,4 +46,6 @@ tests += PreTests.allTests()
tests += PTests.allTests()
tests += SectionTest.allTests()
tests += TextTest.allTests()
tests += CompositeElementsTests.allTests()
tests += FactoryElementsTests.allTests()
XCTMain(tests)
16 changes: 16 additions & 0 deletions Tests/jumpperTests/CompositeElementsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import XCTest
@testable import jumpper

final class CompositeElementsTests: XCTestCase {
func testElement() {
let element = CompositeElements()
element.add("Hello, World!")
element.add(Label("My Label"))

XCTAssertEqual(element.getString(), "Hello, World!<label>My Label</label>")
}

static var allTests = [
("testElement", testElement)
]
}
14 changes: 14 additions & 0 deletions Tests/jumpperTests/FactoryElementsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import XCTest
@testable import jumpper

final class FactoryElementsTests: XCTestCase {
func testElement() {
let element = FactoryElements.textWith("Hello, World!")

XCTAssertEqual(element.getString(), "Hello, World!")
}

static var allTests = [
("testElement", testElement)
]
}
4 changes: 3 additions & 1 deletion Tests/jumpperTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public func allTests() -> [XCTestCaseEntry] {
testCase(PreTests.allTests),
testCase(PTests.allTests),
testCase(SectionTests.allTests),
testCase(TextTests.allTests)
testCase(TextTests.allTests),
testCase(CompositeElementsTests.allTests),
testCase(FactoryElementsTests.allTests)
]
}
#endif
Loading

0 comments on commit 5c448b4

Please sign in to comment.