pxgraphviz 0.3.7 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f684ae44e0d1395363d736a75afb4249da5fa1c0
4
- data.tar.gz: 752c2037b77c545f70c63ad54041a72acbe0f1b8
3
+ metadata.gz: 880353e7984a79808755412706cc87e6fb87a27c
4
+ data.tar.gz: 97cfb0196e9f0aabe27383b19d9998e363a720f3
5
5
  SHA512:
6
- metadata.gz: dce7169b4b8bfae5e31879698a911d6eb14d017a6257597ae51dbddae17f8df3820a39c4176f76a65b114c1ffcc2645c1248178434d7e577058113d6eb41a9a0
7
- data.tar.gz: a899de93bb538df6b7c9add8c7edd5e8d072cf84677dc1319b1937779be92efecb0b09cee81ae5543782fb69f4db8a0274a801edd0b544a8b3cc61b2a5cc0d29
6
+ metadata.gz: 03e8c8d3bd24a12878fd37f096009c1f2468888bf82aed7c6a5bc0d0a93d7b2058dd666a245a8c167a058c8d20276cbe7d0df37aa46ebd2725339fb0bac22faf
7
+ data.tar.gz: f09a3ab964eaf9dee65beccc919499312976afad9608b8aae4272932b94ff5d5dd99d85cec78c61d4f07f6d54a41d279be76ba87b4e434e00585889c59245f23
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- L�����ϴe��jg�3��WQ��bfp0ZrNKi��#�ٞ|��M��!%_�]��|�B�Gq�v�6'`�iFSk�Γ�͊>,�k9u�lc��m�)�b{� rz�q�~vf���o�1+2�z����6�I��a�ݧ�#V��>���؁ �2a��������1����c&��p�2��e��D�n�:��4�-�
2
- BI)�����nb��P��y4�::g@u3���ª9A�h�I6i��;׀G"i�
1
+ �ӥh4��Fl{�Yi7�>z��p9T�@
2
+ F09�B$��t��va�/�����e���Q�����v���qcQ١��U��R
data/lib/pxgraphviz.rb CHANGED
@@ -9,20 +9,18 @@ require 'graphvizml'
9
9
 
10
10
  class PxGraphViz
11
11
 
12
- attr_reader :doc
12
+ attr_reader :doc, :px
13
13
 
14
14
  def initialize(s, style: default_stylesheet())
15
15
 
16
- px = s =~ /^<\?/ ? Polyrex.new.import(s) : Polyrex.new(s)
17
- @doc = build(px, style)
16
+ @px = s =~ /^<\?/ ? Polyrex.new.import(s) : Polyrex.new(s)
17
+ doc = Rexslt.new(xslt_stylesheet(), @px.to_xml)\
18
+ .to_doc.root.element('nodes')
19
+ doc.root.elements.first.insert_before Rexle::Element.new('style')\
20
+ .add_text style
21
+ @doc = doc
18
22
 
19
- end
20
-
21
- # this method will be deprecated in the near future. Use #doc instead
22
- #
23
- def to_doc()
24
- @doc
25
- end
23
+ end
26
24
 
27
25
  def to_dot()
28
26
  GraphVizML.new(@doc).to_dot
@@ -45,108 +43,6 @@ class PxGraphViz
45
43
  end
46
44
 
47
45
  private
48
-
49
- def build(px, style)
50
-
51
- # The issue with 2 nodes having the same name has yet to be rectified
52
- #jr020917 labels = @px.xpath('//records/item/summary/label/text()').uniq
53
-
54
- summary = px.xpath('//records/item/summary')
55
-
56
- labels = summary.map do |x|
57
-
58
- a = [x.text('label'), x.text('shape') || 'box', x.text('url')]
59
-
60
- end
61
-
62
- ids = labels.length.times.map {|i| i+1}
63
-
64
- labels_ids = labels.zip ids
65
-
66
- # Create a document of the nodes
67
-
68
- node_records = RexleBuilder.build do |xml|
69
-
70
- xml.records do
71
-
72
- labels_ids.each do |x, i|
73
-
74
- label, shape, url = x
75
- attr = {gid: i.to_s, shape: shape}
76
-
77
- if url then
78
- xml.a({href: url}) do
79
- xml.node(attr) { xml.label label }
80
- end
81
- else
82
- xml.node(attr) { xml.label label }
83
- end
84
-
85
- end
86
- end
87
-
88
- end
89
-
90
- a_nodes = labels.map(&:first).zip(node_records[3..-1])
91
- h_nodes = a_nodes.to_h
92
-
93
-
94
- a_edges = []
95
- px.each_recursive do |x, parent, level|
96
-
97
- next if level <= 0
98
- a_edges << [
99
- parent.label,
100
- x.label,
101
- x.respond_to?(:connection) ? x.connection : ''
102
- ]
103
-
104
- end
105
-
106
- # Create a document of the nodes
107
-
108
- edge_records = RexleBuilder.build do |xml|
109
-
110
- xml.records do
111
-
112
- a_edges.each.with_index do |x, i|
113
-
114
- item1, item2, connection = x
115
-
116
- xml.edge gid: 'e' + (i+1).to_s do
117
-
118
- xml.summary { xml.label connection }
119
- elements = [h_nodes[item1], h_nodes[item2]]
120
- nodes = elements.map {|node| node[0] == 'a' ? node[3] : node }
121
-
122
- xml.records { RexleArray.new(nodes)}
123
- end
124
-
125
- end
126
- end
127
-
128
- end
129
-
130
-
131
- h = {
132
- style: style,
133
- nodes: {summary: '', records: node_records[3..-1]},
134
- edges: {summary: '', records: edge_records[3..-1]}
135
- }
136
-
137
- a = RexleBuilder.new(h).to_a
138
- a[0] = 'gvml'
139
-
140
- summary = px.summary.to_h
141
- %i(recordx_type format_mask schema).each do |x|
142
- summary.delete x; summary.delete x.to_s
143
- end
144
-
145
- a[1] = summary
146
-
147
- Domle.new(a)
148
-
149
- end
150
46
 
151
47
  def default_stylesheet()
152
48
 
@@ -179,4 +75,79 @@ STYLE
179
75
 
180
76
  end
181
77
 
78
+
79
+ def xslt_stylesheet()
80
+
81
+ <<XSLT
82
+ <?xml version="1.0" encoding="UTF-8"?>
83
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
84
+ <xsl:output method="xml" indent="yes" />
85
+
86
+ <xsl:template match='items'>
87
+ <xsl:element name="nodes">
88
+ <xsl:if test="summary/type">
89
+ <xsl:attribute name="type">
90
+ <xsl:value-of select="summary/type"/>
91
+ </xsl:attribute>
92
+ </xsl:if>
93
+ <xsl:if test="summary/direction">
94
+ <xsl:attribute name="direction">
95
+ <xsl:value-of select="summary/direction"/>
96
+ </xsl:attribute>
97
+ </xsl:if>
98
+ <xsl:apply-templates select='records'/>
99
+ </xsl:element>
100
+ </xsl:template>
101
+
102
+ <xsl:template match='records/item'>
103
+
104
+ <xsl:if test="summary/url">
105
+ <xsl:element name="a">
106
+ <xsl:attribute name="href">
107
+ <xsl:value-of select="summary/url"/>
108
+ </xsl:attribute>
109
+ </xsl:element>
110
+ </xsl:if>
111
+
112
+ <xsl:element name="node">
113
+
114
+ <xsl:attribute name="shape">
115
+ <xsl:value-of select="summary/shape"/>
116
+ </xsl:attribute>
117
+
118
+ <xsl:if test="summary/id">
119
+ <xsl:attribute name="id">
120
+ <xsl:value-of select="summary/id"/>
121
+ </xsl:attribute>
122
+ </xsl:if>
123
+
124
+ <xsl:if test="summary/class">
125
+ <xsl:attribute name="class">
126
+ <xsl:value-of select="summary/class"/>
127
+ </xsl:attribute>
128
+ </xsl:if>
129
+
130
+ <xsl:if test="summary/connection">
131
+ <xsl:attribute name="connection">
132
+ <xsl:value-of select="summary/connection"/>
133
+ </xsl:attribute>
134
+ </xsl:if>
135
+
136
+ <xsl:apply-templates select='summary'/>
137
+ <xsl:apply-templates select='records'/>
138
+
139
+ </xsl:element>
140
+ </xsl:template>
141
+
142
+ <xsl:template match='item/summary'>
143
+
144
+ <label><xsl:value-of select='label'/></label>
145
+
146
+ </xsl:template>
147
+
148
+ </xsl:stylesheet>
149
+
150
+ XSLT
151
+ end
152
+
182
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pxgraphviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  AJ2kmROiYBLscpVrfyHxtEJluJwbid/KyR/BybHL7uezZ2/EbCxCYanOIbNyctTp
32
32
  CNgZvs+F41zO7g==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-09-09 00:00:00.000000000 Z
34
+ date: 2017-09-10 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: polyrex
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: '0.5'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.5.4
65
+ version: 0.5.5
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,7 +72,7 @@ dependencies:
72
72
  version: '0.5'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.5.4
75
+ version: 0.5.5
76
76
  description:
77
77
  email: james@jamesrobertson.eu
78
78
  executables: []
metadata.gz.sig CHANGED
Binary file