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 #15 from micheltlutz-compass/feature/radio
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltlutz authored Aug 16, 2022
2 parents 460568c + 0faff70 commit 45e0249
Show file tree
Hide file tree
Showing 175 changed files with 2,963 additions and 2,130 deletions.
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,78 @@ I hope it will be useful for more developers.

- [Online Doc](http://jumpper-docs.micheltlutz.me)

# Using in Package.swift

```swift
// swift-tools-version:5.6
import PackageDescription

let package = Package(
name: "assessment",
platforms: [
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/jumpper/jumpper.git", from: "0.0.9")
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "jumpper", package: "jumpper")
]
),
.executableTarget(name: "Run", dependencies: [.target(name: "App")]),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)
```

# Vapor usage

> Need Leaf installed
## Need Leaf installed

```swift
import jumpper
import Leaf
import Vapor

router.get { req -> Future<View> in
let div = Div()
div.add("My first div with jumpper")
return try req.view().render("base", ["title": "Hello jumpper", "body": div.getString()])
}
```

## Without Leaf

```swift
import jumpper
import Vapor


protocol JumpperPageProtocol {
func render() throws -> EventLoopFuture<Response>
}

public final class IndexPage: JumpperPageProtocol {
// MARK: - Render

public func render() throws -> EventLoopFuture<Response> {
let response = Response()

let divC = Div()
response.body = .init(string: divC.getString())
return response.encodeResponse(status: .ok, headers: HTTPHeaders.init([("Content-Type", "text/html; charset=UTF-8")]), for: request)
}
}
```

# jumpper vapor project demo

- [jumpper-demo](https://github.com/jumpper/jumpper-demo)
Expand Down
8 changes: 4 additions & 4 deletions Sources/jumpper/HTML/Tags/Inputs/InputText.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2020 micheltlutz
// Copyright (c) 2022 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
Expand Down Expand Up @@ -36,9 +36,9 @@ public final class InputText: InputElementBase {
// MARK: - Initialization
/// Default initializer input text element
/// - Parameters:
/// - value: This is a value for checkbox **value** `String`
/// - id: This is a id for checkbox **id** `String?`
/// - placeholder: This is a placeholder for checkbox **placeholder** `String?`
/// - value: This is a value for input **value** `String`
/// - id: This is a id for input **id** `String?`
/// - placeholder: This is a placeholder for input **placeholder** `String?`
public init(_ value: String, id: String?, placeholder: String?) {
super.init(value, type: "text")

Expand Down
53 changes: 53 additions & 0 deletions Sources/jumpper/HTML/Tags/Inputs/Radio.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// MIT License
//
// Copyright (c) 2022 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

/**
Class define a input type text

### Usage Example: ###
````
Radio("value", id: "nameField", name: "Name")
````
*/
public final class Radio: InputElementBase {
// MARK: - Initialization
/// Default initializer input radio element
/// - Parameters:
/// - value: This is a value for radio **value** `String`
/// - id: This is a id for radio **id** `String?`
/// - name: This is a name for name **name** `String?`
public init(_ value: String, id: String?, name: String?) {
super.init(value, type: "radio")

if let id = id {
addAttribute(("id", id))
}

if let name = name {
addAttribute(("name", name))
}
}
}
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 = "0.0.6"
var version = "0.0.9"
}
2 changes: 2 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import ScriptTests
import TitleTests
import HeaderTests
import FooterTests
import RadioTests

var tests = [XCTestCaseEntry]()
tests += DivTests.allTests()
Expand Down Expand Up @@ -68,5 +69,6 @@ tests += ScriptTests.allTests()
tests += TitleTests.allTests()
tests += HeaderTests.allTests()
tests += FooterTests.allTests()
tests += RadioTests.allTests()

XCTMain(tests)
22 changes: 22 additions & 0 deletions Tests/jumpperTests/RadioTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import XCTest
@testable import jumpper

final class RadioTests: XCTestCase {
func testElement() {
let radio = Radio("option1", id: "option1", name: "option1")

XCTAssertEqual(radio.getString(), "<input value='option1' type='radio' id='option1' name='option1'>")
}

func testElementAttr() {
let radio = Radio("option1", id: "option1", name: "option1")
radio.addAttribute(("class", "button button-outline") )

XCTAssertEqual(radio.getString(), "<input value='option1' type='radio' id='option1' name='option1' class='button button-outline'>")
}

static var allTests = [
("testElement", testElement),
("testElementAttr", testElementAttr)
]
}
3 changes: 2 additions & 1 deletion Tests/jumpperTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public func allTests() -> [XCTestCaseEntry] {
testCase(ScriptTests.allTests),
testCase(TitleTests.allTests),
testCase(HeaderTests.allTests),
testCase(FooterTests.allTests)
testCase(FooterTests.allTests),
testCase(RadioTests.allTests)
]
}
#endif
62 changes: 47 additions & 15 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
<a title="Classes Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html"> Docs</a> (96% documented)</p>
<p class="header-right">
<p><a href="index.html"> Docs</a> (100% documented)</p>
<div class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>
</div>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html"> Reference</a>
<img id="carat" src="img/carat.png" />
<img id="carat" src="img/carat.png" alt=""/>
Classes Reference
</p>
</div>
Expand Down Expand Up @@ -173,6 +173,9 @@
<li class="nav-group-task">
<a href="Classes/Pre.html">Pre</a>
</li>
<li class="nav-group-task">
<a href="Classes/Radio.html">Radio</a>
</li>
<li class="nav-group-task">
<a href="Classes/Script.html">Script</a>
</li>
Expand Down Expand Up @@ -486,8 +489,7 @@ <h4>Declaration</h4>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Undocumented</p>


<a href="Classes/CompositeElements.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
Expand Down Expand Up @@ -1214,7 +1216,7 @@ <h4>Declaration</h4>
<a name="//apple_ref/swift/Section/H1" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/H1"></a>
<h3 class="section-name"><p>H1</p>
<h3 class="section-name"><span>H1</span>
</h3>
</div>
</div>
Expand Down Expand Up @@ -1259,7 +1261,7 @@ <h4>Declaration</h4>
<a name="//apple_ref/swift/Section/H2" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/H2"></a>
<h3 class="section-name"><p>H2</p>
<h3 class="section-name"><span>H2</span>
</h3>
</div>
</div>
Expand Down Expand Up @@ -1304,7 +1306,7 @@ <h4>Declaration</h4>
<a name="//apple_ref/swift/Section/H3" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/H3"></a>
<h3 class="section-name"><p>H3</p>
<h3 class="section-name"><span>H3</span>
</h3>
</div>
</div>
Expand Down Expand Up @@ -1349,7 +1351,7 @@ <h4>Declaration</h4>
<a name="//apple_ref/swift/Section/H4" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/H4"></a>
<h3 class="section-name"><p>H4</p>
<h3 class="section-name"><span>H4</span>
</h3>
</div>
</div>
Expand Down Expand Up @@ -1394,7 +1396,7 @@ <h4>Declaration</h4>
<a name="//apple_ref/swift/Section/H5" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/H5"></a>
<h3 class="section-name"><p>H5</p>
<h3 class="section-name"><span>H5</span>
</h3>
</div>
</div>
Expand Down Expand Up @@ -1439,7 +1441,7 @@ <h4>Declaration</h4>
<a name="//apple_ref/swift/Section/H6" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/H6"></a>
<h3 class="section-name"><p>H6</p>
<h3 class="section-name"><span>H6</span>
</h3>
</div>
</div>
Expand Down Expand Up @@ -1664,6 +1666,37 @@ <h4>Declaration</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:7jumpper5RadioC"></a>
<a name="//apple_ref/swift/Class/Radio" class="dashAnchor"></a>
<a class="token" href="#/s:7jumpper5RadioC">Radio</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Class define a input type text</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>
<pre class="highlight swift"><code><span class="kt">Radio</span><span class="p">(</span><span class="s">"value"</span><span class="p">,</span> <span class="nv">id</span><span class="p">:</span> <span class="s">"nameField"</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Name"</span><span class="p">)</span>
</code></pre>

<a href="Classes/Radio.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">final</span> <span class="kd">class</span> <span class="kt">Radio</span> <span class="p">:</span> <span class="kt"><a href="Classes/InputElementBase.html">InputElementBase</a></span></code></pre>

</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -2435,11 +2468,10 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2021-04-06)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
<p>&copy; 2022 <a class="link" href="" target="_blank" rel="external noopener"></a>. All rights reserved. (Last updated: 2022-08-16)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>
Loading

0 comments on commit 45e0249

Please sign in to comment.