Bug fixes, aria, cross platform support.
This commit is contained in:
@@ -54,7 +54,6 @@ extension BindingPlugin: BuildToolPlugin {
|
|||||||
#if canImport(XcodeProjectPlugin)
|
#if canImport(XcodeProjectPlugin)
|
||||||
|
|
||||||
import XcodeProjectPlugin
|
import XcodeProjectPlugin
|
||||||
import System
|
|
||||||
|
|
||||||
// The entry point for Xcode project builds.
|
// The entry point for Xcode project builds.
|
||||||
extension BindingPlugin: XcodeBuildToolPlugin {
|
extension BindingPlugin: XcodeBuildToolPlugin {
|
||||||
@@ -149,15 +148,22 @@ struct BindingPlugin {
|
|||||||
let extIndex = fileName.index(fileName.startIndex, offsetBy: fileName.count - (ext.count + 1))
|
let extIndex = fileName.index(fileName.startIndex, offsetBy: fileName.count - (ext.count + 1))
|
||||||
let withoutExt = String(fileName[fileName.startIndex..<extIndex])
|
let withoutExt = String(fileName[fileName.startIndex..<extIndex])
|
||||||
let targetFileName = "\(withoutExt.uppercaseFirstLetter()).swift"
|
let targetFileName = "\(withoutExt.uppercaseFirstLetter()).swift"
|
||||||
|
|
||||||
let rootFP = FilePath(rootPath.path)
|
let rootPathP = Path(rootPath.path)
|
||||||
var inputFP = FilePath(eachFile.path)
|
let fileDirP = Path(eachFile.deletingLastPathComponent().path)
|
||||||
let outputDirFP = FilePath(outputDir.path)
|
let relativeDir: String
|
||||||
|
let baseDir = rootPathP.string.hasSuffix("/") ? rootPathP.string : rootPathP.string + "/"
|
||||||
let _ = inputFP.removePrefix(rootFP)
|
if fileDirP.string == rootPathP.string {
|
||||||
inputFP.removeLastComponent()
|
relativeDir = ""
|
||||||
//let idk = outputDirFP.pushing(inputFP)
|
} else if fileDirP.string.hasPrefix(baseDir) {
|
||||||
let outputFileA = outputDir.appendingPathComponent(inputFP.string)
|
relativeDir = String(fileDirP.string.dropFirst(baseDir.count))
|
||||||
|
} else {
|
||||||
|
relativeDir = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
let outputFileA = relativeDir.isEmpty
|
||||||
|
? outputDir
|
||||||
|
: outputDir.appendingPathComponent(relativeDir)
|
||||||
let outputFile = outputFileA.appendingPathComponent(targetFileName)
|
let outputFile = outputFileA.appendingPathComponent(targetFileName)
|
||||||
print("Expected path: \(outputFile.path)")
|
print("Expected path: \(outputFile.path)")
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public protocol IGlobalContainer {
|
|||||||
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
||||||
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
||||||
var dataAttributes:Dictionary<String, String> { get set }
|
var dataAttributes:Dictionary<String, String> { get set }
|
||||||
|
var ariaAttributes:Dictionary<String, String> { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IGlobalContainer {
|
extension IGlobalContainer {
|
||||||
@@ -29,6 +30,10 @@ extension IGlobalContainer {
|
|||||||
dataAttributes[key] = value
|
dataAttributes[key] = value
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||||
|
ariaAttributes[key] = value
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -53,23 +58,27 @@ public struct GlobalAttributesBuilder : IGlobalContainer{
|
|||||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||||
public var dataAttributes:Dictionary<String, 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>) {
|
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>, ariaAttributes: Dictionary<String, String> = [:]) {
|
||||||
self.globalAttributes = globalAttributes
|
self.globalAttributes = globalAttributes
|
||||||
self.globalEvents = globalEvents
|
self.globalEvents = globalEvents
|
||||||
self.dataAttributes = dataAttributes
|
self.dataAttributes = dataAttributes
|
||||||
|
self.ariaAttributes = ariaAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
self.globalAttributes = [:]
|
self.globalAttributes = [:]
|
||||||
self.globalEvents = [:]
|
self.globalEvents = [:]
|
||||||
self.dataAttributes = [:]
|
self.dataAttributes = [:]
|
||||||
|
self.ariaAttributes = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ attributes: [String: String]) throws {
|
public init(_ attributes: [String: String]) throws {
|
||||||
self.globalAttributes = [:]
|
self.globalAttributes = [:]
|
||||||
self.globalEvents = [:]
|
self.globalEvents = [:]
|
||||||
self.dataAttributes = [:]
|
self.dataAttributes = [:]
|
||||||
|
self.ariaAttributes = [:]
|
||||||
for (key, value) in attributes {
|
for (key, value) in attributes {
|
||||||
if self.trySetGlobalAttribute(key, value) {
|
if self.trySetGlobalAttribute(key, value) {
|
||||||
continue
|
continue
|
||||||
@@ -101,6 +110,7 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
|||||||
|
|
||||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||||
|
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||||
|
|
||||||
public var children:[HTMLNode] = []
|
public var children:[HTMLNode] = []
|
||||||
|
|
||||||
@@ -115,23 +125,31 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
|||||||
globalEvents[attr] = value
|
globalEvents[attr] = value
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
if key.count >= 5 {
|
||||||
dataAttributes[key] = value
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||||
continue
|
dataAttributes[key] = value
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||||
|
ariaAttributes[key] = value
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>) {
|
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>, ariaAttributes:Dictionary<String, String> = [:]) {
|
||||||
self.globalAttributes = globalAttributes
|
self.globalAttributes = globalAttributes
|
||||||
self.globalEvents = globalEvents
|
self.globalEvents = globalEvents
|
||||||
|
self.ariaAttributes = ariaAttributes
|
||||||
super.init(dataAttributes: dataAttributes)
|
super.init(dataAttributes: dataAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
||||||
self.globalAttributes = builder.globalAttributes
|
self.globalAttributes = builder.globalAttributes
|
||||||
self.globalEvents = builder.globalEvents
|
self.globalEvents = builder.globalEvents
|
||||||
|
self.ariaAttributes = builder.ariaAttributes
|
||||||
self.children = children
|
self.children = children
|
||||||
super.init(dataAttributes: builder.dataAttributes)
|
super.init(dataAttributes: builder.dataAttributes)
|
||||||
}
|
}
|
||||||
@@ -213,6 +231,18 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
|||||||
result += "\(eachAttr.key)"
|
result += "\(eachAttr.key)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
return result
|
||||||
}
|
}
|
||||||
@@ -369,8 +399,13 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool {
|
|||||||
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
if key.count >= 5 {
|
||||||
return true
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public protocol IGlobalContainer {
|
|||||||
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
||||||
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
||||||
var dataAttributes:Dictionary<String, String> { get set }
|
var dataAttributes:Dictionary<String, String> { get set }
|
||||||
|
var ariaAttributes:Dictionary<String, String> { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IGlobalContainer {
|
extension IGlobalContainer {
|
||||||
@@ -27,9 +28,15 @@ extension IGlobalContainer {
|
|||||||
globalEvents[attr] = value
|
globalEvents[attr] = value
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
if key.count >= 5 {
|
||||||
dataAttributes[key] = value
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||||
return true
|
dataAttributes[key] = value
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||||
|
ariaAttributes[key] = value
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -54,23 +61,27 @@ public struct GlobalAttributesBuilder : IGlobalContainer{
|
|||||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||||
public var dataAttributes:Dictionary<String, 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>) {
|
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>, ariaAttributes: Dictionary<String, String> = [:]) {
|
||||||
self.globalAttributes = globalAttributes
|
self.globalAttributes = globalAttributes
|
||||||
self.globalEvents = globalEvents
|
self.globalEvents = globalEvents
|
||||||
self.dataAttributes = dataAttributes
|
self.dataAttributes = dataAttributes
|
||||||
|
self.ariaAttributes = ariaAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
self.globalAttributes = [:]
|
self.globalAttributes = [:]
|
||||||
self.globalEvents = [:]
|
self.globalEvents = [:]
|
||||||
self.dataAttributes = [:]
|
self.dataAttributes = [:]
|
||||||
|
self.ariaAttributes = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ attributes: [String: String]) throws {
|
public init(_ attributes: [String: String]) throws {
|
||||||
self.globalAttributes = [:]
|
self.globalAttributes = [:]
|
||||||
self.globalEvents = [:]
|
self.globalEvents = [:]
|
||||||
self.dataAttributes = [:]
|
self.dataAttributes = [:]
|
||||||
|
self.ariaAttributes = [:]
|
||||||
for (key, value) in attributes {
|
for (key, value) in attributes {
|
||||||
if self.trySetGlobalAttribute(key, value) {
|
if self.trySetGlobalAttribute(key, value) {
|
||||||
continue
|
continue
|
||||||
@@ -136,6 +147,7 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
|||||||
|
|
||||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||||
|
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||||
|
|
||||||
public var children:[HTMLNode] = []
|
public var children:[HTMLNode] = []
|
||||||
|
|
||||||
@@ -150,23 +162,31 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
|||||||
globalEvents[attr] = value
|
globalEvents[attr] = value
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
if key.count >= 5 {
|
||||||
dataAttributes[key] = value
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||||
continue
|
dataAttributes[key] = value
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||||
|
ariaAttributes[key] = value
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw AppError("Unexpected attribute: \(key)")
|
throw AppError("Unexpected attribute: \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>) {
|
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>, ariaAttributes:Dictionary<String, String> = [:]) {
|
||||||
self.globalAttributes = globalAttributes
|
self.globalAttributes = globalAttributes
|
||||||
self.globalEvents = globalEvents
|
self.globalEvents = globalEvents
|
||||||
|
self.ariaAttributes = ariaAttributes
|
||||||
super.init(dataAttributes: dataAttributes)
|
super.init(dataAttributes: dataAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
||||||
self.globalAttributes = builder.globalAttributes
|
self.globalAttributes = builder.globalAttributes
|
||||||
self.globalEvents = builder.globalEvents
|
self.globalEvents = builder.globalEvents
|
||||||
|
self.ariaAttributes = builder.ariaAttributes
|
||||||
self.children = children
|
self.children = children
|
||||||
super.init(dataAttributes: builder.dataAttributes)
|
super.init(dataAttributes: builder.dataAttributes)
|
||||||
}
|
}
|
||||||
@@ -229,24 +249,36 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
|||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
if (eachAttr.value.count > 0) {
|
if (eachAttr.value.count > 0) {
|
||||||
result += "\(eachAttr.key)='\(eachAttr.value)'"
|
result += "\(eachAttr.key.rawValue)='\(eachAttr.value)'"
|
||||||
} else {
|
} else {
|
||||||
result += "\(eachAttr.key)"
|
result += "\(eachAttr.key.rawValue)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for eachAttr in globalEvents {
|
for eachAttr in globalEvents {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
result += " "
|
result += " "
|
||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
if (eachAttr.value.count > 0) {
|
if (eachAttr.value.count > 0) {
|
||||||
result += "\(eachAttr.key) = \(eachAttr.value)"
|
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)'"
|
||||||
} else {
|
} else {
|
||||||
result += "\(eachAttr.key)"
|
result += "\(eachAttr.key)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,8 +434,13 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool {
|
|||||||
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
if key.count >= 5 {
|
||||||
return true
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -428,4 +465,3 @@ public class NHTMLParent : NHTMLRenderable {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,15 @@ final class HRWTests: XCTestCase {
|
|||||||
let htmlRoot = rootNodes[2]
|
let htmlRoot = rootNodes[2]
|
||||||
print(htmlRoot.toString())
|
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 {
|
func testBindingGenerator() throws {
|
||||||
IHtmlNodeContainerUtility.sharedInstance.defaultBaseDir = "/Users/isaacpaul/Projects/swift-projects/HRW/Tests/HRWTests"
|
IHtmlNodeContainerUtility.sharedInstance.defaultBaseDir = "/Users/isaacpaul/Projects/swift-projects/HRW/Tests/HRWTests"
|
||||||
|
|||||||
Reference in New Issue
Block a user