kramdown-plantuml 1.1.4 → 1.1.5

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
2
  SHA256:
3
- metadata.gz: beba25f229338deced9900f7a611c9040846e562c966de164e88dbb040acadde
4
- data.tar.gz: 8c2aa7aa04a1a6e59a98032e1cc325544a2be7c3bc3cd407cbb3af09babe390c
3
+ metadata.gz: 3968b5c182c334e7dbe020e7cd02309f6349fedeab4c6011b63178aa570b5c7f
4
+ data.tar.gz: 804e7e4c062c10f1f1c7578c338a8b19ec70a23031081a129f90dc44fa087926
5
5
  SHA512:
6
- metadata.gz: fcdfa9c61a9b2c751aeae743edfb58d81c3602e1eb62f6b8993fd11b2372dd6ee271f77737f655967a093c03a90d0ebf3b4865c703b7a5ed2d7b806c5a4d19d5
7
- data.tar.gz: d35a3daea2ab515d0fd788d8b2fb0575c4993e4f25ba3c7ebda02631b8ae8d397dc88917b3809cf732e9b9a5d16bbbfa52cdfa2095a682c68de8d6ed8fba3377
6
+ metadata.gz: ad3f371c0c4608c8d613ba9ec73414f6eea92c8eccf9a087fe7ccc487403b4742afc68c63574937aaf8ea30c9f90aaf56b7e5636764647b442137e7a683cbecd
7
+ data.tar.gz: c437216460a278794c2caeb20c151c5c2a98cce5d5a72e2a4d1b1fb077cc970ceb50fbb0fb3d832b92a7991d35b36776e019a295cbe9884ff928fee073dd9938
data/.github/mergify.yml CHANGED
@@ -17,6 +17,7 @@ pull_request_rules:
17
17
  - name: Thank contributor
18
18
  conditions:
19
19
  - merged
20
+ - -author~=^.*\[bot\]$
20
21
  actions:
21
22
  comment:
22
23
  message: "Thank you @{{author}} for your contribution!"
@@ -1,6 +1,73 @@
1
1
  #!/usr/bin/env bash
2
2
  set -o errexit # Abort if any command fails
3
3
 
4
- gem_build_name=$(gem build kramdown-plantuml.gemspec | awk '/File/ {print $2}')
5
- echo "Gem filename: '${gem_build_name}'"
6
- echo "::set-output name=name::${gem_build_name}"
4
+ me=$(basename "$0")
5
+ help_message="\
6
+ Usage:
7
+ ${me} [--ref <ref>] [--verbose]
8
+ ${me} --help
9
+ Arguments:
10
+ -r, --ref The Git reference that is being built.
11
+ -h, --help Displays this help screen.
12
+ -v, --verbose Increase verbosity. Useful for debugging."
13
+
14
+ parse_args() {
15
+ while : ; do
16
+ if [[ $1 = "-h" || $1 = "--help" ]]; then
17
+ echo "${help_message}"
18
+ return 0
19
+ elif [[ $1 = "-v" || $1 = "--verbose" ]]; then
20
+ verbose=true
21
+ shift
22
+ elif [[ $1 = "-r" || $1 = "--ref" ]]; then
23
+ ref=${2// }
24
+
25
+ if [[ "${ref}" = "--"* ]]; then
26
+ ref=""
27
+ shift 1
28
+ else
29
+ shift 2
30
+ fi
31
+ else
32
+ break
33
+ fi
34
+ done
35
+ }
36
+
37
+ # Echo expanded commands as they are executed (for debugging)
38
+ enable_expanded_output() {
39
+ if [ "${verbose}" = true ]; then
40
+ set -o xtrace
41
+ set +o verbose
42
+ export VERBOSE=true
43
+ fi
44
+ }
45
+
46
+ add_coverage() {
47
+ # If we're not building a tag, bootstrap code coverage.
48
+ if [[ "${ref}" != "refs/tags/"* ]]; then
49
+ [[ "${verbose}" = true ]] && echo "Bootstrapping code coverage."
50
+ export COVER=true
51
+ export COVERAGE=true
52
+ printf "require 'simplecov'\nSimpleCov.start\n" >> lib/kramdown-plantuml.rb
53
+ elif [[ "${verbose}" = true ]]; then
54
+ echo "Skipping coverage report since a tag ref was pushed."
55
+ fi
56
+ }
57
+
58
+ build_gem() {
59
+ gem_build_name=$(gem build kramdown-plantuml.gemspec | awk '/File/ {print $2}')
60
+
61
+ [[ "${verbose}" = true ]] && echo "Gem filename: '${gem_build_name}'"
62
+
63
+ echo "::set-output name=name::${gem_build_name}"
64
+ }
65
+
66
+ main() {
67
+ parse_args "$@"
68
+ enable_expanded_output
69
+ add_coverage
70
+ build_gem
71
+ }
72
+
73
+ main "$@"
@@ -6,7 +6,7 @@ me=$(basename "$0")
6
6
 
7
7
  help_message="\
8
8
  Usage:
9
- ${me} --workdir <workdir> [--gemdir <gemdir> | --version <version> --token <token>] [--verbose]
9
+ ${me} --workdir <workdir> [--gemdir <gemdir> | --version <version> --token <token>] [--verbose] [--theme <name> [--theme-directory <path>]]
10
10
  ${me} --help
11
11
  Arguments:
12
12
  -w, --workdir <workdir> The path to the working directory.
@@ -14,6 +14,8 @@ Arguments:
14
14
  -v, --version <version> The version of the Gem to test.
15
15
  -t, --token <token> The GitHub token to use for retrieving the gem
16
16
  from the GitHub Package Registry.
17
+ -T, --theme-name <name> The theme name to use for the test.
18
+ -p, --theme-directory <path> The directory in which the [--theme-name] is placed.
17
19
  -h, --help Displays this help screen.
18
20
  -v, --verbose Increase verbosity. Useful for debugging."
19
21
 
@@ -52,6 +54,24 @@ parse_args() {
52
54
  else
53
55
  shift 2
54
56
  fi
57
+ elif [[ $1 = "-T" || $1 = "--theme-name" ]]; then
58
+ theme_name=${2// }
59
+
60
+ if [[ "${theme_name}" = "--"* ]]; then
61
+ theme_name=""
62
+ shift 1
63
+ else
64
+ shift 2
65
+ fi
66
+ elif [[ $1 = "-p" || $1 = "--theme-directory" ]]; then
67
+ theme_directory=${2// }
68
+
69
+ if [[ "${theme_directory}" = "--"* ]]; then
70
+ theme_directory=""
71
+ shift 1
72
+ else
73
+ shift 2
74
+ fi
55
75
  elif [[ $1 = "-w" || $1 = "--workdir" ]]; then
56
76
  workdir=${2// }
57
77
 
@@ -67,22 +87,29 @@ parse_args() {
67
87
  done
68
88
 
69
89
  if [[ -z "${workdir}" ]]; then
70
- echo "Missing required argument: --workdir <workdir>."
71
- echo "${help_message}"
90
+ echo "Missing required argument: --workdir <workdir>." >&2
91
+ echo "${help_message}" >&2
72
92
  return 1
73
93
  fi
74
94
 
75
95
  if [[ (-z "${gemdir}" && -z "${token}") || (-n "${gemdir}" && -n "${token}") ]]; then
76
- echo "Missing or invalid required arguments: --gemdir <gem-path> or --token <token>."
77
- echo "Either [--gemdir] or [--token] needs to be provided, but not both."
96
+ echo "Missing or invalid required arguments: --gemdir <gem-path> or --token <token>." >&2
97
+ echo "Either [--gemdir] or [--token] needs to be provided, but not both." >&2
78
98
  echo "${help_message}"
79
99
  return 1
80
100
  fi
81
101
 
82
102
  if [[ (-n "${version}" && -z "${token}") || (-z "${version}" && -n "${token}") ]]; then
83
- echo "Missing or invalid required arguments: --version <gem-path> and --token <token>."
84
- echo "When either argument is present, both must be."
85
- echo "${help_message}"
103
+ echo "Missing or invalid required arguments: --version <gem-path> and --token <token>." >&2
104
+ echo "When either argument is present, both must be." >&2
105
+ echo "${help_message}" >&2
106
+ return 1
107
+ fi
108
+
109
+ if [[ -z "${theme_name}" && -n "${theme_directory}" ]]; then
110
+ echo "Missing or invalid required arguments: --theme-name <name>." >&2
111
+ echo "[--theme-name] is required when [--theme-directory] is provided." >&2
112
+ echo "${help_message}" >&2
86
113
  return 1
87
114
  fi
88
115
  }
@@ -101,26 +128,47 @@ test_gem() {
101
128
 
102
129
  cd "${workdir}"
103
130
 
131
+ # Recreate Gemfile
132
+ printf "# frozen_string_literal: true\nsource 'https://rubygems.org'\ngem 'jekyll'\ngem 'simplecov'\n" > Gemfile
133
+
104
134
  if [[ -n "${token}" ]]; then
105
135
  # A non-empty $token means we should install the Gem from GPR
106
136
  repository="https://rubygems.pkg.github.com/swedbankpay"
107
137
  bundle config "${repository}" "SwedbankPay:${token}"
108
- printf "source '%s' do\n\tgem 'kramdown-plantuml', '%s'\nend" "${repository}" "${version}" >> Gemfile
138
+ printf "source '%s' do\n\tgem 'kramdown-plantuml', '%s'\nend\n" "${repository}" "${version}" >> Gemfile
109
139
  else
110
- echo "gem 'kramdown-plantuml', path: '${gemdir}'" >> Gemfile
140
+ printf "gem 'kramdown-plantuml', path: '%s'\n" "${gemdir}" >> Gemfile
141
+ fi
142
+
143
+ # Recreate _config.yml
144
+ printf "plugins:\n- kramdown-plantuml\n" > _config.yml
145
+
146
+ if [[ -n "${theme_name}" ]]; then
147
+ printf "kramdown:\n plantuml:\n theme:\n name: %s\n" "${theme_name}" >> _config.yml
148
+ class="plantuml theme-${theme_name}"
149
+ else
150
+ class='plantuml'
151
+ fi
152
+
153
+ if [[ -n "${theme_directory}" ]]; then
154
+ printf " directory: %s\n" "${theme_directory}" >> _config.yml
111
155
  fi
112
156
 
113
157
  if [[ "${verbose}" = true ]]; then
158
+ printf "\nGemfile:\n"
114
159
  cat Gemfile
160
+ printf "\n_config.yml\n"
161
+ cat _config.yml
115
162
  jekyll_build_args+=(--verbose)
116
163
  fi
117
164
 
118
165
  bundle install
119
166
  bundle exec jekyll build "${jekyll_build_args[@]}"
120
167
 
168
+
121
169
  file="${workdir}/_site/index.html"
122
170
 
123
- file_contains "${file}" "class=\"plantuml theme-spacelab\""
171
+ file_contains "${file}" "class=\"${class}\""
124
172
  file_contains "${file}" "<svg"
125
173
  file_contains "${file}" "<ellipse"
126
174
  file_contains "${file}" "<polygon"
@@ -96,13 +96,22 @@ jobs:
96
96
  DEBUG: 1
97
97
  run: bundle exec rspec --tag debug
98
98
 
99
+ - name: Upload code coverage (debug)
100
+ uses: actions/upload-artifact@v2
101
+ with:
102
+ name: rspec-debug-coverage
103
+ path: ./coverage
104
+
105
+ - name: Codecov upload (debug)
106
+ run: bundle exec rake codecov:upload || echo 'Codecov upload failed'
107
+
99
108
  - name: Test with Rake
100
109
  run: bundle exec rake
101
110
 
102
111
  - name: Upload code coverage
103
112
  uses: actions/upload-artifact@v2
104
113
  with:
105
- name: coverage
114
+ name: rspec-coverage
106
115
  path: ./coverage
107
116
 
108
117
  - name: Codecov upload
@@ -110,7 +119,7 @@ jobs:
110
119
 
111
120
  - name: Build gem
112
121
  id: gem
113
- run: .github/scripts/build-gem.sh
122
+ run: .github/scripts/build-gem.sh --ref ${{ github.ref }} --verbose
114
123
 
115
124
  - name: Upload gem
116
125
  uses: actions/upload-artifact@v2-preview
@@ -122,7 +131,16 @@ jobs:
122
131
  run: .github/scripts/inspect-gem.sh --gem "${{ github.workspace }}/${{ steps.gem.outputs.name }}" --verbose
123
132
 
124
133
  - name: Test gem
125
- run: .github/scripts/test-gem.sh --workdir "${{ github.workspace }}/spec/fixture" --gemdir "${{ github.workspace }}" --verbose
134
+ run: .github/scripts/test-gem.sh --workdir "${{ github.workspace }}/spec/examples" --gemdir "${{ github.workspace }}" --verbose
135
+
136
+ - name: Upload code coverage (gem)
137
+ uses: actions/upload-artifact@v2
138
+ with:
139
+ name: gem-coverage
140
+ path: ./coverage
141
+
142
+ - name: Codecov upload (gem)
143
+ run: bundle exec rake codecov:upload || echo 'Codecov upload failed'
126
144
 
127
145
  publish-dev:
128
146
  needs: [version, gem]
@@ -156,15 +174,21 @@ jobs:
156
174
  - name: Publish to GPR
157
175
  run: .github/scripts/publish-gem.sh --gem ${{ needs.gem.outputs.name }} --token "${{ secrets.GPR_TOKEN }}" --owner SwedbankPay --verbose
158
176
 
159
- - name: Test gem
160
- run: .github/scripts/test-gem.sh --workdir "${{ github.workspace }}/spec/fixture" --version ${{ needs.version.outputs.version }} --token "${{ secrets.GPR_TOKEN }}" --verbose
177
+ - name: Test gem (no theme)
178
+ run: .github/scripts/test-gem.sh --workdir "${{ github.workspace }}/spec/examples" --version ${{ needs.version.outputs.version }} --token "${{ secrets.GPR_TOKEN }}" --verbose
179
+
180
+ - name: Test gem (built-in theme)
181
+ run: .github/scripts/test-gem.sh --workdir "${{ github.workspace }}/spec/examples" --version ${{ needs.version.outputs.version }} --token "${{ secrets.GPR_TOKEN }}" --verbose --theme-name spacelab
182
+
183
+ - name: Test gem (custom theme)
184
+ run: .github/scripts/test-gem.sh --workdir "${{ github.workspace }}/spec/examples" --version ${{ needs.version.outputs.version }} --token "${{ secrets.GPR_TOKEN }}" --verbose --theme-name c2a3b0 --theme-directory "${{ github.workspace }}/spec/examples"
161
185
 
162
186
  - name: Upload Jekyll site
163
187
  uses: actions/upload-artifact@v2-preview
164
188
  if: always()
165
189
  with:
166
190
  name: site
167
- path: ${{ github.workspace }}/spec/fixture/_site
191
+ path: ${{ github.workspace }}/spec/examples/_site
168
192
 
169
193
  publish-prod:
170
194
  needs: [version, gem]
data/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  [![No PlantUML][no-plantuml-badge]][no-plantuml-workflow]
7
7
  [![Shell][shell-badge]][shell-workflow]
8
8
  [![Codecov][codecov-badge]][codecov]
9
+ [![Codacy Badge][codacy-badge]][codacy]
9
10
  [![License][license-badge]][license]
10
11
  [![CLA assistant][cla-badge]][cla]
11
12
  [![Contributor Covenant][coc-badge]][coc]
@@ -180,6 +181,8 @@ agreement][cla].
180
181
  [clone]: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository
181
182
  [coc-badge]: https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg
182
183
  [coc]: ./CODE_OF_CONDUCT.md
184
+ [codacy-badge]: https://app.codacy.com/project/badge/Grade/de72385f4ca444c18819a3ce8a506638
185
+ [codacy]: https://www.codacy.com/gh/SwedbankPay/kramdown-plantuml/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=SwedbankPay/kramdown-plantuml&amp;utm_campaign=Badge_Grade
183
186
  [codecov-badge]: https://codecov.io/gh/SwedbankPay/kramdown-plantuml/branch/main/graph/badge.svg?token=U3QJLVG3HY
184
187
  [codecov]: https://codecov.io/gh/SwedbankPay/kramdown-plantuml/
185
188
  [diagram-svg]: ./spec/examples/diagram.svg
@@ -17,15 +17,12 @@ module Kramdown
17
17
  @theme = Theme.new(options || {})
18
18
  @logger = Logger.init
19
19
  @executor = Executor.new
20
+ @logger.warn 'PlantUML diagram is empty' if @plantuml.nil? || @plantuml.empty?
20
21
  end
21
22
 
22
23
  def convert_to_svg
23
24
  return @svg unless @svg.nil?
24
-
25
- if @plantuml.nil? || @plantuml.empty?
26
- @logger.warn ' kramdown-plantuml: PlantUML diagram is empty'
27
- return @plantuml
28
- end
25
+ return @plantuml if @plantuml.nil? || @plantuml.empty?
29
26
 
30
27
  @plantuml = @theme.apply(@plantuml)
31
28
  @plantuml = plantuml.strip
@@ -49,8 +46,8 @@ module Kramdown
49
46
  end
50
47
 
51
48
  def log(plantuml)
52
- @logger.debug ' kramdown-plantuml: PlantUML converting diagram:'
53
- @logger.debug_with_prefix ' kramdown-plantuml: ', plantuml
49
+ @logger.debug 'PlantUML converting diagram:'
50
+ @logger.debug_multiline plantuml
54
51
  end
55
52
  end
56
53
  end
@@ -24,11 +24,11 @@ module Kramdown
24
24
 
25
25
  cmd = "java -Djava.awt.headless=true -jar #{@plantuml_jar_file} -tsvg -failfast -pipe #{debug_args}"
26
26
 
27
- @logger.debug " kramdown-plantuml: Executing '#{cmd}'."
27
+ @logger.debug "Executing '#{cmd}'."
28
28
 
29
29
  stdout, stderr, status = Open3.capture3 cmd, stdin_data: diagram.plantuml
30
30
 
31
- @logger.debug " kramdown-plantuml: PlantUML exit code '#{status.exitstatus}'."
31
+ @logger.debug "PlantUML exit code '#{status.exitstatus}'."
32
32
 
33
33
  PlantUmlResult.new(diagram, stdout, stderr, status.exitstatus)
34
34
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'English'
5
+ require_relative 'logger'
6
+ require_relative 'diagram'
7
+
8
+ module Kramdown
9
+ module PlantUml
10
+ # Provides an instance of Jekyll if available.
11
+ module JekyllProvider
12
+ class << self
13
+ def jekyll
14
+ return @jekyll if defined? @jekyll
15
+
16
+ @jekyll = load_jekyll
17
+ end
18
+
19
+ def install
20
+ return @installed = false if jekyll.nil?
21
+
22
+ logger.debug 'Jekyll detected, hooking into :site:post_render'
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
+
32
+ @installed = true
33
+ end
34
+
35
+ def installed?
36
+ @installed
37
+ end
38
+
39
+ def needle(plantuml, options)
40
+ plantuml_options = !options.nil? && options.key?(:plantuml) ? options[:plantuml] : nil
41
+ hash = { 'plantuml' => plantuml, 'options' => plantuml_options }
42
+
43
+ <<~NEEDLE
44
+ <!--#kramdown-plantuml.start#-->
45
+ #{hash.to_json}
46
+ <!--#kramdown-plantuml.end#-->
47
+ NEEDLE
48
+ end
49
+
50
+ private
51
+
52
+ def replace_needles(html)
53
+ html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
54
+ json = $LAST_MATCH_INFO[:json]
55
+ hash = JSON.parse(json)
56
+ plantuml = hash['plantuml']
57
+ options = hash['options']
58
+ diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
59
+ return diagram.convert_to_svg
60
+ end
61
+ end
62
+
63
+ def load_jekyll
64
+ require 'jekyll'
65
+ ::Jekyll
66
+ rescue LoadError
67
+ nil
68
+ end
69
+
70
+ def logger
71
+ @logger ||= ::Kramdown::PlantUml::Logger.init
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'console_logger'
4
+ require_relative 'jekyll_provider'
4
5
 
5
6
  module Kramdown
6
7
  module PlantUml
@@ -17,28 +18,28 @@ module Kramdown
17
18
  end
18
19
 
19
20
  def debug(message)
20
- @logger.debug message
21
+ write :debug, message
21
22
  end
22
23
 
23
- def debug_with_prefix(prefix, multiline_string)
24
+ def debug_multiline(multiline_string)
24
25
  return if multiline_string.nil? || multiline_string.empty?
25
26
 
26
27
  lines = multiline_string.lines
27
28
  lines.each do |line|
28
- @logger.debug "#{prefix}#{line.rstrip}"
29
+ write :debug, line.rstrip
29
30
  end
30
31
  end
31
32
 
32
33
  def info(message)
33
- @logger.info message
34
+ write :info, message
34
35
  end
35
36
 
36
37
  def warn(message)
37
- @logger.warn message
38
+ write :warn, message
38
39
  end
39
40
 
40
41
  def error(message)
41
- @logger.error message
42
+ write :error, message
42
43
  end
43
44
 
44
45
  def debug?
@@ -51,15 +52,7 @@ module Kramdown
51
52
 
52
53
  class << self
53
54
  def init
54
- inner = nil
55
-
56
- begin
57
- require 'jekyll'
58
- inner = Jekyll.logger
59
- rescue LoadError
60
- inner = ConsoleLogger.new level
61
- end
62
-
55
+ inner = JekyllProvider.jekyll ? JekyllProvider.jekyll.logger : nil || ConsoleLogger.new(level)
63
56
  Logger.new inner
64
57
  end
65
58
 
@@ -79,6 +72,10 @@ module Kramdown
79
72
 
80
73
  private
81
74
 
75
+ def write(level, message)
76
+ @logger.public_send(level, " kramdown-plantuml: #{message}")
77
+ end
78
+
82
79
  def level_from_logger
83
80
  return @logger.level if @logger.respond_to? :level
84
81
 
@@ -58,8 +58,8 @@ module Kramdown
58
58
 
59
59
  return if @stderr.nil? || @stderr.empty?
60
60
 
61
- @logger.debug ' kramdown-plantuml: PlantUML log:'
62
- @logger.debug_with_prefix ' kramdown-plantuml: ', @stderr
61
+ @logger.debug 'PlantUML log:'
62
+ @logger.debug_multiline @stderr
63
63
  end
64
64
  end
65
65
  end
@@ -15,12 +15,12 @@ module Kramdown
15
15
 
16
16
  def apply(plantuml)
17
17
  if plantuml.nil? || !plantuml.is_a?(String) || plantuml.empty?
18
- @logger.debug ' kramdown-plantuml: Empty diagram or not a String.'
18
+ @logger.debug 'Empty diagram or not a String.'
19
19
  return plantuml
20
20
  end
21
21
 
22
22
  if @name.nil? || @name.empty?
23
- @logger.debug ' kramdown-plantuml: No theme to apply.'
23
+ @logger.debug 'No theme to apply.'
24
24
  return plantuml
25
25
  end
26
26
 
@@ -32,7 +32,7 @@ module Kramdown
32
32
  def theme_options(options)
33
33
  options = symbolize_keys(options)
34
34
 
35
- @logger.debug " kramdown-plantuml: Options: #{options}"
35
+ @logger.debug "Options: #{options}"
36
36
 
37
37
  return nil if options.nil? || !options.key?(:theme)
38
38
 
@@ -63,7 +63,7 @@ module Kramdown
63
63
  theme_string = "\n!theme #{@name}"
64
64
  theme_string << " from #{@directory}" unless @directory.nil?
65
65
 
66
- @logger.debug " kramdown-plantuml: Applying #{theme_string.strip}"
66
+ @logger.debug "Applying #{theme_string.strip}"
67
67
 
68
68
  /@startuml.*/.match(plantuml) do |match|
69
69
  return plantuml.insert match.end(0), theme_string
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kramdown
4
4
  module PlantUml
5
- VERSION = '1.1.4'
5
+ VERSION = '1.1.5'
6
6
  end
7
7
  end
@@ -1,3 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'kramdown_html'
4
+ require_relative 'kramdown-plantuml/jekyll_provider'
5
+
6
+ ::Kramdown::PlantUml::JekyllProvider.install
data/lib/kramdown_html.rb CHANGED
@@ -5,6 +5,7 @@ require 'kramdown-parser-gfm'
5
5
  require_relative 'kramdown-plantuml/logger'
6
6
  require_relative 'kramdown-plantuml/plantuml_error'
7
7
  require_relative 'kramdown-plantuml/diagram'
8
+ require_relative 'kramdown-plantuml/jekyll_provider'
8
9
 
9
10
  module Kramdown
10
11
  module Converter
@@ -14,10 +15,29 @@ module Kramdown
14
15
  alias super_convert_codeblock convert_codeblock
15
16
 
16
17
  def convert_codeblock(element, indent)
17
- return super_convert_codeblock(element, indent) if element.attr['class'] != 'language-plantuml'
18
+ return super_convert_codeblock(element, indent) unless plantuml?(element)
18
19
 
19
- plantuml = element.value
20
+ jekyll = ::Kramdown::PlantUml::JekyllProvider
21
+
22
+ # If Jekyll is successfully loaded, we'll wait with converting the
23
+ # PlantUML diagram to SVG since a theme may be configured that needs to
24
+ # be copied to the assets directory before the PlantUML conversion can
25
+ # be performed. We therefore place a needle in the haystack that we will
26
+ # convert in the :site:pre_render hook.
27
+ return jekyll.needle(element.value, @options) if jekyll.installed?
28
+
29
+ convert_plantuml(element.value)
30
+ end
31
+
32
+ private
33
+
34
+ def plantuml?(element)
35
+ element.attr['class'] == 'language-plantuml'
36
+ end
37
+
38
+ def convert_plantuml(plantuml)
20
39
  plantuml_options = @options.key?(:plantuml) ? @options[:plantuml] : {}
40
+
21
41
  diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, plantuml_options)
22
42
  diagram.convert_to_svg
23
43
  end
data/pom.xml CHANGED
@@ -10,7 +10,7 @@
10
10
  <dependency>
11
11
  <groupId>net.sourceforge.plantuml</groupId>
12
12
  <artifactId>plantuml</artifactId>
13
- <version>1.2021.9</version>
13
+ <version>1.2021.10</version>
14
14
  </dependency>
15
15
  </dependencies>
16
16
  </project>
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
4
+ version: 1.1.5
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-30 00:00:00.000000000 Z
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -166,13 +166,14 @@ files:
166
166
  - LICENSE
167
167
  - README.md
168
168
  - Rakefile
169
- - bin/net/sourceforge/plantuml/plantuml/1.2021.9/plantuml-1.2021.9.jar
169
+ - bin/net/sourceforge/plantuml/plantuml/1.2021.10/plantuml-1.2021.10.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
174
  - lib/kramdown-plantuml/diagram.rb
175
175
  - lib/kramdown-plantuml/executor.rb
176
+ - lib/kramdown-plantuml/jekyll_provider.rb
176
177
  - lib/kramdown-plantuml/logger.rb
177
178
  - lib/kramdown-plantuml/plantuml_error.rb
178
179
  - lib/kramdown-plantuml/plantuml_result.rb