Skip to content

Commit

Permalink
Upgrade the package (#136)
Browse files Browse the repository at this point in the history
* Start to add conditional attributes

* Revise the rendering of attributes

The renderer should also take an environment value as attribute value into account.

* Add support for concating environment values with string and vice versa
  • Loading branch information
mattesmohr authored Jul 10, 2023
1 parent 8f253e7 commit 228a2e0
Show file tree
Hide file tree
Showing 21 changed files with 1,515 additions and 496 deletions.
22 changes: 22 additions & 0 deletions Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public protocol AutoplayAttribute: Attribute {
/// <tag autoplay />
/// ```
func autoplay() -> Self

func autoplay(_ condition: Bool) -> Self
}

extension AutoplayAttribute where Self: ContentNode {
Expand Down Expand Up @@ -273,6 +275,8 @@ public protocol CheckedAttribute: Attribute {
/// <tag checked />
/// ```
func checked() -> Self

func checked(_ condition: Bool) -> Self
}

extension CheckedAttribute where Self: ContentNode {
Expand Down Expand Up @@ -625,6 +629,8 @@ public protocol DisabledAttribute: Attribute {
/// <tag disabled />
/// ```
func disabled() -> Self

func disabled(_ condition: Bool) -> Self
}

extension DisabledAttribute where Self: ContentNode {
Expand Down Expand Up @@ -914,6 +920,8 @@ public protocol HiddenAttribute: Attribute {
/// <tag hidden />
/// ```
func hidden() -> Self

func hidden(_ condition: Bool) -> Self
}

extension HiddenAttribute where Self: ContentNode {
Expand Down Expand Up @@ -1878,6 +1886,8 @@ public protocol ReadyOnlyAttribute: Attribute {
/// <tag readonly />
/// ```
func readonly() -> Self

func readonly(_ condition: Bool) -> Self
}

extension ReadyOnlyAttribute where Self: ContentNode {
Expand Down Expand Up @@ -1953,6 +1963,8 @@ public protocol RequiredAttribute: Attribute {
/// <tag required />
/// ```
func required() -> Self

func required(_ condition: Bool) -> Self
}

extension RequiredAttribute where Self: ContentNode {
Expand Down Expand Up @@ -2278,20 +2290,30 @@ public protocol SourceAttribute: Attribute {
/// <tag src="" />
/// ```
func source(_ value: String) -> Self

func source(_ value: EnvironmentValue) -> Self
}

extension SourceAttribute where Self: ContentNode {

internal func mutate(source value: String) -> Self {
return self.mutate(key: "src", value: value)
}

internal func mutate(source value: EnvironmentValue) -> Self {
return self.mutate(key: "src", value: value)
}
}

extension SourceAttribute where Self: EmptyNode {

internal func mutate(source value: String) -> Self {
return self.mutate(key: "src", value: value)
}

internal func mutate(source value: EnvironmentValue) -> Self {
return self.mutate(key: "src", value: value)
}
}

/// The protocol provides the element with the start handler.
Expand Down
9 changes: 9 additions & 0 deletions Sources/HTMLKit/Abstraction/Elements/BasicElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
public func hidden() -> Html {
return mutate(hidden: "hidden")
}

public func hidden(_ condition: Bool) -> Html {

if condition {
return mutate(hidden: "hidden")
}

return self
}

public func inputMode(_ value: String) -> Html {
return mutate(inputmode: value)
Expand Down
Loading

0 comments on commit 228a2e0

Please sign in to comment.