asciidoctor-plantuml 0.0.8 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-plantuml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Horacio Sanson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2021-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,48 +24,82 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10.5'
47
+ version: '13.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.5'
54
+ version: '13.0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: nokogiri
56
+ name: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.6'
61
+ version: '1.7'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.6'
68
+ version: '1.7'
55
69
  - !ruby/object:Gem::Dependency
56
- name: asciidoctor
70
+ name: test-unit
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.5'
62
- type: :runtime
75
+ version: '3.3'
76
+ type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.5'
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: asciidoctor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.6
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: 3.0.0
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.5.6
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: 3.0.0
69
103
  description: Asciidoctor PlantUML extension
70
104
  email:
71
105
  - hsanson@gmail.com
@@ -74,8 +108,8 @@ extensions: []
74
108
  extra_rdoc_files: []
75
109
  files:
76
110
  - lib/asciidoctor-plantuml.rb
77
- - lib/asciidoctor-plantuml/plantuml.rb
78
- - lib/asciidoctor-plantuml/version.rb
111
+ - lib/asciidoctor_plantuml/plantuml.rb
112
+ - lib/asciidoctor_plantuml/version.rb
79
113
  - test/test_plantuml.rb
80
114
  homepage: https://github.com/hsanson/asciidoctor-plantuml
81
115
  licenses:
@@ -89,17 +123,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
123
  requirements:
90
124
  - - ">="
91
125
  - !ruby/object:Gem::Version
92
- version: '0'
126
+ version: '2.3'
93
127
  required_rubygems_version: !ruby/object:Gem::Requirement
94
128
  requirements:
95
129
  - - ">="
96
130
  - !ruby/object:Gem::Version
97
131
  version: '0'
98
132
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.5.1
133
+ rubygems_version: 3.1.2
101
134
  signing_key:
102
135
  specification_version: 4
103
- summary: An extension for Asciidoctor that enables support for PlantUML diagrams.
136
+ summary: Asciidoctor support for PlantUML diagrams.
104
137
  test_files:
105
138
  - test/test_plantuml.rb
@@ -1,286 +0,0 @@
1
- require 'uri'
2
- require 'zlib'
3
- require 'open-uri'
4
- require 'net/http'
5
-
6
- module Asciidoctor
7
- module PlantUml
8
-
9
- class Configuration
10
-
11
- DEFAULT_URL = ENV["PLANTUML_URL"] || ""
12
-
13
- attr_accessor :url, :txt_enable, :svg_enable, :png_enable
14
-
15
- def initialize
16
- @url = DEFAULT_URL
17
- @txt_enable = true
18
- @svg_enable = true
19
- @png_enable = true
20
- end
21
- end
22
-
23
- class << self
24
- attr_writer :configuration
25
- end
26
-
27
- def self.configuration
28
- @configuration ||= Configuration.new
29
- end
30
-
31
- def self.configure
32
- yield(configuration)
33
- end
34
-
35
- class Processor
36
-
37
- FORMATS = ["png", "svg", "txt"]
38
- DEFAULT_FORMAT = FORMATS[0]
39
-
40
- class << self
41
- def valid_format?(format)
42
- FORMATS.include?(format)
43
- end
44
-
45
- def server_url
46
- PlantUml::configuration.url
47
- end
48
-
49
- def txt_enabled?
50
- PlantUml::configuration.txt_enable
51
- end
52
-
53
- def png_enabled?
54
- PlantUml::configuration.png_enable
55
- end
56
-
57
- def svg_enabled?
58
- PlantUml::configuration.svg_enable
59
- end
60
-
61
- def enabled?
62
- txt_enabled? || png_enabled? || svg_enabled?
63
- end
64
-
65
- def plantuml_content(code, attrs = {})
66
-
67
- format = attrs["format"] || DEFAULT_FORMAT
68
-
69
- if !enabled?
70
- return plantuml_disabled_content(code, attrs)
71
- end
72
-
73
- if !valid_uri?(server_url)
74
- return plantuml_server_unavailable_content(server_url, attrs)
75
- end
76
-
77
- case format
78
- when "png"
79
- plantuml_img_content(code, format, attrs)
80
- when "txt"
81
- if txt_enabled?
82
- plantuml_txt_content(code, format, attrs)
83
- else
84
- plantuml_invalid_content(format, attrs)
85
- end
86
- when "svg"
87
- plantuml_img_content(code, format, attrs)
88
- else
89
- plantuml_invalid_content(format, attrs)
90
- end
91
- end
92
-
93
- # Compression code used to generate PlantUML URLs. Taken directly from the
94
- # Transcoder class in the PlantUML java code.
95
- def gen_url(text, format)
96
- result = ""
97
- compressedData = Zlib::Deflate.deflate(text)
98
- compressedData.chars.each_slice(3) do |bytes|
99
- #print bytes[0], ' ' , bytes[1] , ' ' , bytes[2]
100
- b1 = bytes[0].nil? ? 0 : (bytes[0].ord & 0xFF)
101
- b2 = bytes[1].nil? ? 0 : (bytes[1].ord & 0xFF)
102
- b3 = bytes[2].nil? ? 0 : (bytes[2].ord & 0xFF)
103
- result += append3bytes(b1, b2, b3)
104
- end
105
- join_paths(server_url, "/#{format}/", result).to_s
106
- end
107
-
108
- private
109
-
110
- def plantuml_txt_content(code, format, attrs = {})
111
- begin
112
- url = gen_url(code, format)
113
- open(url) do |f|
114
- plantuml_ascii_content(f.read, format, attrs)
115
- end
116
- rescue
117
- plantuml_img_content(code, format, attrs)
118
- end
119
- end
120
-
121
- def plantuml_ascii_content(code, format, attrs = {})
122
- content = "<div class=\"listingblock\">"
123
- content += "<div class=\"content\">"
124
- content += "<pre "
125
- content +="id=\"#{attrs['id']}\" " if attrs['id']
126
- content +="class=\"plantuml\">\n"
127
- content += code
128
- content +="</pre>"
129
- content += "</div>"
130
- content += "</div>"
131
- end
132
-
133
- def plantuml_img_content(code, format, attrs = {})
134
- content = "<div class=\"imageblock\">"
135
- content += "<div class=\"content\">"
136
- content += "<img "
137
- content +="id=\"#{attrs['id']}\" " if attrs['id']
138
- content +="class=\"plantuml\" "
139
- content +="width=\"#{attrs['width']}\" " if attrs['width']
140
- content +="height=\"#{attrs['height']}\" " if attrs['height']
141
- content +="alt=\"#{attrs['alt']}\" " if attrs['alt']
142
- content +="src=\"#{gen_url(code, format)}\" />"
143
- content += "</div>"
144
- content += "</div>"
145
- end
146
-
147
- def plantuml_invalid_content(format, attrs = {})
148
- content = "<div class=\"listingblock\">"
149
- content += "<div class=\"content\">"
150
- content += "<pre "
151
- content +="id=\"#{attrs['id']}\" " if attrs['id']
152
- content +="class=\"plantuml plantuml-error\"> "
153
- content += "PlantUML Error: Invalid format \"#{format}\""
154
- content +="</pre>"
155
- content += "</div>"
156
- content += "</div>"
157
- end
158
-
159
- def plantuml_server_unavailable_content(url, attrs = {})
160
- content = "<div class=\"listingblock\">"
161
- content += "<div class=\"content\">"
162
- content += "<pre "
163
- content +="id=\"#{attrs['id']}\" " if attrs['id']
164
- content +="class=\"plantuml plantuml-error\"> "
165
- content += "PlantUML Error: cannot connect to PlantUML server at \"#{url}\""
166
- content +="</pre>"
167
- content += "</div>"
168
- content += "</div>"
169
- end
170
-
171
- def plantuml_disabled_content(code, attrs = {})
172
- content = "<div class=\"listingblock\">"
173
- content += "<div class=\"content\">"
174
- content += "<pre "
175
- content +="id=\"#{attrs['id']}\" " if attrs['id']
176
- content +="class=\"plantuml plantuml-error\">\n"
177
- content += code
178
- content +="</pre>"
179
- content += "</div>"
180
- content += "</div>"
181
- end
182
-
183
- def encode6bit(b)
184
- if b < 10
185
- return ('0'.ord + b).chr
186
- end
187
- b = b - 10
188
- if b < 26
189
- return ('A'.ord + b).chr
190
- end
191
- b = b - 26
192
- if b < 26
193
- return ('a'.ord + b).chr
194
- end
195
- b = b - 26
196
- if b == 0
197
- return '-'
198
- end
199
- if b == 1
200
- return '_'
201
- end
202
- return '?'
203
- end
204
-
205
- def append3bytes(b1, b2, b3)
206
- c1 = b1 >> 2
207
- c2 = ((b1 & 0x3) << 4) | (b2 >> 4)
208
- c3 = ((b2 & 0xF) << 2) | (b3 >> 6)
209
- c4 = b3 & 0x3F
210
- return encode6bit(c1 & 0x3F).chr +
211
- encode6bit(c2 & 0x3F).chr +
212
- encode6bit(c3 & 0x3F).chr +
213
- encode6bit(c4 & 0x3F).chr
214
- end
215
-
216
- # Make a call to the PlantUML server with the simplest diagram possible to
217
- # check if the server is available or not.
218
- def check_server(check_url)
219
- response = Net::HTTP.get_response(URI(check_url))
220
- return response.is_a?(Net::HTTPSuccess)
221
- rescue
222
- return false
223
- end
224
-
225
- def valid_uri?(uri)
226
- !(uri =~ /\A#{URI::regexp(['http', 'https'])}\z/).nil?
227
- end
228
-
229
- def join_paths(*paths, separator: '/')
230
- paths = paths.compact.reject(&:empty?)
231
- last = paths.length - 1
232
- paths.each_with_index.map { |path, index|
233
- expand_path(path, index, last, separator)
234
- }.join
235
- end
236
-
237
- def expand_path(path, current, last, separator)
238
- if path.start_with?(separator) && current != 0
239
- path = path[1..-1]
240
- end
241
-
242
- unless path.end_with?(separator) || current == last
243
- path = [path, separator]
244
- end
245
-
246
- path
247
- end
248
- end
249
- end
250
-
251
- class BlockProcessor < Asciidoctor::Extensions::BlockProcessor
252
-
253
- use_dsl
254
- named :plantuml
255
- on_context :listing
256
- content_model :simple
257
-
258
- def process(parent, target, attrs)
259
-
260
- lines = target.lines
261
-
262
- if !(target.lines[0] =~ /@startuml/)
263
- lines = ["@startuml"] + target.lines
264
- end
265
-
266
- if !(target.lines[-1] =~ /@enduml/)
267
- lines += ["@enduml"]
268
- end
269
-
270
- content = Processor.plantuml_content(lines.join("\n"), attrs)
271
-
272
- return create_plantuml_block(parent, content, attrs)
273
-
274
- end
275
-
276
- private
277
-
278
- def create_plantuml_block(parent, content, attrs)
279
- Asciidoctor::Block.new parent, :pass, { content_model: :raw,
280
- source: content, subs: :default }.merge(attrs)
281
- end
282
-
283
- end
284
-
285
- end
286
- end
@@ -1,5 +0,0 @@
1
- module Asciidoctor
2
- module PlantUML
3
- VERSION = "0.0.8"
4
- end
5
- end