Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding addElements, addElementsAfter, addElementsBefore, replac… #60

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
indent_style = tab
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ It includes many more features for consuming documents.

Release Notes
=============
Version 1.9.1
-
* Adding `addElement`, `addElements`, `addElementsBefore`, `addElementsAfter`, `removeElement`,
`removeElements`, and `replaceElement` to Node.\
Thanks to [@csmile2](https://github.com/csmile2) for requesting this!
* Deprecating `addNode`, `addNodeBefore`, `addNodeAfter`, `removeNode`, and `replaceNode` in favor of Element methods.
* Adding ktlint checks

Version 1.9.0
-
* Adding `unsafe` and `unsafeText` methods to allow for unescaped values in elements and attributes.\
Expand Down
15 changes: 9 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ plugins {
kotlin("jvm") version "1.6.20" apply false
id("com.bmuschko.nexus") version "2.3.1" apply false
id("io.github.gradle-nexus.publish-plugin") version "2.0.0-rc-1"
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
}

extra["kotlinVersion"] = "1.6.20"

allprojects {
group = "org.redundent"
version = "1.9.0"
version = "1.9.1"

repositories {
mavenCentral()
Expand All @@ -25,10 +26,12 @@ subprojects {
afterEvaluate {
configure<PublishingExtension> {
publications.withType<MavenPublication> {
artifact(tasks.register("${name}JavadocJar", Jar::class) {
archiveClassifier.set("javadoc")
archiveAppendix.set([email protected])
})
artifact(
tasks.register("${name}JavadocJar", Jar::class) {
archiveClassifier.set("javadoc")
archiveAppendix.set([email protected])
}
)

pom {
name.set("Kotlin XML Builder")
Expand Down Expand Up @@ -61,4 +64,4 @@ subprojects {
}
}
}
}
}
1 change: 1 addition & 0 deletions kotlin-xml-builder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
kotlin("jvm")
`maven-publish`
signing
id("org.jlleitschuh.gradle.ktlint")
}

val kotlinVersion: String by rootProject.extra
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.redundent.kotlin.xml

data class Attribute @JvmOverloads constructor(
val name: String,
val value: Any,
val namespace: Namespace? = null)
val name: String,
val value: Any,
val namespace: Namespace? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class CDATAElement internal constructor(text: String) : TextElement(text) {
val cdataEnd = "]]>"
val cdataStart = "<![CDATA["
return this
// split cdataEnd into two pieces so XML parser doesn't recognize it
.replace(cdataEnd, "]]$cdataEnd$cdataStart>")
// split cdataEnd into two pieces so XML parser doesn't recognize it
.replace(cdataEnd, "]]$cdataEnd$cdataStart>")
}

return "<![CDATA[${text.escapeCData()}]]>"
Expand All @@ -23,7 +23,7 @@ class CDATAElement internal constructor(text: String) : TextElement(text) {
// Need to use javaClass here to avoid a normal TextElement and a CDATAElement having the same hashCode if they have
// the same text
override fun hashCode(): Int = HashCodeBuilder()
.appendSuper(super.hashCode())
.append(javaClass.hashCode())
.toHashCode()
}
.appendSuper(super.hashCode())
.append(javaClass.hashCode())
.toHashCode()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class Comment internal constructor(val text: String) : Element {
override fun equals(other: Any?): Boolean = other is Comment && other.text == text

override fun hashCode(): Int = text.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package org.redundent.kotlin.xml

class Doctype @JvmOverloads constructor(
private val name: String,
private val systemId: String? = null,
private val publicId: String? = null) : Element {
private val name: String,
private val systemId: String? = null,
private val publicId: String? = null
) : Element {

override fun render(builder: Appendable, indent: String, printOptions: PrintOptions) {
builder.append("<!DOCTYPE $name")
override fun render(builder: Appendable, indent: String, printOptions: PrintOptions) {
builder.append("<!DOCTYPE $name")

val publicIdSet = publicId != null
val systemIdSet = systemId != null
val publicIdSet = publicId != null
val systemIdSet = systemId != null

if (publicIdSet) {
builder.append(" PUBLIC \"$publicId\"")
}
if (publicIdSet) {
builder.append(" PUBLIC \"$publicId\"")
}

if (systemIdSet) {
if (!publicIdSet) {
builder.append(" SYSTEM")
}
builder.append(" \"$systemId\"")
}
if (systemIdSet) {
if (!publicIdSet) {
builder.append(" SYSTEM")
}
builder.append(" \"$systemId\"")
}

builder.appendLine(">")
}
}
builder.appendLine(">")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface Element {
* This method handles creating the xml. Used internally
*/
fun render(builder: Appendable, indent: String, printOptions: PrintOptions)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ data class Namespace(
/**
* The value/uri/url of the namespace
*/
val value: String) {
val value: String
) {

constructor(value: String) : this("", value)

Expand Down
Loading