ox-builder 1.0.1 → 1.0.2
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 +8 -8
- data/README.md +1 -0
- data/benchmarks/huge.rb +2 -2
- data/benchmarks/indent.rb +51 -0
- data/benchmarks/medium.rb +2 -4
- data/benchmarks/templates/{large.builder → countries.builder} +0 -0
- data/benchmarks/templates/{large.ox → countries.ox} +0 -0
- data/benchmarks/templates/{small.builder → person.builder} +0 -0
- data/benchmarks/templates/{small.ox → person.ox} +0 -0
- data/lib/ox/builder/factory.rb +4 -2
- data/lib/ox/builder/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWYzZGQ5MzAyZGY4MzIzMjcyZTE4ODQ4NWQ5NWI1NjNlN2MwODRjNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjExOTE2YjlhNWMzNjdmYzg4MzE3NGI0ZjdjYjc1Y2EzZTVkOTQxOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjAxODcyMzM4Nzk1NjJmNTRhNDJhMWE5MmQyM2U1NTAxZDk0YmNmMzIzOTRl
|
10
|
+
NjhmYmUxZGE5ZmY0YzYzYjE2MDQ3ODUyMzE2Njg5NmQyMWQ0MDZkNzMyZTA4
|
11
|
+
YWVjNmUzNzViYTExN2VlOWE5MmNhNGYxZDk4NTliNjUxNThjZmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjYwM2NkYzBkNGJlNWE2NTQzMzFjODliY2M4YjE5YTk0MDdmNTVhZjIxYTM0
|
14
|
+
MjU4ZjNlMjQ2NDE0M2FmZmI2YzgzNzM4OTZhZmFiMjU4ZjJlZTdkNTI5NmVm
|
15
|
+
MjczNDg1ZDMyZjU0ZTJiMmYwMDZjMjE3YTJiZjY2NWIzOTBkZDA=
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Ox::Builder
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/ox-builder)
|
3
4
|
[](https://travis-ci.org/dvandersluis/ox-builder)
|
4
5
|
|
5
6
|
Ox::Builder provides a DSL for quickly building XML documents using the [`ox`](https://github.com/ohler55/ox) gem.
|
data/benchmarks/huge.rb
CHANGED
@@ -5,8 +5,8 @@ Country = Struct.new(:code, :name, :population, :north, :south, :east, :west, :c
|
|
5
5
|
data = YAML.load_file('benchmarks/data/countries.yml')['countries']['country'] * 100
|
6
6
|
@countries = data.map{ |c| Country.new(*c.values) }
|
7
7
|
|
8
|
-
builder_tilt = Tilt.new('benchmarks/templates/
|
9
|
-
ox_tilt = Tilt.new('benchmarks/templates/
|
8
|
+
builder_tilt = Tilt.new('benchmarks/templates/countries.builder')
|
9
|
+
ox_tilt = Tilt.new('benchmarks/templates/countries.ox')
|
10
10
|
|
11
11
|
# Output is 11M
|
12
12
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative './runner'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
Country = Struct.new(:code, :name, :population, :north, :south, :east, :west, :capital, :continent_name)
|
5
|
+
data = YAML.load_file('benchmarks/data/countries.yml')['countries']['country']
|
6
|
+
@countries = data.map{ |c| Country.new(*c.values) }
|
7
|
+
|
8
|
+
doc = Ox::Builder.build do
|
9
|
+
instruct!
|
10
|
+
|
11
|
+
countries do
|
12
|
+
@countries.each do |country|
|
13
|
+
country do
|
14
|
+
name { cdata!(country.name) }
|
15
|
+
code { cdata!(country.code) }
|
16
|
+
continent { cdata!(country.continent_name) }
|
17
|
+
capital { cdata!(country.capital) }
|
18
|
+
population country.population
|
19
|
+
|
20
|
+
boundaries do
|
21
|
+
north country.north
|
22
|
+
sourth country.south
|
23
|
+
east country.east
|
24
|
+
west country.west
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Benchmark.ips do |x|
|
32
|
+
x.config(time: 20, warmup: 10)
|
33
|
+
|
34
|
+
x.report('indent(200)') do
|
35
|
+
doc.to_xml(indent: 200)
|
36
|
+
end
|
37
|
+
|
38
|
+
x.report('indent(10)') do
|
39
|
+
doc.to_xml(indent: 10)
|
40
|
+
end
|
41
|
+
|
42
|
+
x.report('indent(2)') do
|
43
|
+
doc.to_xml(indent: 2)
|
44
|
+
end
|
45
|
+
|
46
|
+
x.report('indent(0)') do
|
47
|
+
doc.to_xml(indent: 0)
|
48
|
+
end
|
49
|
+
|
50
|
+
x.compare!
|
51
|
+
end
|
data/benchmarks/medium.rb
CHANGED
@@ -5,10 +5,8 @@ Country = Struct.new(:code, :name, :population, :north, :south, :east, :west, :c
|
|
5
5
|
data = YAML.load_file('benchmarks/data/countries.yml')['countries']['country']
|
6
6
|
@countries = data.map{ |c| Country.new(*c.values) }
|
7
7
|
|
8
|
-
builder_tilt = Tilt.new('benchmarks/templates/
|
9
|
-
ox_tilt = Tilt.new('benchmarks/templates/
|
10
|
-
|
11
|
-
File.write('ox.xml', builder_tilt.render(Object.new, { countries: @countries }))
|
8
|
+
builder_tilt = Tilt.new('benchmarks/templates/countries.builder')
|
9
|
+
ox_tilt = Tilt.new('benchmarks/templates/countries.ox')
|
12
10
|
|
13
11
|
# Output is 107K
|
14
12
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/ox/builder/factory.rb
CHANGED
@@ -9,8 +9,10 @@ module Ox
|
|
9
9
|
@node = node
|
10
10
|
end
|
11
11
|
|
12
|
-
def to_s
|
13
|
-
|
12
|
+
def to_s(options = {})
|
13
|
+
encoding = options.fetch(:encoding, 'UTF-8')
|
14
|
+
indent = options.fetch(:indent, 2)
|
15
|
+
Ox.dump(node, encoding: encoding, indent: indent)
|
14
16
|
end
|
15
17
|
alias_method :to_xml, :to_s
|
16
18
|
|
data/lib/ox/builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ox-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vandersluis
|
@@ -167,13 +167,14 @@ files:
|
|
167
167
|
- Rakefile
|
168
168
|
- benchmarks/data/countries.yml
|
169
169
|
- benchmarks/huge.rb
|
170
|
+
- benchmarks/indent.rb
|
170
171
|
- benchmarks/medium.rb
|
171
172
|
- benchmarks/runner.rb
|
172
173
|
- benchmarks/small.rb
|
173
|
-
- benchmarks/templates/
|
174
|
-
- benchmarks/templates/
|
175
|
-
- benchmarks/templates/
|
176
|
-
- benchmarks/templates/
|
174
|
+
- benchmarks/templates/countries.builder
|
175
|
+
- benchmarks/templates/countries.ox
|
176
|
+
- benchmarks/templates/person.builder
|
177
|
+
- benchmarks/templates/person.ox
|
177
178
|
- bin/console
|
178
179
|
- bin/setup
|
179
180
|
- lib/ox/builder.rb
|