kramdown-plantuml 1.1.5 → 1.1.9
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 -1
- data/.github/workflows/ruby.yml +17 -1
- data/README.md +14 -0
- data/Rakefile +1 -1
- data/bin/net/sourceforge/plantuml/plantuml/{1.2021.10/plantuml-1.2021.10.jar → 1.2021.12/plantuml-1.2021.12.jar} +0 -0
- data/kramdown-plantuml.gemspec +2 -1
- data/lib/kramdown-plantuml/diagram.rb +13 -6
- data/lib/kramdown-plantuml/executor.rb +17 -7
- data/lib/kramdown-plantuml/jekyll_provider.rb +72 -20
- data/lib/kramdown-plantuml/{logger.rb → log_wrapper.rb} +4 -3
- data/lib/kramdown-plantuml/options.rb +91 -0
- data/lib/kramdown-plantuml/plantuml_result.rb +2 -2
- data/lib/kramdown-plantuml/theme.rb +26 -22
- data/lib/kramdown-plantuml/version.rb +1 -1
- data/lib/{which.rb → kramdown-plantuml/which.rb} +2 -1
- data/lib/kramdown_html.rb +12 -7
- data/pom.xml +1 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ffc24d5b020aac9204946744f85793d0ae07da2fe95a27b9301f104aee78c13
|
4
|
+
data.tar.gz: 83ae8392c10526f3382d327497fee2b85c297f9eb7599798f1e789f947084800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38a1e20a6a08fc178d25737ff9443fecfd8f48bbbc10f1b69eda8fd929f472a05f39150ad91d17cbaf94285757c156101510c16346aecee06f7a712e74c9908b
|
7
|
+
data.tar.gz: 9d6d3192043170c20829ab97fc5513bc392d5eb8af92eb8017042d6ebbd19000730427a5b8c3ac3809095d4a8ec74945424fe854c0d1667ecce1340b3e88b78a
|
data/.github/scripts/test-gem.sh
CHANGED
data/.github/workflows/ruby.yml
CHANGED
@@ -94,7 +94,7 @@ jobs:
|
|
94
94
|
- name: RSPec (debug)
|
95
95
|
env:
|
96
96
|
DEBUG: 1
|
97
|
-
run: bundle exec rspec --tag debug
|
97
|
+
run: bundle exec rspec --format documentation --tag debug
|
98
98
|
|
99
99
|
- name: Upload code coverage (debug)
|
100
100
|
uses: actions/upload-artifact@v2
|
@@ -117,6 +117,22 @@ jobs:
|
|
117
117
|
- name: Codecov upload
|
118
118
|
run: bundle exec rake codecov:upload || echo 'Codecov upload failed'
|
119
119
|
|
120
|
+
- name: RSPec (Jekyll)
|
121
|
+
run: |
|
122
|
+
echo "gem 'jekyll', require: false, group: :test" >> Gemfile
|
123
|
+
bundle install
|
124
|
+
bundle exec rspec --format documentation --tag jekyll
|
125
|
+
git checkout HEAD -- Gemfile
|
126
|
+
|
127
|
+
- name: Upload code coverage (Jekyll)
|
128
|
+
uses: actions/upload-artifact@v2
|
129
|
+
with:
|
130
|
+
name: rspec-jekyll-coverage
|
131
|
+
path: ./coverage
|
132
|
+
|
133
|
+
- name: Codecov upload (Jekyll)
|
134
|
+
run: bundle exec rake codecov:upload || echo 'Codecov upload failed'
|
135
|
+
|
120
136
|
- name: Build gem
|
121
137
|
id: gem
|
122
138
|
run: .github/scripts/build-gem.sh --ref ${{ github.ref }} --verbose
|
data/README.md
CHANGED
@@ -130,6 +130,20 @@ kramdown:
|
|
130
130
|
directory: path/to/themes
|
131
131
|
```
|
132
132
|
|
133
|
+
### Errors
|
134
|
+
|
135
|
+
By default, `kramdown-plantuml` will raise an error and crash if something goes
|
136
|
+
wrong during processing. This can be circumvented by setting the `raise_errors`
|
137
|
+
configuration key to `false`:
|
138
|
+
|
139
|
+
```yaml
|
140
|
+
kramdown:
|
141
|
+
plantuml:
|
142
|
+
raise_errors: false
|
143
|
+
```
|
144
|
+
|
145
|
+
The default value of `raise_errors` is `true`.
|
146
|
+
|
133
147
|
## Contributing
|
134
148
|
|
135
149
|
Bug reports and pull requests are welcome on [GitHub][github]. This project is
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'rspec/core/rake_task'
|
|
6
6
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
8
|
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
9
|
-
t.rspec_opts = '--format documentation --tag ~no_plantuml --tag ~no_java --tag ~debug'
|
9
|
+
t.rspec_opts = '--format documentation --tag ~no_plantuml --tag ~no_java --tag ~debug --tag ~jekyll'
|
10
10
|
end
|
11
11
|
|
12
12
|
namespace :maven do
|
Binary file
|
data/kramdown-plantuml.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'lib/which'
|
3
|
+
require_relative 'lib/kramdown-plantuml/which'
|
4
4
|
require_relative 'lib/kramdown-plantuml/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
|
+
spec.add_dependency 'htmlentities', '~> 4'
|
38
39
|
spec.add_dependency 'kramdown', '~> 2.3'
|
39
40
|
spec.add_dependency 'kramdown-parser-gfm', '~> 1.1'
|
40
41
|
spec.add_dependency 'open3', '~> 0.1'
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
require_relative 'version'
|
4
4
|
require_relative 'theme'
|
5
|
+
require_relative 'options'
|
5
6
|
require_relative 'plantuml_error'
|
6
|
-
require_relative '
|
7
|
+
require_relative 'log_wrapper'
|
7
8
|
require_relative 'executor'
|
8
9
|
|
9
10
|
module Kramdown
|
@@ -12,10 +13,14 @@ module Kramdown
|
|
12
13
|
class Diagram
|
13
14
|
attr_reader :theme, :plantuml, :result
|
14
15
|
|
15
|
-
def initialize(plantuml, options
|
16
|
+
def initialize(plantuml, options)
|
17
|
+
raise ArgumentError, 'options cannot be nil' if options.nil?
|
18
|
+
raise ArgumentError, "options must be a '#{Options}'." unless options.is_a?(Options)
|
19
|
+
|
16
20
|
@plantuml = plantuml
|
17
|
-
@
|
18
|
-
@
|
21
|
+
@options = options
|
22
|
+
@theme = Theme.new(options)
|
23
|
+
@logger = LogWrapper.init
|
19
24
|
@executor = Executor.new
|
20
25
|
@logger.warn 'PlantUML diagram is empty' if @plantuml.nil? || @plantuml.empty?
|
21
26
|
end
|
@@ -25,12 +30,14 @@ module Kramdown
|
|
25
30
|
return @plantuml if @plantuml.nil? || @plantuml.empty?
|
26
31
|
|
27
32
|
@plantuml = @theme.apply(@plantuml)
|
28
|
-
@plantuml = plantuml.strip
|
29
33
|
log(plantuml)
|
30
34
|
@result = @executor.execute(self)
|
31
35
|
@result.validate
|
32
36
|
@svg = wrap(@result.without_xml_prologue)
|
33
|
-
|
37
|
+
rescue StandardError => e
|
38
|
+
raise e if @options.raise_errors?
|
39
|
+
|
40
|
+
@logger.error e.to_s
|
34
41
|
end
|
35
42
|
|
36
43
|
private
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'open3'
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
4
|
+
require_relative 'which'
|
5
|
+
require_relative 'log_wrapper'
|
6
6
|
require_relative 'plantuml_result'
|
7
7
|
|
8
8
|
module Kramdown
|
@@ -10,12 +10,18 @@ module Kramdown
|
|
10
10
|
# Executes the PlantUML Java application.
|
11
11
|
class Executor
|
12
12
|
def initialize
|
13
|
-
@logger =
|
13
|
+
@logger = LogWrapper.init
|
14
|
+
|
15
|
+
java_location = Which.which('java')
|
16
|
+
|
17
|
+
raise IOError, 'Java can not be found' if java_location.nil?
|
18
|
+
|
19
|
+
@logger.debug "Java found: #{java_location}"
|
14
20
|
@plantuml_jar_file = find_plantuml_jar_file
|
15
21
|
|
16
|
-
raise IOError, 'Java can not be found' unless Which.which('java')
|
17
|
-
raise IOError, "No 'plantuml.jar' file could be found" if @plantuml_jar_file.nil?
|
18
22
|
raise IOError, "'#{@plantuml_jar_file}' does not exist" unless File.exist? @plantuml_jar_file
|
23
|
+
|
24
|
+
@logger.debug "plantuml.jar found: #{@plantuml_jar_file}"
|
19
25
|
end
|
20
26
|
|
21
27
|
def execute(diagram)
|
@@ -37,9 +43,13 @@ module Kramdown
|
|
37
43
|
|
38
44
|
def find_plantuml_jar_file
|
39
45
|
dir = File.dirname __dir__
|
40
|
-
|
46
|
+
bin_dir = File.expand_path File.join dir, '../bin'
|
47
|
+
jar_glob = File.join bin_dir, '/**/plantuml*.jar'
|
41
48
|
first_jar = Dir[jar_glob].first
|
42
|
-
|
49
|
+
|
50
|
+
raise IOError, "No 'plantuml.jar' file could be found within the '#{bin_dir}' directory." if first_jar.nil?
|
51
|
+
|
52
|
+
File.expand_path first_jar
|
43
53
|
end
|
44
54
|
|
45
55
|
def debug_args
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'English'
|
5
|
-
|
5
|
+
require 'htmlentities'
|
6
|
+
require_relative 'log_wrapper'
|
6
7
|
require_relative 'diagram'
|
7
8
|
|
8
9
|
module Kramdown
|
@@ -10,6 +11,8 @@ module Kramdown
|
|
10
11
|
# Provides an instance of Jekyll if available.
|
11
12
|
module JekyllProvider
|
12
13
|
class << self
|
14
|
+
attr_reader :site_destination_dir
|
15
|
+
|
13
16
|
def jekyll
|
14
17
|
return @jekyll if defined? @jekyll
|
15
18
|
|
@@ -19,16 +22,8 @@ module Kramdown
|
|
19
22
|
def install
|
20
23
|
return @installed = false if jekyll.nil?
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
Jekyll::Hooks.register :site, :post_render do |site|
|
25
|
-
logger.debug ':site:post_render triggered.'
|
26
|
-
|
27
|
-
site.pages.each do |page|
|
28
|
-
page.output = replace_needles(page.output)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
25
|
+
find_site_destination_dir
|
26
|
+
register_hook
|
32
27
|
@installed = true
|
33
28
|
end
|
34
29
|
|
@@ -37,29 +32,86 @@ module Kramdown
|
|
37
32
|
end
|
38
33
|
|
39
34
|
def needle(plantuml, options)
|
40
|
-
|
41
|
-
hash = { 'plantuml' => plantuml, 'options' => plantuml_options }
|
35
|
+
hash = { 'plantuml' => plantuml, 'options' => options.to_h }
|
42
36
|
|
43
37
|
<<~NEEDLE
|
44
38
|
<!--#kramdown-plantuml.start#-->
|
45
39
|
#{hash.to_json}
|
46
40
|
<!--#kramdown-plantuml.end#-->
|
47
41
|
NEEDLE
|
42
|
+
rescue StandardError => e
|
43
|
+
raise e if options.raise_errors?
|
44
|
+
|
45
|
+
puts e
|
46
|
+
logger.error 'Error while placing needle.'
|
47
|
+
logger.error e.to_s
|
48
|
+
logger.debug_multiline plantuml
|
48
49
|
end
|
49
50
|
|
50
51
|
private
|
51
52
|
|
52
|
-
def
|
53
|
+
def find_site_destination_dir
|
54
|
+
if jekyll.sites.nil? || jekyll.sites.empty?
|
55
|
+
logger.debug 'Jekyll detected, hooking into :site:post_write.'
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
@site_destination_dir = jekyll.sites.first.dest
|
60
|
+
logger.debug "Jekyll detected, hooking into :site:post_write of '#{@site_destination_dir}'."
|
61
|
+
@site_destination_dir
|
62
|
+
end
|
63
|
+
|
64
|
+
def register_hook
|
65
|
+
Jekyll::Hooks.register :site, :post_write do |site|
|
66
|
+
logger.debug ':site:post_write triggered.'
|
67
|
+
|
68
|
+
@site_destination_dir ||= site.dest
|
69
|
+
|
70
|
+
site.pages.each do |page|
|
71
|
+
page.output = replace_needles(page)
|
72
|
+
page.write(@site_destination_dir)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def replace_needles(page)
|
78
|
+
logger.debug "Replacing Jekyll needle in #{page.path}"
|
79
|
+
|
80
|
+
html = page.output
|
81
|
+
return html if html.nil? || html.empty? || !html.is_a?(String)
|
82
|
+
|
53
83
|
html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
|
54
84
|
json = $LAST_MATCH_INFO[:json]
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
85
|
+
return replace_needle(json)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def replace_needle(json)
|
90
|
+
logger.debug 'Replacing Jekyll needle.'
|
91
|
+
|
92
|
+
needle_hash = JSON.parse(json)
|
93
|
+
options_hash = needle_hash['options']
|
94
|
+
options_hash[:site_destination_dir] = @site_destination_dir
|
95
|
+
options = ::Kramdown::PlantUml::Options.new({ plantuml: options_hash })
|
96
|
+
|
97
|
+
begin
|
98
|
+
decode_and_convert(needle_hash, options)
|
99
|
+
rescue StandardError => e
|
100
|
+
raise e if options.raise_errors?
|
101
|
+
|
102
|
+
logger.error 'Error while replacing Jekyll needle.'
|
103
|
+
logger.error e.to_s
|
104
|
+
logger.debug_multiline json
|
60
105
|
end
|
61
106
|
end
|
62
107
|
|
108
|
+
def decode_and_convert(hash, options)
|
109
|
+
encoded_plantuml = hash['plantuml']
|
110
|
+
plantuml = HTMLEntities.new.decode encoded_plantuml
|
111
|
+
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
|
112
|
+
diagram.convert_to_svg
|
113
|
+
end
|
114
|
+
|
63
115
|
def load_jekyll
|
64
116
|
require 'jekyll'
|
65
117
|
::Jekyll
|
@@ -68,7 +120,7 @@ module Kramdown
|
|
68
120
|
end
|
69
121
|
|
70
122
|
def logger
|
71
|
-
@logger ||= ::Kramdown::PlantUml::
|
123
|
+
@logger ||= ::Kramdown::PlantUml::LogWrapper.init
|
72
124
|
end
|
73
125
|
end
|
74
126
|
end
|
@@ -6,7 +6,7 @@ require_relative 'jekyll_provider'
|
|
6
6
|
module Kramdown
|
7
7
|
module PlantUml
|
8
8
|
# Logs stuff
|
9
|
-
class
|
9
|
+
class LogWrapper
|
10
10
|
def initialize(logger)
|
11
11
|
raise ArgumentError, 'logger cannot be nil' if logger.nil?
|
12
12
|
raise ArgumentError, 'logger must respond to #debug' unless logger.respond_to? :debug
|
@@ -52,8 +52,9 @@ module Kramdown
|
|
52
52
|
|
53
53
|
class << self
|
54
54
|
def init
|
55
|
-
inner = JekyllProvider.jekyll ? JekyllProvider.jekyll.logger : nil
|
56
|
-
|
55
|
+
inner = JekyllProvider.jekyll ? JekyllProvider.jekyll.logger : nil
|
56
|
+
inner ||= ConsoleLogger.new(level)
|
57
|
+
new inner
|
57
58
|
end
|
58
59
|
|
59
60
|
def level
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'log_wrapper'
|
4
|
+
|
5
|
+
module Kramdown
|
6
|
+
module PlantUml
|
7
|
+
# Options for PlantUML processing
|
8
|
+
class Options
|
9
|
+
attr_reader :theme_name, :theme_directory
|
10
|
+
|
11
|
+
def initialize(options_hash = {})
|
12
|
+
@logger = LogWrapper.init
|
13
|
+
@options = massage(options_hash)
|
14
|
+
@raise_errors = extract_raise_errors(@options)
|
15
|
+
extract_theme_options(@options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def raise_errors?
|
19
|
+
@raise_errors
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
@options
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def boolean(value, default_value)
|
29
|
+
return value if [true, false].include? value
|
30
|
+
return default_value if value.nil?
|
31
|
+
|
32
|
+
s = value.to_s.strip
|
33
|
+
return true if %w[true yes 1].select { |v| v.casecmp(s).zero? }.any?
|
34
|
+
return false if %w[false no 0].select { |v| v.casecmp(s).zero? }.any?
|
35
|
+
|
36
|
+
default_value
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract_plantuml_options(options_hash)
|
40
|
+
return options_hash[:plantuml] if options_hash.key?(:plantuml)
|
41
|
+
return options_hash['plantuml'] if options_hash.key?('plantuml')
|
42
|
+
|
43
|
+
{}
|
44
|
+
end
|
45
|
+
|
46
|
+
def extract_theme_options(options)
|
47
|
+
return if options.empty? || !options.key?(:theme)
|
48
|
+
|
49
|
+
theme = options[:theme] || {}
|
50
|
+
|
51
|
+
unless theme.is_a?(Hash)
|
52
|
+
@logger.warn ":theme is not a Hash: #{theme}"
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
56
|
+
@theme_name = theme.key?(:name) ? theme[:name] : nil
|
57
|
+
@theme_directory = theme.key?(:directory) ? theme[:directory] : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def extract_raise_errors(options)
|
61
|
+
if options.key?(:raise_errors)
|
62
|
+
raise_errors = options[:raise_errors]
|
63
|
+
return boolean(raise_errors, true)
|
64
|
+
end
|
65
|
+
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
def massage(options_hash)
|
70
|
+
if options_hash.nil? || !options_hash.is_a?(Hash) || options_hash.empty?
|
71
|
+
@logger.debug 'No options provided'
|
72
|
+
return {}
|
73
|
+
end
|
74
|
+
|
75
|
+
plantuml_options = extract_plantuml_options(options_hash)
|
76
|
+
symbolize_keys(plantuml_options)
|
77
|
+
end
|
78
|
+
|
79
|
+
def symbolize_keys(options)
|
80
|
+
return options if options.nil? || options.empty?
|
81
|
+
|
82
|
+
array = options.map do |key, value|
|
83
|
+
value = value.is_a?(Hash) ? symbolize_keys(value) : value
|
84
|
+
[key.to_sym, value]
|
85
|
+
end
|
86
|
+
|
87
|
+
array.to_h
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'log_wrapper'
|
4
4
|
require_relative 'plantuml_error'
|
5
5
|
require_relative 'diagram'
|
6
6
|
|
@@ -20,7 +20,7 @@ module Kramdown
|
|
20
20
|
@stdout = stdout
|
21
21
|
@stderr = stderr
|
22
22
|
@exitcode = exitcode
|
23
|
-
@logger =
|
23
|
+
@logger = LogWrapper.init
|
24
24
|
end
|
25
25
|
|
26
26
|
def without_xml_prologue
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'options'
|
4
|
+
require_relative 'log_wrapper'
|
5
|
+
require_relative 'jekyll_provider'
|
4
6
|
|
5
7
|
module Kramdown
|
6
8
|
module PlantUml
|
@@ -8,9 +10,14 @@ module Kramdown
|
|
8
10
|
class Theme
|
9
11
|
attr_reader :name, :directory
|
10
12
|
|
11
|
-
def initialize(options
|
12
|
-
|
13
|
-
|
13
|
+
def initialize(options)
|
14
|
+
raise ArgumentError, 'options cannot be nil' if options.nil?
|
15
|
+
raise ArgumentError, "options must be a '#{Options}'." unless options.is_a?(Options)
|
16
|
+
|
17
|
+
@raise_errors = options.raise_errors?
|
18
|
+
@logger = LogWrapper.init
|
19
|
+
@name = options.theme_name
|
20
|
+
@directory = resolve options.theme_directory
|
14
21
|
end
|
15
22
|
|
16
23
|
def apply(plantuml)
|
@@ -21,7 +28,7 @@ module Kramdown
|
|
21
28
|
|
22
29
|
if @name.nil? || @name.empty?
|
23
30
|
@logger.debug 'No theme to apply.'
|
24
|
-
return plantuml
|
31
|
+
return plantuml.strip
|
25
32
|
end
|
26
33
|
|
27
34
|
theme(plantuml)
|
@@ -29,29 +36,26 @@ module Kramdown
|
|
29
36
|
|
30
37
|
private
|
31
38
|
|
32
|
-
def
|
33
|
-
|
39
|
+
def resolve(directory)
|
40
|
+
jekyll = JekyllProvider
|
34
41
|
|
35
|
-
|
42
|
+
return directory if directory.nil? || directory.empty? || !jekyll.installed?
|
36
43
|
|
37
|
-
|
44
|
+
directory = File.absolute_path(directory, jekyll.site_destination_dir)
|
38
45
|
|
39
|
-
|
40
|
-
name = theme.key?(:name) ? theme[:name] : nil
|
41
|
-
directory = theme.key?(:directory) ? theme[:directory] : nil
|
46
|
+
log_or_raise "The theme directory '#{directory}' cannot be found" unless Dir.exist?(directory)
|
42
47
|
|
43
|
-
|
44
|
-
end
|
48
|
+
theme_path = File.join(directory, "puml-theme-#{@name}.puml")
|
45
49
|
|
46
|
-
|
47
|
-
return options if options.nil?
|
50
|
+
log_or_raise "The theme '#{theme_path}' cannot be found" unless File.exist?(theme_path)
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
directory
|
53
|
+
end
|
54
|
+
|
55
|
+
def log_or_raise(message)
|
56
|
+
raise IOError, message if @raise_errors
|
53
57
|
|
54
|
-
|
58
|
+
logger.warn message
|
55
59
|
end
|
56
60
|
|
57
61
|
def theme(plantuml)
|
@@ -69,7 +73,7 @@ module Kramdown
|
|
69
73
|
return plantuml.insert match.end(0), theme_string
|
70
74
|
end
|
71
75
|
|
72
|
-
plantuml
|
76
|
+
plantuml.strip
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# Mimics the `which` Unix utility
|
4
4
|
class Which
|
5
5
|
def self.which(cmd)
|
6
6
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
@@ -10,6 +10,7 @@ class Which
|
|
10
10
|
return exe if File.executable?(exe) && !File.directory?(exe)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
13
14
|
nil
|
14
15
|
end
|
15
16
|
end
|
data/lib/kramdown_html.rb
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'kramdown'
|
4
4
|
require 'kramdown-parser-gfm'
|
5
|
-
require_relative 'kramdown-plantuml/
|
5
|
+
require_relative 'kramdown-plantuml/log_wrapper'
|
6
6
|
require_relative 'kramdown-plantuml/plantuml_error'
|
7
|
+
require_relative 'kramdown-plantuml/options'
|
7
8
|
require_relative 'kramdown-plantuml/diagram'
|
8
9
|
require_relative 'kramdown-plantuml/jekyll_provider'
|
9
10
|
|
@@ -24,9 +25,10 @@ module Kramdown
|
|
24
25
|
# be copied to the assets directory before the PlantUML conversion can
|
25
26
|
# be performed. We therefore place a needle in the haystack that we will
|
26
27
|
# convert in the :site:pre_render hook.
|
27
|
-
|
28
|
+
options = ::Kramdown::PlantUml::Options.new(@options)
|
29
|
+
return jekyll.needle(element.value, options) if jekyll.installed?
|
28
30
|
|
29
|
-
convert_plantuml(element.value)
|
31
|
+
convert_plantuml(element.value, options)
|
30
32
|
end
|
31
33
|
|
32
34
|
private
|
@@ -35,11 +37,14 @@ module Kramdown
|
|
35
37
|
element.attr['class'] == 'language-plantuml'
|
36
38
|
end
|
37
39
|
|
38
|
-
def convert_plantuml(plantuml)
|
39
|
-
|
40
|
-
|
41
|
-
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, plantuml_options)
|
40
|
+
def convert_plantuml(plantuml, options)
|
41
|
+
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
|
42
42
|
diagram.convert_to_svg
|
43
|
+
rescue StandardError => e
|
44
|
+
raise e if options.raise_errors?
|
45
|
+
|
46
|
+
logger = ::Kramdown::PlantUml::LogWrapper.init
|
47
|
+
logger.error "Error while replacing needle: #{e.inspect}"
|
43
48
|
end
|
44
49
|
end
|
45
50
|
end
|
data/pom.xml
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.9
|
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-
|
11
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: htmlentities
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: kramdown
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,7 +180,7 @@ files:
|
|
166
180
|
- LICENSE
|
167
181
|
- README.md
|
168
182
|
- Rakefile
|
169
|
-
- bin/net/sourceforge/plantuml/plantuml/1.2021.
|
183
|
+
- bin/net/sourceforge/plantuml/plantuml/1.2021.12/plantuml-1.2021.12.jar
|
170
184
|
- kramdown-plantuml.gemspec
|
171
185
|
- lib/kramdown-plantuml.rb
|
172
186
|
- lib/kramdown-plantuml/bool_env.rb
|
@@ -174,13 +188,14 @@ files:
|
|
174
188
|
- lib/kramdown-plantuml/diagram.rb
|
175
189
|
- lib/kramdown-plantuml/executor.rb
|
176
190
|
- lib/kramdown-plantuml/jekyll_provider.rb
|
177
|
-
- lib/kramdown-plantuml/
|
191
|
+
- lib/kramdown-plantuml/log_wrapper.rb
|
192
|
+
- lib/kramdown-plantuml/options.rb
|
178
193
|
- lib/kramdown-plantuml/plantuml_error.rb
|
179
194
|
- lib/kramdown-plantuml/plantuml_result.rb
|
180
195
|
- lib/kramdown-plantuml/theme.rb
|
181
196
|
- lib/kramdown-plantuml/version.rb
|
197
|
+
- lib/kramdown-plantuml/which.rb
|
182
198
|
- lib/kramdown_html.rb
|
183
|
-
- lib/which.rb
|
184
199
|
- pom.xml
|
185
200
|
homepage: https://github.com/SwedbankPay/kramdown-plantuml
|
186
201
|
licenses:
|