kramdown-plantuml 1.3.1 → 1.3.2

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: a2a7f9fc36a5af2bb28cc4aa5a6dcf7313e8fbf4efad763783cf165ff4ca0192
4
- data.tar.gz: c6732b8d23e7edc5d89c4ca9bb4db9fbd5aeded25b76007bb2fa15a9c32ccdde
3
+ metadata.gz: 716bd98dfc84efc97e64f12e8c1f68c1ee7a982e1d1ea33eabdf0f74b4560c04
4
+ data.tar.gz: 56254a3d065d7c69f2744cca59d32974e37f3e773bceccc2c63ab8dc151a5ace
5
5
  SHA512:
6
- metadata.gz: f9f0d06fbf084ea9b93ef189a6c6c1b43dbc9b73abdfe4f46963b396bdf0e2e5f3340f047f32e75af488072120f76f470febdd3ab91b6d3d87dbd4173213ecca
7
- data.tar.gz: d9fd8d226b104f5ba77b6fd50e25add3c8261933a9841b0a454df231afa8d544583a2b584fbb5ac463e8c7526432cf2753f1fa9249d51c743c0a7890403099a5
6
+ metadata.gz: 4e19ff0d0e8b1b90f5a5e19595c95982c9e6c126b1b54b5238c0ee1ac81463aaf63350be0ea90c04844cbc7fca5c126cadd86fec50073ed9af0bf83b9800a706
7
+ data.tar.gz: c0dea81be5cd8bbf9c9541b4941cfd4c0ab05700a092a6b4672ec7adfe96f5e2212c22861dfcd0e86d1e90611b8bf2734da12d12b05853239ffa582b3b67bcc5
@@ -43,7 +43,7 @@ jobs:
43
43
  java-version: 14
44
44
 
45
45
  - name: Cache Maven dependencies
46
- uses: actions/cache@v2.1.6
46
+ uses: actions/cache@v2.1.7
47
47
  with:
48
48
  path: ~/.m2/repository
49
49
  key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
data/README.md CHANGED
@@ -127,7 +127,7 @@ kramdown:
127
127
  plantuml:
128
128
  theme:
129
129
  name: my-custom-theme
130
- directory: path/to/themes
130
+ directory: spec/examples
131
131
  ```
132
132
 
133
133
  ### Dimensions and Styling
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'log_wrapper'
4
- require_relative 'jekyll_page_processor'
5
4
 
6
5
  module Kramdown
7
6
  module PlantUml
8
7
  # Provides an instance of Jekyll if available.
9
8
  module JekyllProvider
10
9
  class << self
11
- attr_reader :site_destination_dir
10
+ attr_reader :site_source_dir
12
11
 
13
12
  def jekyll
14
13
  return @jekyll if defined? @jekyll
@@ -16,60 +15,17 @@ module Kramdown
16
15
  @jekyll = load_jekyll
17
16
  end
18
17
 
19
- def install
20
- return @installed = false if jekyll.nil?
21
-
22
- find_site_destination_dir
23
- register_hook
24
- @installed = true
25
- end
26
-
27
- def installed?
28
- @installed
29
- end
30
-
31
- def needle(plantuml, options)
32
- JekyllPageProcessor.needle(plantuml, options)
33
- end
34
-
35
18
  private
36
19
 
37
- def find_site_destination_dir
20
+ def find_site_source_dir
38
21
  if jekyll.sites.nil? || jekyll.sites.empty?
39
- logger.debug 'Jekyll detected, hooking into :site:post_write.'
22
+ logger.warn 'Jekyll detected, but no sites found.'
40
23
  return nil
41
24
  end
42
25
 
43
- @site_destination_dir = jekyll.sites.first.dest
44
- logger.debug "Jekyll detected, hooking into :site:post_write of '#{@site_destination_dir}'."
45
- @site_destination_dir
46
- end
47
-
48
- def register_hook
49
- Jekyll::Hooks.register :site, :post_write do |site|
50
- site_post_write(site)
51
- end
52
- end
53
-
54
- def site_post_write(site)
55
- logger.debug 'Jekyll:site:post_write triggered.'
56
- @site_destination_dir ||= site.dest
57
-
58
- site.pages.each do |page|
59
- processor = JekyllPageProcessor.new(page)
60
-
61
- next unless processor.should_process?
62
-
63
- processor.process(site.dest)
64
- end
65
-
66
- site.posts.each do |post|
67
- processor = JekyllPageProcessor.new(post)
68
-
69
- next unless processor.should_process?
70
-
71
- processor.process(site.dest)
72
- end
26
+ @site_source_dir = jekyll.sites.first.source
27
+ logger.debug "Jekyll detected, using '#{@site_source_dir}' as base directory."
28
+ @site_source_dir
73
29
  end
74
30
 
75
31
  def load_jekyll
@@ -18,7 +18,7 @@ module Kramdown
18
18
  raise ArgumentError, 'options cannot be nil' if options.nil?
19
19
  raise ArgumentError, "options must be a '#{Options}'." unless options.is_a?(Options)
20
20
 
21
- @plantuml = plantuml
21
+ @plantuml = plantuml.strip unless plantuml.nil?
22
22
  @options = options
23
23
  @theme = Theme.new(options)
24
24
  @logger = LogWrapper.init
@@ -35,9 +35,9 @@ module Kramdown
35
35
  def resolve(directory)
36
36
  jekyll = JekyllProvider
37
37
 
38
- return directory if directory.nil? || directory.empty? || !jekyll.installed?
38
+ return directory if directory.nil? || directory.empty?
39
39
 
40
- directory = File.absolute_path(directory, jekyll.site_destination_dir)
40
+ directory = File.absolute_path(directory, jekyll.site_source_dir)
41
41
 
42
42
  log_or_raise "The theme directory '#{directory}' cannot be found" unless Dir.exist?(directory)
43
43
 
@@ -51,7 +51,7 @@ module Kramdown
51
51
  def log_or_raise(message)
52
52
  raise IOError, message if @raise_errors
53
53
 
54
- logger.warn message
54
+ @logger.warn message
55
55
  end
56
56
 
57
57
  def theme(plantuml)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kramdown
4
4
  module PlantUml
5
- VERSION = '1.3.1'
5
+ VERSION = '1.3.2'
6
6
  end
7
7
  end
@@ -1,6 +1,3 @@
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
@@ -6,7 +6,6 @@ require_relative 'kramdown-plantuml/log_wrapper'
6
6
  require_relative 'kramdown-plantuml/plantuml_error'
7
7
  require_relative 'kramdown-plantuml/options'
8
8
  require_relative 'kramdown-plantuml/plantuml_diagram'
9
- require_relative 'kramdown-plantuml/jekyll_provider'
10
9
 
11
10
  module Kramdown
12
11
  module Converter
@@ -16,19 +15,9 @@ module Kramdown
16
15
  alias super_convert_codeblock convert_codeblock
17
16
 
18
17
  def convert_codeblock(element, indent)
19
- return super_convert_codeblock(element, indent) unless plantuml?(element)
18
+ return super_convert_codeblock(element, indent) unless plantuml? element
20
19
 
21
- jekyll = ::Kramdown::PlantUml::JekyllProvider
22
-
23
- # If Jekyll is successfully loaded, we'll wait with converting the
24
- # PlantUML diagram to SVG since a theme may be configured that needs to
25
- # be copied to the assets directory before the PlantUML conversion can
26
- # be performed. We therefore place a needle in the haystack that we will
27
- # convert in the :site:pre_render hook.
28
- options = ::Kramdown::PlantUml::Options.new(@options)
29
- return jekyll.needle(element.value, options) if jekyll.installed?
30
-
31
- convert_plantuml(element.value, options)
20
+ convert_plantuml(element.value)
32
21
  end
33
22
 
34
23
  private
@@ -37,14 +26,15 @@ module Kramdown
37
26
  element.attr['class'] == 'language-plantuml'
38
27
  end
39
28
 
40
- def convert_plantuml(plantuml, options)
41
- diagram = ::Kramdown::PlantUml::PlantUmlDiagram.new(plantuml, options)
29
+ def convert_plantuml(plantuml)
30
+ puml_opts = ::Kramdown::PlantUml::Options.new(@options)
31
+ diagram = ::Kramdown::PlantUml::PlantUmlDiagram.new(plantuml, puml_opts)
42
32
  diagram.svg.to_s
43
33
  rescue StandardError => e
44
- raise e if options.raise_errors?
34
+ raise e if puml_opts.nil? || puml_opts.raise_errors?
45
35
 
46
36
  logger = ::Kramdown::PlantUml::LogWrapper.init
47
- logger.error "Error while replacing needle: #{e.inspect}"
37
+ logger.error "Error while converting diagram: #{e.inspect}"
48
38
  end
49
39
  end
50
40
  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.14</version>
13
+ <version>1.2021.16</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.3.1
4
+ version: 1.3.2
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-19 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -194,13 +194,12 @@ files:
194
194
  - LICENSE
195
195
  - README.md
196
196
  - Rakefile
197
- - bin/net/sourceforge/plantuml/plantuml/1.2021.12/plantuml-1.2021.12.jar
197
+ - bin/net/sourceforge/plantuml/plantuml/1.2021.16/plantuml-1.2021.16.jar
198
198
  - kramdown-plantuml.gemspec
199
199
  - lib/kramdown-plantuml.rb
200
200
  - lib/kramdown-plantuml/bool_env.rb
201
201
  - lib/kramdown-plantuml/console_logger.rb
202
202
  - lib/kramdown-plantuml/executor.rb
203
- - lib/kramdown-plantuml/jekyll_page_processor.rb
204
203
  - lib/kramdown-plantuml/jekyll_provider.rb
205
204
  - lib/kramdown-plantuml/log_wrapper.rb
206
205
  - lib/kramdown-plantuml/none_s.rb
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'htmlentities'
4
- require 'json'
5
- require_relative 'log_wrapper'
6
-
7
- module Kramdown
8
- module PlantUml
9
- # Processes Jekyll pages.
10
- class JekyllPageProcessor
11
- PROCESSED_KEY = :kramdown_plantuml_processed
12
-
13
- def initialize(page)
14
- raise ArgumentError, 'page cannot be nil' if page.nil?
15
-
16
- @page = page
17
- end
18
-
19
- def process(site_destination_directory)
20
- @page.output = do_process
21
- @page.data[PROCESSED_KEY] = true
22
- @page.write(site_destination_directory)
23
- end
24
-
25
- def should_process?
26
- return false unless @page.output_ext == '.html'
27
-
28
- if !@page.data.nil? && @page.data.key?(PROCESSED_KEY) && @page.data[PROCESSED_KEY]
29
- logger.debug "Skipping #{@page.path} because it has already been processed."
30
- return false
31
- end
32
-
33
- true
34
- end
35
-
36
- class << self
37
- def needle(plantuml, options)
38
- hash = { 'plantuml' => plantuml, 'options' => options.to_h }
39
-
40
- <<~NEEDLE
41
- <!--#kramdown-plantuml.start#-->
42
- #{hash.to_json}
43
- <!--#kramdown-plantuml.end#-->
44
- NEEDLE
45
- rescue StandardError => e
46
- raise e if options.nil? || options.raise_errors?
47
-
48
- logger.error 'Error while placing needle.'
49
- logger.error e.to_s
50
- logger.debug_multiline plantuml
51
- end
52
-
53
- def logger
54
- @logger ||= ::Kramdown::PlantUml::LogWrapper.init
55
- end
56
- end
57
-
58
- private
59
-
60
- def do_process
61
- logger.debug "Replacing Jekyll needles in #{@page.path}"
62
-
63
- html = @page.output
64
-
65
- return html if html.nil? || html.empty? || !html.is_a?(String)
66
-
67
- html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
68
- json = $LAST_MATCH_INFO ? $LAST_MATCH_INFO[:json] : nil
69
- replace_needle(json) unless json.nil?
70
- end
71
- end
72
-
73
- def replace_needle(json)
74
- logger.debug 'Replacing Jekyll needle.'
75
-
76
- needle_hash = JSON.parse(json)
77
- options_hash = needle_hash['options']
78
- options = ::Kramdown::PlantUml::Options.new({ plantuml: options_hash })
79
-
80
- begin
81
- decode_and_convert(needle_hash, options)
82
- rescue StandardError => e
83
- raise e if options.raise_errors?
84
-
85
- logger.error 'Error while replacing Jekyll needle.'
86
- logger.error e.to_s
87
- logger.debug_multiline json
88
- end
89
- end
90
-
91
- def decode_and_convert(hash, options)
92
- encoded_plantuml = hash['plantuml']
93
- plantuml = HTMLEntities.new.decode encoded_plantuml
94
- diagram = ::Kramdown::PlantUml::PlantUmlDiagram.new(plantuml, options)
95
- diagram.svg
96
- end
97
-
98
- def logger
99
- @logger ||= ::Kramdown::PlantUml::LogWrapper.init
100
- end
101
- end
102
- end
103
- end