nokogiri_schematron_builder 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +6 -4
- data/lib/nokogiri/xml/schematron/pattern.rb +15 -7
- data/lib/nokogiri/xml/schematron/schema.rb +13 -5
- data/lib/nokogiri/xml/schematron/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5944b8a8e4f2284b7b08412cb7727ca4866778292df231ff57a15ff5aa3209fc
|
4
|
+
data.tar.gz: b08518566add564d4342853dd1e40e7d2aa7f021e5ccf9543005b04b843d999a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594def9e1f4508e38458805e3592488f4c89433fa10a005030e7791714ff47b58b2bfe22fcc5eef93aa97b6eb8cac7b3d446dcc4a4064c34ea16166e43e15f98
|
7
|
+
data.tar.gz: cad2079f775c8580173b26e26457a453c8e8503fa21dcb3bab8144c3aeee3aa6bbfc832bcd3d556660a223a09e943b7202e576c374ff21796fd9ea5ae552a2f2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## [0.1.1] - 2019-11-07
|
6
|
+
|
7
|
+
### Added
|
8
|
+
- This `CHANGELOG.md` file.
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- Rename attribute from `Nokogiri::XML::Schematron::Pattern#name` to `Nokogiri::XML::Schematron::Pattern#title`.
|
12
|
+
- Map `Nokogiri::XML::Schematron::Pattern#title` attribute to `<sch:title>` XML element (previously `@name` XML attribute).
|
13
|
+
- Map `Nokogiri::XML::Schematron::Schema#title` attribute to `<sch:title>` XML element (previously, `@title` XML attribute).
|
14
|
+
|
15
|
+
## [0.1.0] - 2019-10-20
|
16
|
+
|
17
|
+
### Added
|
18
|
+
- Initial commit.
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Create the schema using the domain-specific language:
|
|
31
31
|
```ruby
|
32
32
|
schema = Nokogiri::XML::Schematron::Schema.new(title: "Example schema") do
|
33
33
|
ns(prefix: "ex", uri: "http://example.com/ns#")
|
34
|
-
pattern(
|
34
|
+
pattern(title: "Example pattern") do
|
35
35
|
rule(context: "/") do
|
36
36
|
assert(test: "count(ex:A) >= 1", message: "element \"ex:A\" is REQUIRED")
|
37
37
|
end
|
@@ -50,7 +50,7 @@ Or, equivalently:
|
|
50
50
|
```ruby
|
51
51
|
schema = Nokogiri::XML::Schematron::Schema.new(title: "Example schema") do
|
52
52
|
ns(prefix: "ex", uri: "http://example.com/ns#")
|
53
|
-
pattern(
|
53
|
+
pattern(title: "Example pattern") do
|
54
54
|
context("/") do
|
55
55
|
require("ex:A") do
|
56
56
|
permit("ex:B") do
|
@@ -78,9 +78,11 @@ The result is:
|
|
78
78
|
|
79
79
|
```xml
|
80
80
|
<?xml version="1.0" encoding="UTF-8"?>
|
81
|
-
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"
|
81
|
+
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron">
|
82
|
+
<sch:title>Example schema</sch:title>
|
82
83
|
<sch:ns prefix="ex" uri="http://example.com/ns#"/>
|
83
|
-
<sch:pattern
|
84
|
+
<sch:pattern>
|
85
|
+
<sch:title>Example pattern</sch:title>
|
84
86
|
<sch:rule context="/">
|
85
87
|
<sch:assert test="count(ex:A) >= 1">element "ex:A" is REQUIRED</sch:assert>
|
86
88
|
</sch:rule>
|
@@ -10,19 +10,19 @@ module Nokogiri
|
|
10
10
|
#
|
11
11
|
# For example:
|
12
12
|
#
|
13
|
-
# pattern = Nokogiri::XML::Schematron::Pattern.new(nil, id: "pattern1",
|
14
|
-
# # => #<Nokogiri::XML::Schematron::Pattern:0x00007f8486a71f18 @parent=nil, @children=[], @options={:id=>"pattern1", :
|
13
|
+
# pattern = Nokogiri::XML::Schematron::Pattern.new(nil, id: "pattern1", title: "Example pattern")
|
14
|
+
# # => #<Nokogiri::XML::Schematron::Pattern:0x00007f8486a71f18 @parent=nil, @children=[], @options={:id=>"pattern1", :title=>"Example pattern"}>
|
15
15
|
# pattern.to_builder.to_xml
|
16
|
-
# # => "<?xml version=\"1.0\"?>\n<sch:pattern xmlns:sch=\"http://purl.oclc.org/dsdl/schematron\" id=\"pattern1\"
|
16
|
+
# # => "<?xml version=\"1.0\"?>\n<sch:pattern xmlns:sch=\"http://purl.oclc.org/dsdl/schematron\" id=\"pattern1\">\n <sch:title>Example pattern</sch:title>\n</sch:pattern>\n"
|
17
17
|
#
|
18
18
|
class Pattern < Nokogiri::XML::Schematron::Base
|
19
19
|
# @!attribute [rw] id
|
20
20
|
# @return [String] the value of the +@id+ XML attribute.
|
21
21
|
attribute :id
|
22
22
|
|
23
|
-
# @!attribute [rw]
|
24
|
-
# @return [String] the value of the +@
|
25
|
-
attribute :
|
23
|
+
# @!attribute [rw] title
|
24
|
+
# @return [String] the value of the +@title+ XML element.
|
25
|
+
attribute :title
|
26
26
|
|
27
27
|
# @!method context(context, **options, &block)
|
28
28
|
# Create a new +Node::Context+ object.
|
@@ -132,13 +132,21 @@ module Nokogiri
|
|
132
132
|
protected
|
133
133
|
|
134
134
|
def build!(xml)
|
135
|
-
xml["sch"].send(:pattern, %w(id
|
135
|
+
xml["sch"].send(:pattern, %w(id).inject(xmlns) { |acc, method_name|
|
136
136
|
unless (s = send(method_name.to_sym)).nil?
|
137
137
|
acc[method_name.to_s] = s
|
138
138
|
end
|
139
139
|
|
140
140
|
acc
|
141
141
|
}) do
|
142
|
+
%w(title).each do |method_name|
|
143
|
+
unless (s = send(method_name.to_sym)).nil?
|
144
|
+
xml["sch"].send(method_name.to_sym, xmlns) do
|
145
|
+
xml.text(s)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
142
150
|
super(xml)
|
143
151
|
end
|
144
152
|
|
@@ -13,7 +13,7 @@ module Nokogiri
|
|
13
13
|
# schema = Nokogiri::XML::Schematron::Schema.new(id: "schema1", title: "Example schema")
|
14
14
|
# # => #<Nokogiri::XML::Schematron::Schema:0x00007fa1fb9e3b68 @parent=nil, @children=[], @options={:id=>"schema1", :title=>"Example schema"}>
|
15
15
|
# schema.to_builder.to_xml
|
16
|
-
# # => "<?xml version=\"1.0\"?>\n<sch:schema xmlns:sch=\"http://purl.oclc.org/dsdl/schematron\" id=\"schema1\"
|
16
|
+
# # => "<?xml version=\"1.0\"?>\n<sch:schema xmlns:sch=\"http://purl.oclc.org/dsdl/schematron\" id=\"schema1\">\n <sch:title>Example schema</sch:title>\n</sch:schema>\n"
|
17
17
|
#
|
18
18
|
class Schema < Nokogiri::XML::Schematron::Base
|
19
19
|
# @!attribute [rw] id
|
@@ -21,7 +21,7 @@ module Nokogiri
|
|
21
21
|
attribute :id
|
22
22
|
|
23
23
|
# @!attribute [rw] title
|
24
|
-
# @return [String] the value of the +@title+ XML
|
24
|
+
# @return [String] the value of the +@title+ XML element.
|
25
25
|
attribute :title
|
26
26
|
|
27
27
|
# @!method ns(**options, &block)
|
@@ -47,7 +47,7 @@ module Nokogiri
|
|
47
47
|
# Create a new +Pattern+ object.
|
48
48
|
# @param options [Hash<Symbol, Object>] the options.
|
49
49
|
# @option options [String] :id the value of the +@id+ XML attribute.
|
50
|
-
# @option options [String] :
|
50
|
+
# @option options [String] :title the value of the +@title+ XML element.
|
51
51
|
# @yieldparam pattern [Nokogiri::XML::Schematron::Pattern] the internal representation of the +<sch:pattern>+ XML element.
|
52
52
|
# @yieldreturn [void]
|
53
53
|
# @return [Nokogiri::XML::Schematron::Pattern] the +Pattern+ object.
|
@@ -57,7 +57,7 @@ module Nokogiri
|
|
57
57
|
#
|
58
58
|
# @param options [Hash<Symbol, Object>] the options.
|
59
59
|
# @option options [#to_s] :id the value of the +@id+ XML attribute.
|
60
|
-
# @option options [#to_s] :title the value of the +@title+ XML
|
60
|
+
# @option options [#to_s] :title the value of the +@title+ XML element.
|
61
61
|
# @yieldparam schema [Nokogiri::XML::Schematron::Schema] the internal representation of the +<sch:schema>+ XML element.
|
62
62
|
# @yieldreturn [void]
|
63
63
|
def initialize(**options, &block)
|
@@ -67,13 +67,21 @@ module Nokogiri
|
|
67
67
|
protected
|
68
68
|
|
69
69
|
def build!(xml)
|
70
|
-
xml["sch"].send(:schema, %w(id
|
70
|
+
xml["sch"].send(:schema, %w(id).inject(xmlns) { |acc, method_name|
|
71
71
|
unless (s = send(method_name.to_sym)).nil?
|
72
72
|
acc[method_name.to_s] = s
|
73
73
|
end
|
74
74
|
|
75
75
|
acc
|
76
76
|
}) do
|
77
|
+
%w(title).each do |method_name|
|
78
|
+
unless (s = send(method_name.to_sym)).nil?
|
79
|
+
xml["sch"].send(method_name.to_sym, xmlns) do
|
80
|
+
xml.text(s)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
77
85
|
super(xml)
|
78
86
|
end
|
79
87
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri_schematron_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Borkum
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- CHANGELOG.md
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|