Moved BindingGenerator from gen html project. It makes more sense here.

This commit is contained in:
2025-10-25 00:06:22 -04:00
parent 58a8419984
commit 603a0aa0e3
141 changed files with 12738 additions and 7 deletions

View File

@@ -6,6 +6,9 @@
// Non-commercial license, see LICENSE.MD in the project root for details
//
import System
import Foundation
public protocol IFlowContent : HTMLNode {}
public protocol IGlobalContainer {
@@ -96,6 +99,39 @@ public struct HtmlIterator : IteratorProtocol {
}
}*/
public protocol IHtmlNodeContainer {
var rootNodeGeneric: HTMLNode { get }
}
public class IHtmlNodeContainerUtility {
nonisolated(unsafe) public static let sharedInstance = IHtmlNodeContainerUtility()
public var defaultBaseDir = ""
public static func readHtmlFromFile(_ baseDir:String? = nil, _ fileName:String) throws -> [HTMLNode] {
let dir = baseDir ?? sharedInstance.defaultBaseDir
let strFp = "file://\(dir)/\(fileName)"
guard let url = URL(string:strFp) else {
throw AppError("String not valid url: \(strFp)")
}
let data = try Foundation.Data(contentsOf: url)
guard let str = String(data: data, encoding: .utf8) else {
throw AppError("Data not utf8")
}
/*
let fp = FilePath("\(strFp)")
guard let str = String(validating: fp) else {
throw AppError("File not found at path: \(strFp)")
}
if str == strFp {
throw AppError("File not found at path: \(str)")
}*/
guard let xmlReader = XMLParser(str: str) else { throw AppError("Empty String") }
let rootNodes = try xmlReader.readObjects()
return rootNodes
}
}
public class HTMLNode : XMLNode, IGlobalContainer {
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
@@ -231,7 +267,7 @@ public class HTMLNode : XMLNode, IGlobalContainer {
newDepth = nextDepth
result += renderedChild
}
result += "<\(nodeName)/>"
result += "</\(nodeName)>"
}
return (newDepth, result)
}