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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 15045d60b78fc56c90233662980d14c92e1d3c25
4
- data.tar.gz: 892146d2831c72f6060c0d975833655abfe956ff
2
+ SHA256:
3
+ metadata.gz: ba4babed21a28731c99371c05721c7ab28880d80589dae09d3f8a6dcd3155a6c
4
+ data.tar.gz: dce2a02f2ecc5220945b5a18056dc6e5da0f717bf5745d098c707a88f6b806ed
5
5
  SHA512:
6
- metadata.gz: 79604792d7c22a2e966c00563857d4412a053a7f0cade50b4fac5d400004a1816bc89633d32c91e2d113da9414c208ef15dc93da2ef89a108b76eaef2040c211
7
- data.tar.gz: c740f285e88ed7195b4c73a50b5254fd2dfb5f0af3ed79823e19065553b29179c6872ad1dca45e8eb113d8a3f8b9d2171a22613bd2943c6f394587c5525b0b1d
6
+ metadata.gz: 62ceb0f15d69db32449a9e1502c24f262fd7a141b61c86d757d2366fc5b511c166e36b8cc93921544acdfc1af8cf48fba6a2a5622196879890f9ef599ec2a331
7
+ data.tar.gz: 66ffb7c891b4c7de6070936b024fdcce280219be04458da4c83b3019bd19c4df030668aef133181d1f8fcff627e3c21df02aa3fd8964fcd4b34f7e5446af5434
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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(options={})
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
- def to_xslt()
13
+ @schema, @xslt_schema, @debug = schema, xslt_schema, debug
15
14
 
16
- header =<<HEADER
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
- HEADER
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
- name = x[/\w+/]
28
- children = ($')[/^\[([^\]]+)\]$/,1]
29
- list = children.split(',').map {|y| y.split(':') } if children
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
- a = a_element.zip(a_html).map.with_index do |a,i|
35
- out = []
36
- tag = a.shift
37
- field = i > 0 ? 'records/' + tag : tag
38
- out << "<xsl:template match='#{field}'>" + "\n"
39
- a.flatten!(1)
40
- if a.last.is_a? Array then
41
-
42
- out << scan_e(a, tag)
43
- out << "</xsl:template>\n\n"
44
- else
45
- out << " <%s>\n" % a.first
46
- out << " <xsl:apply-templates select='summary'/>\n"
47
- out << " <xsl:apply-templates select='records'/>\n"
48
- out << " <\\%s>\n" % a.first
49
- out << "</xsl:template>\n\n"
50
- out << "<xsl:template match='%s/summary'>\n" % [tag]
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
- header + a.flatten.join + "</xsl:stylesheet>"
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 scan_e(a, prev_tag='', indent=' ')
72
+ def build(xml, a1, a2=nil)
63
73
 
64
- out = []
74
+ xml.xsl_template(match: a1[1][0]) do
65
75
 
66
- unless a.first.is_a? Array then
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
- a.flatten!(1)
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
- else
82
- a.map do |x|
83
- out << indent + "<%s><xsl:value-of select='%s'/></%s>\n" % [x[0],x[-1],x[0]]
84
- end
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.1.2
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
- MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTEzMDIwNjIxMDIwOVoXDTE0MDIwNjIxMDIwOVowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAMsMa7WYljN/rj4fTyDeuz/Wls0fn5jzMfx/1wpTsO57lwz/M5k4HCIWbQgi
19
- 18HopsrlrTPPICPIujsRy++H7ciNV8l24yZAQvLT5VEVouiwfR5GL3F8DsG1jM9u
20
- 47OvzF2XH200Q+we2c4RYBUKv3AOwnGcxMQVUPX6EYLr1uR62T+phKovfeFnsAyd
21
- 9CgvAitmSlJDjfjC0FVYumKD7m0m2s/UrlJrTjAWDFeINV/mi7PYJcBE/4WlFISo
22
- o6i1fva8+GgTQn7h5Fu7YrcFdXlxmiIkpoleUddyPJhoBrok109OR6BfskI+I+xu
23
- Je9LTASmS9XEsXjOKC08b/WkIW0CAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4E
24
- FgQUywhkOZNImaszVseSkk9YK4wTd+gwCwYDVR0PBAQDAgSwMA0GCSq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+ J9wxFDyIkWQWt7wEwchHEmgqg5Khl85v+ZYm5woyxaZ2UxIYIsn0zDLv5/bAbjBu
24
+ MyR9ESJFs9smj0PaRbSSZbxvNWsPLA34SriPKJ4ADHuIobaz0czEPQQ2uTUCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU/tSS0D1U
26
+ WpsGaMWQpoJMbNO7ru4wJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAEClE6CK7psVlx2h8R0OdazLpajaOMH3jqFccirRu
29
+ ZrcS7WrhCX7mS0ZIZKjS3Y858VquhAtGHyqUhMDR9tSkxc8BnNs98PH+IJhr0S1o
30
+ OrehvvB/PVTlGqfVz99zEnIgwCJbLo9ybBVu23oOk9AU0+ZYkMyWiNOeT5T60klB
31
+ TGgG+T9BZ+68svDbYPdJdu6FEgBDh4W0TFYnyaGobXQdEszF20bGojr4NpAThcEX
32
+ glSFwCel07qQwxTdMYzghycoMtQkqeee+rmGLC3CWzgMgiHzBytPQ4KAZjxVnaVd
33
+ +jt0YSFc2tu2SmL3Pp5yZFihzdl31RWjc043Ija25V8lt0dOzvWrsyels00Lm+Qj
34
+ svP34ffw0yjardgXXz3OwGqnxqd2YgAfSSuRhuFIvDJQnQxcO+jSSNCFteCtAVJA
35
+ WBxOsiiSQG+VSI4oin72wnIx2th+aWRcF5QunIzpkdn1F4STsdMf8lt1FHhSWqay
36
+ fn8Lgzl33OaKmer+1+KH1MjJ
31
37
  -----END CERTIFICATE-----
32
- date: 2013-07-27 00:00:00.000000000 Z
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@r0bertson.co.uk
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: '0'
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
- rubyforge_project:
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: polyrex-xslt
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