polyrex-xslt 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/polyrex-xslt.rb +70 -58
- metadata +53 -28
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba4babed21a28731c99371c05721c7ab28880d80589dae09d3f8a6dcd3155a6c
|
4
|
+
data.tar.gz: dce2a02f2ecc5220945b5a18056dc6e5da0f717bf5745d098c707a88f6b806ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62ceb0f15d69db32449a9e1502c24f262fd7a141b61c86d757d2366fc5b511c166e36b8cc93921544acdfc1af8cf48fba6a2a5622196879890f9ef599ec2a331
|
7
|
+
data.tar.gz: 66ffb7c891b4c7de6070936b024fdcce280219be04458da4c83b3019bd19c4df030668aef133181d1f8fcff627e3c21df02aa3fd8964fcd4b34f7e5446af5434
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/polyrex-xslt.rb
CHANGED
@@ -2,89 +2,101 @@
|
|
2
2
|
|
3
3
|
# file: polyrex-xslt.rb
|
4
4
|
|
5
|
+
require 'rexle'
|
6
|
+
require 'rexle-builder'
|
7
|
+
|
8
|
+
|
5
9
|
class PolyrexXSLT
|
6
|
-
|
7
|
-
attr_accessor :schema, :xslt_schema
|
8
10
|
|
9
|
-
def initialize(
|
10
|
-
o = {schema: '', xslt_schema: ''}.merge(options)
|
11
|
-
@schema, @xslt_schema = o.values
|
12
|
-
end
|
11
|
+
def initialize(schema: '', xslt_schema: '', debug: false)
|
13
12
|
|
14
|
-
|
13
|
+
@schema, @xslt_schema, @debug = schema, xslt_schema, debug
|
15
14
|
|
16
|
-
|
17
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
18
|
-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
19
|
-
<xsl:output method="xml" indent="yes" />
|
15
|
+
end
|
20
16
|
|
21
|
-
|
17
|
+
def to_xslt()
|
22
18
|
|
23
19
|
a_element = @schema.split('/').map{|x| x[/\w+/]}
|
24
20
|
|
21
|
+
@xslt_schema = build_xslt_schema(@schema) if @xslt_schema.empty?
|
22
|
+
puts ('@xslt_schema: ' + @xslt_schema.inspect).debug if @debug
|
23
|
+
|
25
24
|
a_html = @xslt_schema.split('/').map do |x|
|
26
|
-
|
27
|
-
|
28
|
-
children =
|
29
|
-
|
25
|
+
|
26
|
+
result = x.match(/([\w\>]+)(?:[\(\[]([^\]\)]+)[\]\)])?(.*)/)
|
27
|
+
name, children, remaining = result.captures if result
|
28
|
+
|
29
|
+
list = children.split(/ *, */).map {|y| y.split(':',2)} if children
|
30
30
|
|
31
31
|
[name, list]
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
out << "</xsl:template>\n\n"
|
34
|
+
puts ('a_html: ' + a_html.inspect).debug if @debug
|
35
|
+
|
36
|
+
a = a_element.zip(a_html)
|
37
|
+
|
38
|
+
xml = RexleBuilder.new
|
39
|
+
raw_a = xml.xsl_stylesheet(xmlns_xsl: \
|
40
|
+
"http://www.w3.org/1999/XSL/Transform", version: "1.0") do
|
41
|
+
xml.xsl_output(method: "xml", indent: "yes", \
|
42
|
+
:"omit-xml-declaration" => "yes")
|
43
|
+
|
44
|
+
a.each_cons(2).with_index do |x,i|
|
45
|
+
|
46
|
+
x1, x2 = x
|
47
|
+
puts 'x1: ' + x1.inspect if @debug
|
48
|
+
build(xml, x1, x2)
|
49
|
+
build(xml, x2) if x2
|
50
|
+
|
52
51
|
end
|
53
|
-
|
54
|
-
out
|
52
|
+
|
55
53
|
end
|
56
54
|
|
57
|
-
|
55
|
+
xml2 = Rexle.new(raw_a).xml(pretty: true).gsub('xsl_apply_templates',\
|
56
|
+
'xsl:apply-templates').gsub('xsl_value_of','xsl:value-of').\
|
57
|
+
gsub('xsl_template','xsl:template').gsub('xsl_','xsl:').\
|
58
|
+
gsub('xmlns_xsl','xmlns:xsl')
|
59
|
+
|
60
|
+
header = %q(
|
61
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
62
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
63
|
+
<xsl:output method="xml" indent="yes" />
|
64
|
+
)
|
65
|
+
|
66
|
+
header + xml2
|
67
|
+
|
58
68
|
end
|
59
69
|
|
60
70
|
private
|
61
71
|
|
62
|
-
def
|
72
|
+
def build(xml, a1, a2=nil)
|
63
73
|
|
64
|
-
|
74
|
+
xml.xsl_template(match: a1[1][0]) do
|
65
75
|
|
66
|
-
|
67
|
-
tag = a.shift
|
68
|
-
out << indent + "<%s>\n" % tag
|
69
|
-
out << indent + " <xsl:apply-templates select='summary'/>\n"
|
70
|
-
out << indent + "<\\%s>\n" % tag
|
71
|
-
out << "</xsl:template>\n\n"
|
72
|
-
out << "<xsl:template match='%s/summary'>\n" % [prev_tag]
|
76
|
+
xml.send a1[0].to_sym do
|
73
77
|
|
74
|
-
|
75
|
-
if a.last.is_a? Array then
|
76
|
-
out << scan_e(a, tag, indent + ' ')
|
77
|
-
else
|
78
|
-
out << indent + ' ' + a.first + "\n"
|
79
|
-
end
|
78
|
+
xml.summary do
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
if a1[1][1] then
|
81
|
+
|
82
|
+
a1[1][1].each do |source, target|
|
83
|
+
|
84
|
+
xml.xsl_element(name: target) do
|
85
|
+
xml.xsl_value_of(select: source)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
xml.records do
|
95
|
+
xml.xsl_apply_templates(select: a2[1][0]) if a2
|
96
|
+
end
|
97
|
+
end
|
85
98
|
end
|
86
99
|
|
87
|
-
out
|
88
100
|
end
|
89
|
-
|
101
|
+
|
90
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-xslt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,29 +10,55 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwODA1MDczNDQ2WhcN
|
15
|
+
MjAwODA0MDczNDQ2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDBD20I
|
17
|
+
g+Js3EafyvbGq0YOT4Z29xUDWXeO/Tb4bPjm8xKgCbTv4Fur2SueF5IWczx477Y0
|
18
|
+
phZU7eE1RCLV5Fq/lE22XBMBldWGqZ06F8CW2tDCJi1WtqOWO3hb0niL0PrVyocN
|
19
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syels00Lm+Qj
|
34
|
+
svP34ffw0yjardgXXz3OwGqnxqd2YgAfSSuRhuFIvDJQnQxcO+jSSNCFteCtAVJA
|
35
|
+
WBxOsiiSQG+VSI4oin72wnIx2th+aWRcF5QunIzpkdn1F4STsdMf8lt1FHhSWqay
|
36
|
+
fn8Lgzl33OaKmer+1+KH1MjJ
|
31
37
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
33
|
-
dependencies:
|
38
|
+
date: 2019-08-05 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rexle
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.5.2
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.5'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.5.2
|
34
60
|
description:
|
35
|
-
email: james@
|
61
|
+
email: james@jamesrobertson.eu
|
36
62
|
executables: []
|
37
63
|
extensions: []
|
38
64
|
extra_rdoc_files: []
|
@@ -48,18 +74,17 @@ require_paths:
|
|
48
74
|
- lib
|
49
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
76
|
requirements:
|
51
|
-
- -
|
77
|
+
- - ">="
|
52
78
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
79
|
+
version: 2.1.2
|
54
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
81
|
requirements:
|
56
|
-
- -
|
82
|
+
- - ">="
|
57
83
|
- !ruby/object:Gem::Version
|
58
84
|
version: '0'
|
59
85
|
requirements: []
|
60
|
-
|
61
|
-
rubygems_version: 2.0.0.rc.2
|
86
|
+
rubygems_version: 3.0.1
|
62
87
|
signing_key:
|
63
88
|
specification_version: 4
|
64
|
-
summary:
|
89
|
+
summary: Generates XSLT to produce a Polyrex document from a tree-like XML structure.
|
65
90
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|