From bbe324ea14b70e9db1dd3d21347c7689452fab64 Mon Sep 17 00:00:00 2001 From: RussBaz Date: Tue, 2 Apr 2024 17:03:43 +0500 Subject: [PATCH] The previous fix did not work. Added a different one. --- README.md | 2 +- Resources/Pages/index.html | 6 ++++-- Sources/Core/SwiftOutputBuilder.swift | 2 +- Sources/Example/pages.swift | 8 ++++++-- Sources/Runtime/SwiftAttributeStorage.swift | 12 ++++++------ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4517205..7a81f19 100644 --- a/README.md +++ b/README.md @@ -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.14"), +.package(url: "https://github.com/RussBaz/experimental-reparse-html.git", from: "0.0.15"), ``` Then add the `ReparseRuntime` as a dependency to your target like this: diff --git a/Resources/Pages/index.html b/Resources/Pages/index.html index b60cca3..5138817 100644 --- a/Resources/Pages/index.html +++ b/Resources/Pages/index.html @@ -41,12 +41,14 @@

data-loading-delay data-loading-disable hx-vals='{"key": "\(key)"}' - on-click="console.log('?')" + disabled='\(context.count < 6 ? "true" : "false" )' + onclick="console.log('?')" onfocus="console.log('?'); console.log('This is drastic?'); console.log('too many');" + > - + What's up? diff --git a/Sources/Core/SwiftOutputBuilder.swift b/Sources/Core/SwiftOutputBuilder.swift index 25f4361..1108566 100644 --- a/Sources/Core/SwiftOutputBuilder.swift +++ b/Sources/Core/SwiftOutputBuilder.swift @@ -49,7 +49,7 @@ public final class SwiftOutputBuilder { let topLine = """ // // ------------------------------ - // reparse version: 0.0.13 + // reparse version: 0.0.15 // ------------------------------ // This is an auto-generated file // ------------------------------ diff --git a/Sources/Example/pages.swift b/Sources/Example/pages.swift index 0de8a68..94be643 100644 --- a/Sources/Example/pages.swift +++ b/Sources/Example/pages.swift @@ -282,9 +282,13 @@ enum Pages {

""") - attributes = SwiftAttributeStorage.from(attributes: ["class": .string("button", wrapper: .double), "hx-post": .string("/auth/logout?next=/", wrapper: .double), "hx-target": .string("body", wrapper: .double), "hx-vals": .string("{\"key\": \"\(key)\"}", wrapper: .single), "on-click": .string("console.log('?')", 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]) + attributes = SwiftAttributeStorage.from(attributes: ["class": .string("button", wrapper: .double), "disabled": .string(""" + \(context.count < 6 ? "true" : "false") + """, wrapper: .single), "hx-post": .string("/auth/logout?next=/", wrapper: .double), "hx-target": .string("body", wrapper: .double), "hx-vals": .string(""" + {"key": "\(key)"} + """, wrapper: .single), "onclick": .string("console.log('?')", 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) + attributes.replace(key: "requried", with: .flag) previousUnnamedIfTaken = true } else { previousUnnamedIfTaken = false diff --git a/Sources/Runtime/SwiftAttributeStorage.swift b/Sources/Runtime/SwiftAttributeStorage.swift index d898fab..5921e50 100644 --- a/Sources/Runtime/SwiftAttributeStorage.swift +++ b/Sources/Runtime/SwiftAttributeStorage.swift @@ -95,11 +95,11 @@ public final class SwiftAttributeStorage { case let .string(v, wrapper): switch wrapper { case .single: - lines.append("\"\(key)\": .string(\"\(v.replacing("\"", with: "\\\""))\", wrapper: .single)") + lines.append("\"\(key)\": .string(\"\"\"\n\(v)\n\"\"\", wrapper: .single)") case .double: - lines.append("\"\(key)\": .string(\"\(v.replacing("\"", with: "\\\""))\", wrapper: .double)") + lines.append("\"\(key)\": .string(\"\(v)\", wrapper: .double)") case .none: - lines.append("\"\(key)\": .string(\"\(v.replacing("\"", with: "\\\""))\", wrapper: .none)") + lines.append("\"\(key)\": .string(\"\(v)\", wrapper: .none)") } } } @@ -149,11 +149,11 @@ public extension SwiftAttributeStorage.AttributeValue { case let .string(string, wrapper): switch wrapper { case .single: - ".string(\"\(string.replacing("\"", with: "\\\""))\", wrapper: .single)" + ".string(\"\"\"\n\(string)\n\"\"\", wrapper: .single)" case .double: - ".string(\"\(string.replacing("\"", with: "\\\""))\", wrapper: .double)" + ".string(\"\(string)\", wrapper: .double)" case .none: - ".string(\"\(string.replacing("\"", with: "\\\""))\", wrapper: .none)" + ".string(\"\(string)\", wrapper: .none)" } } }