Skip to content

Commit

Permalink
Added an option to drop the value in the r-set tag, defaulting to a f…
Browse files Browse the repository at this point in the history
…lag value
  • Loading branch information
RussBaz committed Mar 25, 2024
1 parent 4849e61 commit d499348
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Here is an example of the `Reparse` syntax as used in the bundled `Example` proj
If you would like to use it in your own project, firstly, add it to your package dependencies like this:

```swift
.package(url: "https://github.com/RussBaz/experimental-reparse-html.git", from: "0.0.12"),
.package(url: "https://github.com/RussBaz/experimental-reparse-html.git", from: "0.0.13"),
```

Then add the `ReparseRuntime` as a dependency to your target like this:
Expand Down
1 change: 1 addition & 0 deletions Resources/Pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h1>
console.log('This is drastic?');
console.log('too many');"
>
<r-set name="disabled" r-if="!context.isEmpty" />
What's up?
</button>
</main>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ extension Parser {
guard tag.isVoid else { ignoringUntilDepth = depth; return }
guard let attributes = tag.attributes else { return }
guard let name = attributes.find("name") else { return }
guard let attributeValue = attributes["value"] else { return }
let attributeValue = attributes["value"] ?? .flag

let appending = if attributes.has("append") { true } else { false }

Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/SwiftOutputBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class SwiftOutputBuilder {
let topLine = """
//
// ------------------------------
// reparse version: 0.0.12
// reparse version: 0.0.13
// ------------------------------
// This is an auto-generated file
// ------------------------------
Expand Down
15 changes: 13 additions & 2 deletions Sources/Example/pages.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// ------------------------------
// reparse version: 0.0.12
// reparse version: 0.0.13
// ------------------------------
// This is an auto-generated file
// ------------------------------
Expand Down Expand Up @@ -276,7 +276,18 @@ enum Pages {
}
lines.append("""
</p>
<button class="button" hx-post="/auth/logout?next=/" hx-target="body" onfocus="console.log('?'); console.log('This is drastic?'); console.log('too many');" data-loading-delay data-loading-disable>
""")
attributes = SwiftAttributeStorage.from(attributes: ["class": .string("button", wrapper: .double), "hx-post": .string("/auth/logout?next=/", wrapper: .double), "hx-target": .string("body", wrapper: .double), "onfocus": .string("console.log('?'); console.log('This is drastic?'); console.log('too many');", wrapper: .double), "data-loading-delay": .flag, "data-loading-disable": .flag])
if !context.isEmpty {
attributes.replace(key: "disabled", with: .flag)
previousUnnamedIfTaken = true
} else {
previousUnnamedIfTaken = false
}
lines.append("<button\(attributes)>")
lines.append("""
What's up?
</button>
</main>
Expand Down

0 comments on commit d499348

Please sign in to comment.