Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added http-equip & main HTML Component #99

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/Plot/API/HTMLAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ public extension Attribute where Context == HTML.MetaContext {
static func content(_ content: String) -> Attribute {
Attribute(name: "content", value: content)
}

/// Make use of http-equiv attribute in meta tag
/// - parameter value: see HTTP_Equiv_Valye enum for explanation
static func http_equiv(value: HTTP_Equiv_Value) -> Attribute {
Attribute(name: "http-equiv", value: value.value)
}
}

// MARK: - iFrames
Expand Down
14 changes: 12 additions & 2 deletions Sources/Plot/API/HTMLComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public struct Input: InputComponent {
/// Any placeholder to render within the input element.
public var placeholder: String?
public var isAutoFocused = false
public var checked: Bool

@EnvironmentValue(.isAutoCompleteEnabled) private var isAutoCompleteEnabled

Expand All @@ -466,12 +467,14 @@ public struct Input: InputComponent {
name: String? = nil,
value: String? = nil,
isRequired: Bool = false,
placeholder: String? = nil) {
placeholder: String? = nil,
checked: Bool = false) {
self.type = type
self.name = name
self.value = value
self.isRequired = isRequired
self.placeholder = placeholder
self.checked = checked
}

public var body: Component {
Expand All @@ -482,7 +485,9 @@ public struct Input: InputComponent {
.required(isRequired),
.unwrap(placeholder, Attribute.placeholder),
.autofocus(isAutoFocused),
.checked(checked),
.unwrap(isAutoCompleteEnabled, Attribute.autocomplete)

)
}
}
Expand Down Expand Up @@ -846,6 +851,8 @@ public struct TextArea: InputComponent {
public var isRequired: Bool
/// Whether the browser should auto-focus the text field.
public var isAutoFocused = false
/// Optional Placeholder
public var placeholder : String?

/// Create a new text area.
/// - parameters:
Expand All @@ -860,12 +867,14 @@ public struct TextArea: InputComponent {
name: String? = nil,
numberOfRows: Int? = nil,
numberOfColumns: Int? = nil,
isRequired: Bool = false) {
isRequired: Bool = false,
placeholder: String? = nil) {
self.text = text
self.name = name
self.numberOfRows = numberOfRows
self.numberOfColumns = numberOfColumns
self.isRequired = isRequired
self.placeholder = placeholder
}

public var body: Component {
Expand All @@ -875,6 +884,7 @@ public struct TextArea: InputComponent {
.unwrap(numberOfRows, Node.rows),
.unwrap(numberOfColumns, Node.cols),
.required(isRequired),
.unwrap(placeholder, Node.placeholder),
.unwrap(isAutoFocused, Node.autofocus)
)
}
Expand Down
31 changes: 31 additions & 0 deletions Sources/Plot/API/HTTPEquivValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// File.swift
//
//
// Created by Klaus Kneupner on 13/05/2023.
//

import Foundation

/// The http-equiv attribute is used within the <meta> tag, part of the <head> part of HTML
/// /// see for example: https://www.w3schools.com/tags/att_meta_http_equiv.asp
///
public enum HTTP_Equiv_Value {
/// Specifies a content policy for the document.
case contentSecurityPolicy
/// Specifies the character encoding for the document./
case contentType
/// Specified the preferred style sheet to use./
case defaultStyle
/// Defines a time interval for the document to refresh itself./
case refresh

public var value: String {
switch self {
case .contentSecurityPolicy: return "content-security-policy"
case .contentType: return "content-type"
case .defaultStyle: return "default-style"
case .refresh: return "refresh"
}
}
}
11 changes: 10 additions & 1 deletion Tests/PlotTests/HTMLComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,16 @@ final class HTMLComponentTests: XCTestCase {
</body>
""")
}


func testTextAreaPlaceholder() {
let html = TextArea(placeholder: "testplaceholder").render()
XCTAssertEqual(html, "<textarea placeholder=\"testplaceholder\"></textarea>")

let html2 = TextArea().render()
XCTAssertEqual(html2, "<textarea></textarea>")
}


func testForm() {
let html = Form(
url: "url.com",
Expand Down