Compare commits
2 Commits
main
..
b4427ad9dd
| Author | SHA1 | Date | |
|---|---|---|---|
|
b4427ad9dd
|
|||
|
a00774ebfe
|
+2
-4
@@ -23,15 +23,13 @@ let package = Package(
|
||||
.plugin(name: "BindingPlugin", targets: ["BindingPlugin"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "/Users/isaacpaul/Projects/swift-projects/GenHTML5"),
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
|
||||
.package(url: "https://github.com/apple/swift-system.git", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "HRW",
|
||||
dependencies: [
|
||||
.product(name: "SystemPackage", package: "swift-system"),
|
||||
]
|
||||
dependencies: [ ]
|
||||
),
|
||||
.executableTarget(name: "BindingGenerator", dependencies: [
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser")
|
||||
|
||||
@@ -54,6 +54,7 @@ extension BindingPlugin: BuildToolPlugin {
|
||||
#if canImport(XcodeProjectPlugin)
|
||||
|
||||
import XcodeProjectPlugin
|
||||
import System
|
||||
|
||||
// The entry point for Xcode project builds.
|
||||
extension BindingPlugin: XcodeBuildToolPlugin {
|
||||
@@ -149,21 +150,14 @@ struct BindingPlugin {
|
||||
let withoutExt = String(fileName[fileName.startIndex..<extIndex])
|
||||
let targetFileName = "\(withoutExt.uppercaseFirstLetter()).swift"
|
||||
|
||||
let rootPathP = Path(rootPath.path)
|
||||
let fileDirP = Path(eachFile.deletingLastPathComponent().path)
|
||||
let relativeDir: String
|
||||
let baseDir = rootPathP.string.hasSuffix("/") ? rootPathP.string : rootPathP.string + "/"
|
||||
if fileDirP.string == rootPathP.string {
|
||||
relativeDir = ""
|
||||
} else if fileDirP.string.hasPrefix(baseDir) {
|
||||
relativeDir = String(fileDirP.string.dropFirst(baseDir.count))
|
||||
} else {
|
||||
relativeDir = ""
|
||||
}
|
||||
let rootFP = FilePath(rootPath.path)
|
||||
var inputFP = FilePath(eachFile.path)
|
||||
let outputDirFP = FilePath(outputDir.path)
|
||||
|
||||
let outputFileA = relativeDir.isEmpty
|
||||
? outputDir
|
||||
: outputDir.appendingPathComponent(relativeDir)
|
||||
let _ = inputFP.removePrefix(rootFP)
|
||||
inputFP.removeLastComponent()
|
||||
//let idk = outputDirFP.pushing(inputFP)
|
||||
let outputFileA = outputDir.appendingPathComponent(inputFP.string)
|
||||
let outputFile = outputFileA.appendingPathComponent(targetFileName)
|
||||
print("Expected path: \(outputFile.path)")
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ public protocol IGlobalContainer {
|
||||
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
||||
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
||||
var dataAttributes:Dictionary<String, String> { get set }
|
||||
var ariaAttributes:Dictionary<String, String> { get set }
|
||||
}
|
||||
|
||||
extension IGlobalContainer {
|
||||
@@ -30,10 +29,6 @@ extension IGlobalContainer {
|
||||
dataAttributes[key] = value
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
ariaAttributes[key] = value
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -58,27 +53,23 @@ public struct GlobalAttributesBuilder : IGlobalContainer{
|
||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||
public var dataAttributes:Dictionary<String, String> = [:]
|
||||
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||
|
||||
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>, ariaAttributes: Dictionary<String, String> = [:]) {
|
||||
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>) {
|
||||
self.globalAttributes = globalAttributes
|
||||
self.globalEvents = globalEvents
|
||||
self.dataAttributes = dataAttributes
|
||||
self.ariaAttributes = ariaAttributes
|
||||
}
|
||||
|
||||
public init() {
|
||||
self.globalAttributes = [:]
|
||||
self.globalEvents = [:]
|
||||
self.dataAttributes = [:]
|
||||
self.ariaAttributes = [:]
|
||||
}
|
||||
|
||||
public init(_ attributes: [String: String]) throws {
|
||||
self.globalAttributes = [:]
|
||||
self.globalEvents = [:]
|
||||
self.dataAttributes = [:]
|
||||
self.ariaAttributes = [:]
|
||||
for (key, value) in attributes {
|
||||
if self.trySetGlobalAttribute(key, value) {
|
||||
continue
|
||||
@@ -110,7 +101,6 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
|
||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||
|
||||
public var children:[HTMLNode] = []
|
||||
|
||||
@@ -125,31 +115,23 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
globalEvents[attr] = value
|
||||
continue
|
||||
}
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
dataAttributes[key] = value
|
||||
continue
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
ariaAttributes[key] = value
|
||||
continue
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>, ariaAttributes:Dictionary<String, String> = [:]) {
|
||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>) {
|
||||
self.globalAttributes = globalAttributes
|
||||
self.globalEvents = globalEvents
|
||||
self.ariaAttributes = ariaAttributes
|
||||
super.init(dataAttributes: dataAttributes)
|
||||
}
|
||||
|
||||
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
||||
self.globalAttributes = builder.globalAttributes
|
||||
self.globalEvents = builder.globalEvents
|
||||
self.ariaAttributes = builder.ariaAttributes
|
||||
self.children = children
|
||||
super.init(dataAttributes: builder.dataAttributes)
|
||||
}
|
||||
@@ -232,18 +214,6 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
}
|
||||
}
|
||||
|
||||
for eachAttr in ariaAttributes {
|
||||
if (!first) {
|
||||
result += " "
|
||||
}
|
||||
first = false
|
||||
if (eachAttr.value.count > 0) {
|
||||
result += "\(eachAttr.key)='\(eachAttr.value)'"
|
||||
} else {
|
||||
result += "\(eachAttr.key)"
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -399,14 +369,9 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool {
|
||||
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
||||
return true
|
||||
}
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,9 @@ struct HtmlElement {
|
||||
|
||||
struct StandardError: TextOutputStream {
|
||||
mutating func write(_ string: String) {
|
||||
FileHandle.standardError.write(Foundation.Data(string.utf8))
|
||||
for byte in string.utf8 { putc(numericCast(byte), stderr) }
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated(unsafe) var standardError: StandardError = StandardError()
|
||||
|
||||
extension String {
|
||||
@@ -328,9 +327,10 @@ struct CLI {
|
||||
|
||||
let cmdLinArgs = CommandLine.arguments.dropFirst()
|
||||
|
||||
var args: [String] = Array(cmdLinArgs)
|
||||
#if DEBUG
|
||||
var args:[String] = Array(cmdLinArgs)
|
||||
args.append(contentsOf: ["-r"])
|
||||
#else
|
||||
#endif
|
||||
|
||||
await Process.main(args)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Non-commercial license, see LICENSE.MD in the project root for details
|
||||
//
|
||||
|
||||
import SystemPackage
|
||||
import System
|
||||
import Foundation
|
||||
|
||||
public protocol IFlowContent : HTMLNode {}
|
||||
@@ -15,7 +15,6 @@ public protocol IGlobalContainer {
|
||||
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
||||
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
||||
var dataAttributes:Dictionary<String, String> { get set }
|
||||
var ariaAttributes:Dictionary<String, String> { get set }
|
||||
}
|
||||
|
||||
extension IGlobalContainer {
|
||||
@@ -28,16 +27,10 @@ extension IGlobalContainer {
|
||||
globalEvents[attr] = value
|
||||
return true
|
||||
}
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
dataAttributes[key] = value
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
ariaAttributes[key] = value
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -61,27 +54,23 @@ public struct GlobalAttributesBuilder : IGlobalContainer{
|
||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||
public var dataAttributes:Dictionary<String, String> = [:]
|
||||
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||
|
||||
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>, ariaAttributes: Dictionary<String, String> = [:]) {
|
||||
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>) {
|
||||
self.globalAttributes = globalAttributes
|
||||
self.globalEvents = globalEvents
|
||||
self.dataAttributes = dataAttributes
|
||||
self.ariaAttributes = ariaAttributes
|
||||
}
|
||||
|
||||
public init() {
|
||||
self.globalAttributes = [:]
|
||||
self.globalEvents = [:]
|
||||
self.dataAttributes = [:]
|
||||
self.ariaAttributes = [:]
|
||||
}
|
||||
|
||||
public init(_ attributes: [String: String]) throws {
|
||||
self.globalAttributes = [:]
|
||||
self.globalEvents = [:]
|
||||
self.dataAttributes = [:]
|
||||
self.ariaAttributes = [:]
|
||||
for (key, value) in attributes {
|
||||
if self.trySetGlobalAttribute(key, value) {
|
||||
continue
|
||||
@@ -147,7 +136,6 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
|
||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||
|
||||
public var children:[HTMLNode] = []
|
||||
|
||||
@@ -162,31 +150,23 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
globalEvents[attr] = value
|
||||
continue
|
||||
}
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
dataAttributes[key] = value
|
||||
continue
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
ariaAttributes[key] = value
|
||||
continue
|
||||
}
|
||||
}
|
||||
throw AppError("Unexpected attribute: \(key)")
|
||||
}
|
||||
}
|
||||
|
||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>, ariaAttributes:Dictionary<String, String> = [:]) {
|
||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>) {
|
||||
self.globalAttributes = globalAttributes
|
||||
self.globalEvents = globalEvents
|
||||
self.ariaAttributes = ariaAttributes
|
||||
super.init(dataAttributes: dataAttributes)
|
||||
}
|
||||
|
||||
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
||||
self.globalAttributes = builder.globalAttributes
|
||||
self.globalEvents = builder.globalEvents
|
||||
self.ariaAttributes = builder.ariaAttributes
|
||||
self.children = children
|
||||
super.init(dataAttributes: builder.dataAttributes)
|
||||
}
|
||||
@@ -249,9 +229,9 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
}
|
||||
first = false
|
||||
if (eachAttr.value.count > 0) {
|
||||
result += "\(eachAttr.key.rawValue)='\(eachAttr.value)'"
|
||||
result += "\(eachAttr.key)='\(eachAttr.value)'"
|
||||
} else {
|
||||
result += "\(eachAttr.key.rawValue)"
|
||||
result += "\(eachAttr.key)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,19 +241,7 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
}
|
||||
first = false
|
||||
if (eachAttr.value.count > 0) {
|
||||
result += "\(eachAttr.key.rawValue) = \(eachAttr.value)"
|
||||
} else {
|
||||
result += "\(eachAttr.key.rawValue)"
|
||||
}
|
||||
}
|
||||
|
||||
for eachAttr in ariaAttributes {
|
||||
if (!first) {
|
||||
result += " "
|
||||
}
|
||||
first = false
|
||||
if (eachAttr.value.count > 0) {
|
||||
result += "\(eachAttr.key)='\(eachAttr.value)'"
|
||||
result += "\(eachAttr.key) = \(eachAttr.value)"
|
||||
} else {
|
||||
result += "\(eachAttr.key)"
|
||||
}
|
||||
@@ -434,14 +402,9 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool {
|
||||
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
||||
return true
|
||||
}
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -465,3 +428,4 @@ public class NHTMLParent : NHTMLRenderable {
|
||||
return nil
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
@@ -82,15 +82,6 @@ final class HRWTests: XCTestCase {
|
||||
print(htmlRoot.toString())
|
||||
}
|
||||
|
||||
func testAriaAttributesAreGlobal() throws {
|
||||
guard let xmlReader = XMLParser(str: #"<span aria-hidden="true">Hidden</span>"#) else { throw EmptyStringError() }
|
||||
let rootNodes = try xmlReader.readObjects()
|
||||
let span = rootNodes[0] as! Span
|
||||
|
||||
XCTAssertEqual(span.ariaAttributes["aria-hidden"], "true")
|
||||
XCTAssertTrue(span.renderAttributes().contains("aria-hidden='true'"))
|
||||
}
|
||||
|
||||
func testBindingGenerator() throws {
|
||||
IHtmlNodeContainerUtility.sharedInstance.defaultBaseDir = "/Users/isaacpaul/Projects/swift-projects/HRW/Tests/HRWTests"
|
||||
let idk = try Example()
|
||||
|
||||
Reference in New Issue
Block a user