philiprehberger-xml_builder 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +15 -2
- data/lib/philiprehberger/xml_builder/document.rb +12 -3
- data/lib/philiprehberger/xml_builder/version.rb +1 -1
- data/lib/philiprehberger/xml_builder.rb +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3fb9d2343ef89b02de12422a8ca7632e3d16634876c8d602f93966f35f4f8287
|
|
4
|
+
data.tar.gz: 7a21d2d73ddfe6d7d2305527fc1305425965197eb5950809d3168308ed4a7d4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c0d1c868566984cc1656049d2705a2b7af30293e567b0d66ff065edeeea004d257e5d3164b2e288949dfcc0654f0dddc3dea2d81a0c64ccebd1cd05c14afbb8
|
|
7
|
+
data.tar.gz: 8094d77d65803ac2ad438e1eee6c9c32218e60e6548a09d18874796bad2a17ba891178aa6f0198b6d756ea4d067abcca2a8492a391b7e8d8409d381fcf652df2
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-04-10
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Add `declaration:` option to `build`, `build_soap`, and `Document.new` to omit the XML declaration when building fragments
|
|
14
|
+
- Add CDATA content validation — raises `Error` if content contains `]]>`
|
|
15
|
+
- Add comment text validation — raises `Error` if text contains `--`
|
|
16
|
+
- Add Ruby 3.4 to CI test matrix
|
|
17
|
+
|
|
18
|
+
## [0.2.2] - 2026-03-31
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- Add GitHub issue templates, dependabot config, and PR template
|
|
22
|
+
|
|
10
23
|
## [0.2.1] - 2026-03-31
|
|
11
24
|
|
|
12
25
|
### Changed
|
data/README.md
CHANGED
|
@@ -98,6 +98,19 @@ xml = Philiprehberger::XmlBuilder.build do |doc|
|
|
|
98
98
|
end
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
### Without XML Declaration
|
|
102
|
+
|
|
103
|
+
Omit the `<?xml ... ?>` declaration when building fragments:
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
xml = Philiprehberger::XmlBuilder.build(declaration: false) do |doc|
|
|
107
|
+
doc.tag(:item, id: "1") { doc.text("fragment") }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
puts xml
|
|
111
|
+
# <item id="1">fragment</item>
|
|
112
|
+
```
|
|
113
|
+
|
|
101
114
|
### XML Namespaces
|
|
102
115
|
|
|
103
116
|
Register namespace prefixes and create namespace-aware elements:
|
|
@@ -184,8 +197,8 @@ end
|
|
|
184
197
|
|
|
185
198
|
| Method | Description |
|
|
186
199
|
|--------|-------------|
|
|
187
|
-
| `.build(encoding: "UTF-8", version: "1.0") { \|doc\| ... }` | Build an XML document and return the string |
|
|
188
|
-
| `.build_soap(soap_version: "1.1", encoding: "UTF-8", version: "1.0") { \|header, body\| ... }` | Build a SOAP envelope document |
|
|
200
|
+
| `.build(encoding: "UTF-8", version: "1.0", declaration: true) { \|doc\| ... }` | Build an XML document and return the string |
|
|
201
|
+
| `.build_soap(soap_version: "1.1", encoding: "UTF-8", version: "1.0", declaration: true) { \|header, body\| ... }` | Build a SOAP envelope document |
|
|
189
202
|
|
|
190
203
|
### `Document`
|
|
191
204
|
|
|
@@ -10,9 +10,10 @@ module Philiprehberger
|
|
|
10
10
|
|
|
11
11
|
# @param version [String] XML version for the declaration
|
|
12
12
|
# @param encoding [String] XML encoding for the declaration
|
|
13
|
-
def initialize(version: '1.0', encoding: 'UTF-8')
|
|
13
|
+
def initialize(version: '1.0', encoding: 'UTF-8', declaration: true)
|
|
14
14
|
@version = version
|
|
15
15
|
@encoding = encoding
|
|
16
|
+
@declaration = declaration
|
|
16
17
|
@children = []
|
|
17
18
|
@node_stack = []
|
|
18
19
|
@namespaces = {}
|
|
@@ -50,6 +51,8 @@ module Philiprehberger
|
|
|
50
51
|
# @param content [String] the CDATA content (must not contain "]]>")
|
|
51
52
|
# @return [void]
|
|
52
53
|
def cdata(content)
|
|
54
|
+
raise Error, 'CDATA content must not contain "]]>"' if content.to_s.include?(']]>')
|
|
55
|
+
|
|
53
56
|
current_parent.push("<![CDATA[#{content}]]>")
|
|
54
57
|
end
|
|
55
58
|
|
|
@@ -58,6 +61,8 @@ module Philiprehberger
|
|
|
58
61
|
# @param text [String] the comment text
|
|
59
62
|
# @return [void]
|
|
60
63
|
def comment(text)
|
|
64
|
+
raise Error, 'Comment text must not contain "--"' if text.to_s.include?('--')
|
|
65
|
+
|
|
61
66
|
current_parent.push("<!-- #{text} -->")
|
|
62
67
|
end
|
|
63
68
|
|
|
@@ -90,8 +95,12 @@ module Philiprehberger
|
|
|
90
95
|
# @param indent [Integer, nil] number of spaces per indentation level, or nil for compact output
|
|
91
96
|
# @return [String] the rendered XML document
|
|
92
97
|
def to_xml(indent: nil)
|
|
93
|
-
parts = [
|
|
94
|
-
|
|
98
|
+
parts = []
|
|
99
|
+
|
|
100
|
+
if @declaration
|
|
101
|
+
parts << "<?xml version=\"#{@version}\" encoding=\"#{@encoding}\"?>"
|
|
102
|
+
parts << (indent ? "\n" : '')
|
|
103
|
+
end
|
|
95
104
|
|
|
96
105
|
@children.each do |child|
|
|
97
106
|
parts << render_child(child, indent: indent, level: 0)
|
|
@@ -15,8 +15,8 @@ module Philiprehberger
|
|
|
15
15
|
# @param version [String] XML version declaration (default: "1.0")
|
|
16
16
|
# @yield [Document] the document builder
|
|
17
17
|
# @return [String] the rendered XML string
|
|
18
|
-
def self.build(encoding: 'UTF-8', version: '1.0', &block)
|
|
19
|
-
doc = Document.new(version: version, encoding: encoding)
|
|
18
|
+
def self.build(encoding: 'UTF-8', version: '1.0', declaration: true, &block)
|
|
19
|
+
doc = Document.new(version: version, encoding: encoding, declaration: declaration)
|
|
20
20
|
block.call(doc)
|
|
21
21
|
doc.to_s
|
|
22
22
|
end
|
|
@@ -31,8 +31,8 @@ module Philiprehberger
|
|
|
31
31
|
# @param version [String] XML version declaration (default: "1.0")
|
|
32
32
|
# @yield [header, body] yields two arrays; push lambdas that accept a doc
|
|
33
33
|
# @return [String] the rendered SOAP XML string
|
|
34
|
-
def self.build_soap(soap_version: '1.1', encoding: 'UTF-8', version: '1.0', &block)
|
|
35
|
-
doc = Document.new(version: version, encoding: encoding)
|
|
34
|
+
def self.build_soap(soap_version: '1.1', encoding: 'UTF-8', version: '1.0', declaration: true, &block)
|
|
35
|
+
doc = Document.new(version: version, encoding: encoding, declaration: declaration)
|
|
36
36
|
doc.soap_envelope(version: soap_version, &block)
|
|
37
37
|
doc.to_s
|
|
38
38
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-xml_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Programmatic XML construction with a clean DSL, auto-escaping, CDATA,
|
|
14
14
|
comments, processing instructions, and pretty printing. Zero dependencies.
|
|
@@ -26,11 +26,11 @@ files:
|
|
|
26
26
|
- lib/philiprehberger/xml_builder/escaper.rb
|
|
27
27
|
- lib/philiprehberger/xml_builder/node.rb
|
|
28
28
|
- lib/philiprehberger/xml_builder/version.rb
|
|
29
|
-
homepage: https://
|
|
29
|
+
homepage: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-xml_builder
|
|
30
30
|
licenses:
|
|
31
31
|
- MIT
|
|
32
32
|
metadata:
|
|
33
|
-
homepage_uri: https://
|
|
33
|
+
homepage_uri: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-xml_builder
|
|
34
34
|
source_code_uri: https://github.com/philiprehberger/rb-xml-builder
|
|
35
35
|
changelog_uri: https://github.com/philiprehberger/rb-xml-builder/blob/main/CHANGELOG.md
|
|
36
36
|
bug_tracker_uri: https://github.com/philiprehberger/rb-xml-builder/issues
|