kramdown-plantuml 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/scripts/test-gem.sh +0 -2
- data/.github/workflows/ruby.yml +9 -3
- data/bin/net/sourceforge/plantuml/plantuml/{1.2021.8/plantuml-1.2021.8.jar → 1.2021.9/plantuml-1.2021.9.jar} +0 -0
- data/lib/kramdown-plantuml/{converter.rb → diagram.rb} +20 -15
- data/lib/kramdown-plantuml/executor.rb +14 -10
- data/lib/kramdown-plantuml/logger.rb +3 -3
- data/lib/kramdown-plantuml/plantuml_error.rb +51 -14
- data/lib/kramdown-plantuml/plantuml_result.rb +21 -5
- data/lib/kramdown-plantuml/{themer.rb → theme.rb} +12 -12
- data/lib/kramdown-plantuml/version.rb +1 -1
- data/lib/kramdown-plantuml.rb +0 -2
- data/lib/kramdown_html.rb +3 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beba25f229338deced9900f7a611c9040846e562c966de164e88dbb040acadde
|
4
|
+
data.tar.gz: 8c2aa7aa04a1a6e59a98032e1cc325544a2be7c3bc3cd407cbb3af09babe390c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcdfa9c61a9b2c751aeae743edfb58d81c3602e1eb62f6b8993fd11b2372dd6ee271f77737f655967a093c03a90d0ebf3b4865c703b7a5ed2d7b806c5a4d19d5
|
7
|
+
data.tar.gz: d35a3daea2ab515d0fd788d8b2fb0575c4993e4f25ba3c7ebda02631b8ae8d397dc88917b3809cf732e9b9a5d16bbbfa52cdfa2095a682c68de8d6ed8fba3377
|
data/.github/scripts/test-gem.sh
CHANGED
data/.github/workflows/ruby.yml
CHANGED
@@ -91,14 +91,20 @@ jobs:
|
|
91
91
|
- name: rubocop
|
92
92
|
run: bundle exec rubocop --fail-level warning --display-only-fail-level-offenses
|
93
93
|
|
94
|
-
- name: Test with Rake
|
95
|
-
run: bundle exec rake
|
96
|
-
|
97
94
|
- name: RSPec (debug)
|
98
95
|
env:
|
99
96
|
DEBUG: 1
|
100
97
|
run: bundle exec rspec --tag debug
|
101
98
|
|
99
|
+
- name: Test with Rake
|
100
|
+
run: bundle exec rake
|
101
|
+
|
102
|
+
- name: Upload code coverage
|
103
|
+
uses: actions/upload-artifact@v2
|
104
|
+
with:
|
105
|
+
name: coverage
|
106
|
+
path: ./coverage
|
107
|
+
|
102
108
|
- name: Codecov upload
|
103
109
|
run: bundle exec rake codecov:upload || echo 'Codecov upload failed'
|
104
110
|
|
Binary file
|
@@ -1,40 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'version'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'theme'
|
5
5
|
require_relative 'plantuml_error'
|
6
6
|
require_relative 'logger'
|
7
7
|
require_relative 'executor'
|
8
8
|
|
9
9
|
module Kramdown
|
10
10
|
module PlantUml
|
11
|
-
#
|
12
|
-
class
|
13
|
-
|
14
|
-
|
11
|
+
# Represents a PlantUML diagram that can be converted to SVG.
|
12
|
+
class Diagram
|
13
|
+
attr_reader :theme, :plantuml, :result
|
14
|
+
|
15
|
+
def initialize(plantuml, options = {})
|
16
|
+
@plantuml = plantuml
|
17
|
+
@theme = Theme.new(options || {})
|
15
18
|
@logger = Logger.init
|
16
19
|
@executor = Executor.new
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
20
|
-
|
22
|
+
def convert_to_svg
|
23
|
+
return @svg unless @svg.nil?
|
24
|
+
|
25
|
+
if @plantuml.nil? || @plantuml.empty?
|
21
26
|
@logger.warn ' kramdown-plantuml: PlantUML diagram is empty'
|
22
|
-
return plantuml
|
27
|
+
return @plantuml
|
23
28
|
end
|
24
29
|
|
25
|
-
plantuml = @
|
26
|
-
plantuml = plantuml.strip
|
30
|
+
@plantuml = @theme.apply(@plantuml)
|
31
|
+
@plantuml = plantuml.strip
|
27
32
|
log(plantuml)
|
28
|
-
result = @executor.execute(
|
29
|
-
result.validate
|
30
|
-
svg = result.without_xml_prologue
|
31
|
-
|
33
|
+
@result = @executor.execute(self)
|
34
|
+
@result.validate
|
35
|
+
@svg = wrap(@result.without_xml_prologue)
|
36
|
+
@svg
|
32
37
|
end
|
33
38
|
|
34
39
|
private
|
35
40
|
|
36
41
|
def wrap(svg)
|
37
|
-
theme_class = @
|
42
|
+
theme_class = @theme.name ? "theme-#{@theme.name}" : ''
|
38
43
|
class_name = "plantuml #{theme_class}".strip
|
39
44
|
|
40
45
|
wrapper_element_start = "<div class=\"#{class_name}\">"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'open3'
|
4
4
|
require_relative '../which'
|
@@ -18,21 +18,19 @@ module Kramdown
|
|
18
18
|
raise IOError, "'#{@plantuml_jar_file}' does not exist" unless File.exist? @plantuml_jar_file
|
19
19
|
end
|
20
20
|
|
21
|
-
def execute(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
' -nometadata'
|
27
|
-
end
|
21
|
+
def execute(diagram)
|
22
|
+
raise ArgumentError, 'diagram cannot be nil' if diagram.nil?
|
23
|
+
raise ArgumentError, "diagram must be a #{Diagram}" unless diagram.is_a?(Diagram)
|
24
|
+
|
25
|
+
cmd = "java -Djava.awt.headless=true -jar #{@plantuml_jar_file} -tsvg -failfast -pipe #{debug_args}"
|
28
26
|
|
29
27
|
@logger.debug " kramdown-plantuml: Executing '#{cmd}'."
|
30
28
|
|
31
|
-
stdout, stderr, status = Open3.capture3 cmd, stdin_data:
|
29
|
+
stdout, stderr, status = Open3.capture3 cmd, stdin_data: diagram.plantuml
|
32
30
|
|
33
31
|
@logger.debug " kramdown-plantuml: PlantUML exit code '#{status.exitstatus}'."
|
34
32
|
|
35
|
-
PlantUmlResult.new(stdout, stderr, status)
|
33
|
+
PlantUmlResult.new(diagram, stdout, stderr, status.exitstatus)
|
36
34
|
end
|
37
35
|
|
38
36
|
private
|
@@ -43,6 +41,12 @@ module Kramdown
|
|
43
41
|
first_jar = Dir[jar_glob].first
|
44
42
|
File.expand_path first_jar unless first_jar.nil?
|
45
43
|
end
|
44
|
+
|
45
|
+
def debug_args
|
46
|
+
return ' -verbose' if @logger.debug?
|
47
|
+
|
48
|
+
' -nometadata'
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
@@ -20,10 +20,10 @@ module Kramdown
|
|
20
20
|
@logger.debug message
|
21
21
|
end
|
22
22
|
|
23
|
-
def debug_with_prefix(prefix,
|
24
|
-
return if
|
23
|
+
def debug_with_prefix(prefix, multiline_string)
|
24
|
+
return if multiline_string.nil? || multiline_string.empty?
|
25
25
|
|
26
|
-
lines =
|
26
|
+
lines = multiline_string.lines
|
27
27
|
lines.each do |line|
|
28
28
|
@logger.debug "#{prefix}#{line.rstrip}"
|
29
29
|
end
|
@@ -1,32 +1,69 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'plantuml_result'
|
4
|
+
|
3
5
|
module Kramdown
|
4
6
|
module PlantUml
|
5
7
|
# PlantUML Error
|
6
8
|
class PlantUmlError < StandardError
|
7
|
-
def initialize(
|
9
|
+
def initialize(result)
|
10
|
+
raise ArgumentError, 'result cannot be nil' if result.nil?
|
11
|
+
raise ArgumentError, "result must be a #{PlantUmlResult}" unless result.is_a?(PlantUmlResult)
|
12
|
+
|
13
|
+
super create_message(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def create_message(result)
|
19
|
+
header = header(result).gsub("\n", ' ').strip
|
20
|
+
plantuml = plantuml(result)
|
21
|
+
result = result(result)
|
8
22
|
message = <<~MESSAGE
|
9
|
-
|
23
|
+
#{header}
|
10
24
|
|
11
25
|
#{plantuml}
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
Exit code: #{exitcode}
|
16
|
-
#{stderr}
|
27
|
+
#{result}
|
17
28
|
MESSAGE
|
18
29
|
|
19
|
-
|
30
|
+
message.strip
|
20
31
|
end
|
21
32
|
|
22
|
-
def
|
23
|
-
|
33
|
+
def header(result)
|
34
|
+
if theme_not_found?(result) && !result.diagram.nil? && !result.diagram.theme.nil?
|
35
|
+
return <<~HEADER
|
36
|
+
Conversion of the following PlantUML result failed because the
|
37
|
+
theme '#{result.diagram.theme.name}' can't be found in the directory
|
38
|
+
'#{result.diagram.theme.directory}':
|
39
|
+
HEADER
|
40
|
+
end
|
41
|
+
|
42
|
+
'Conversion of the following PlantUML result failed:'
|
43
|
+
end
|
44
|
+
|
45
|
+
def theme_not_found?(result)
|
46
|
+
!result.nil? \
|
47
|
+
&& !result.stderr.nil? \
|
48
|
+
&& result.stderr.include?('NullPointerException') \
|
49
|
+
&& result.stderr.include?('getTheme')
|
50
|
+
end
|
51
|
+
|
52
|
+
def plantuml(result)
|
53
|
+
return nil if result.nil? || result.diagram.nil?
|
54
|
+
|
55
|
+
result.diagram.plantuml
|
56
|
+
end
|
57
|
+
|
58
|
+
def result(result)
|
59
|
+
return nil if result.nil?
|
60
|
+
|
61
|
+
<<~RESULT
|
62
|
+
The error received from PlantUML was:
|
24
63
|
|
25
|
-
|
26
|
-
#
|
27
|
-
|
28
|
-
# Circumvents https://bugs.openjdk.java.net/browse/JDK-8244621
|
29
|
-
!stderr.include?('CoreText note:')
|
64
|
+
Exit code: #{result.exitcode}
|
65
|
+
#{result.stderr}
|
66
|
+
RESULT
|
30
67
|
end
|
31
68
|
end
|
32
69
|
end
|
@@ -2,17 +2,24 @@
|
|
2
2
|
|
3
3
|
require_relative 'logger'
|
4
4
|
require_relative 'plantuml_error'
|
5
|
+
require_relative 'diagram'
|
5
6
|
|
6
7
|
module Kramdown
|
7
8
|
module PlantUml
|
8
9
|
# Executes the PlantUML Java application.
|
9
10
|
class PlantUmlResult
|
10
|
-
attr_reader :stdout, :stderr, :exitcode
|
11
|
+
attr_reader :diagram, :stdout, :stderr, :exitcode
|
11
12
|
|
12
|
-
def initialize(stdout, stderr,
|
13
|
+
def initialize(diagram, stdout, stderr, exitcode)
|
14
|
+
raise ArgumentError, 'diagram cannot be nil' if diagram.nil?
|
15
|
+
raise ArgumentError, "diagram must be a #{Diagram}" unless diagram.is_a?(Diagram)
|
16
|
+
raise ArgumentError, 'exitcode cannot be nil' if exitcode.nil?
|
17
|
+
raise ArgumentError, "exitcode must be a #{Integer}" unless exitcode.is_a?(Integer)
|
18
|
+
|
19
|
+
@diagram = diagram
|
13
20
|
@stdout = stdout
|
14
21
|
@stderr = stderr
|
15
|
-
@exitcode =
|
22
|
+
@exitcode = exitcode
|
16
23
|
@logger = Logger.init
|
17
24
|
end
|
18
25
|
|
@@ -37,8 +44,17 @@ module Kramdown
|
|
37
44
|
@stdout
|
38
45
|
end
|
39
46
|
|
40
|
-
def
|
41
|
-
|
47
|
+
def valid?
|
48
|
+
return true if @exitcode.zero? || @stderr.nil? || @stderr.empty?
|
49
|
+
|
50
|
+
# If stderr is not empty, but contains the string 'CoreText note:',
|
51
|
+
# the error is caused by a bug in Java, and should be ignored.
|
52
|
+
# Circumvents https://bugs.openjdk.java.net/browse/JDK-8244621
|
53
|
+
@stderr.include?('CoreText note:')
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate
|
57
|
+
raise PlantUmlError, self unless valid?
|
42
58
|
|
43
59
|
return if @stderr.nil? || @stderr.empty?
|
44
60
|
|
@@ -5,21 +5,21 @@ require_relative 'logger'
|
|
5
5
|
module Kramdown
|
6
6
|
module PlantUml
|
7
7
|
# Provides theming support for PlantUML
|
8
|
-
class
|
9
|
-
attr_reader :
|
8
|
+
class Theme
|
9
|
+
attr_reader :name, :directory
|
10
10
|
|
11
11
|
def initialize(options = {})
|
12
12
|
@logger = Logger.init
|
13
|
-
@
|
13
|
+
@name, @directory = theme_options(options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
if plantuml.nil? || plantuml.empty?
|
18
|
-
@logger.debug ' kramdown-plantuml: Empty diagram.'
|
16
|
+
def apply(plantuml)
|
17
|
+
if plantuml.nil? || !plantuml.is_a?(String) || plantuml.empty?
|
18
|
+
@logger.debug ' kramdown-plantuml: Empty diagram or not a String.'
|
19
19
|
return plantuml
|
20
20
|
end
|
21
21
|
|
22
|
-
if @
|
22
|
+
if @name.nil? || @name.empty?
|
23
23
|
@logger.debug ' kramdown-plantuml: No theme to apply.'
|
24
24
|
return plantuml
|
25
25
|
end
|
@@ -37,10 +37,10 @@ module Kramdown
|
|
37
37
|
return nil if options.nil? || !options.key?(:theme)
|
38
38
|
|
39
39
|
theme = options[:theme] || {}
|
40
|
-
|
41
|
-
|
40
|
+
name = theme.key?(:name) ? theme[:name] : nil
|
41
|
+
directory = theme.key?(:directory) ? theme[:directory] : nil
|
42
42
|
|
43
|
-
[
|
43
|
+
[name, directory]
|
44
44
|
end
|
45
45
|
|
46
46
|
def symbolize_keys(options)
|
@@ -60,8 +60,8 @@ module Kramdown
|
|
60
60
|
|
61
61
|
return plantuml if startuml_index.nil?
|
62
62
|
|
63
|
-
theme_string = "\n!theme #{@
|
64
|
-
theme_string << " from #{@
|
63
|
+
theme_string = "\n!theme #{@name}"
|
64
|
+
theme_string << " from #{@directory}" unless @directory.nil?
|
65
65
|
|
66
66
|
@logger.debug " kramdown-plantuml: Applying #{theme_string.strip}"
|
67
67
|
|
data/lib/kramdown-plantuml.rb
CHANGED
data/lib/kramdown_html.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'kramdown'
|
4
4
|
require 'kramdown-parser-gfm'
|
5
|
-
require_relative 'kramdown-plantuml/converter'
|
6
5
|
require_relative 'kramdown-plantuml/logger'
|
7
6
|
require_relative 'kramdown-plantuml/plantuml_error'
|
7
|
+
require_relative 'kramdown-plantuml/diagram'
|
8
8
|
|
9
9
|
module Kramdown
|
10
10
|
module Converter
|
@@ -18,9 +18,8 @@ module Kramdown
|
|
18
18
|
|
19
19
|
plantuml = element.value
|
20
20
|
plantuml_options = @options.key?(:plantuml) ? @options[:plantuml] : {}
|
21
|
-
|
22
|
-
|
23
|
-
converter.convert_plantuml_to_svg(plantuml)
|
21
|
+
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, plantuml_options)
|
22
|
+
diagram.convert_to_svg
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown-plantuml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swedbank Pay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -166,17 +166,17 @@ files:
|
|
166
166
|
- LICENSE
|
167
167
|
- README.md
|
168
168
|
- Rakefile
|
169
|
-
- bin/net/sourceforge/plantuml/plantuml/1.2021.
|
169
|
+
- bin/net/sourceforge/plantuml/plantuml/1.2021.9/plantuml-1.2021.9.jar
|
170
170
|
- kramdown-plantuml.gemspec
|
171
171
|
- lib/kramdown-plantuml.rb
|
172
172
|
- lib/kramdown-plantuml/bool_env.rb
|
173
173
|
- lib/kramdown-plantuml/console_logger.rb
|
174
|
-
- lib/kramdown-plantuml/
|
174
|
+
- lib/kramdown-plantuml/diagram.rb
|
175
175
|
- lib/kramdown-plantuml/executor.rb
|
176
176
|
- lib/kramdown-plantuml/logger.rb
|
177
177
|
- lib/kramdown-plantuml/plantuml_error.rb
|
178
178
|
- lib/kramdown-plantuml/plantuml_result.rb
|
179
|
-
- lib/kramdown-plantuml/
|
179
|
+
- lib/kramdown-plantuml/theme.rb
|
180
180
|
- lib/kramdown-plantuml/version.rb
|
181
181
|
- lib/kramdown_html.rb
|
182
182
|
- lib/which.rb
|