kramdown-plantuml 1.1.9 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ffc24d5b020aac9204946744f85793d0ae07da2fe95a27b9301f104aee78c13
4
- data.tar.gz: 83ae8392c10526f3382d327497fee2b85c297f9eb7599798f1e789f947084800
3
+ metadata.gz: af8b7df3676e0e2a57ebe8e4fc96f0e51388036d7910c9547bbd73f75b9ebde0
4
+ data.tar.gz: 1dc627d6d92fd81bd88a2ad7b9bc31f11a319117e734bff80d3e49651be07979
5
5
  SHA512:
6
- metadata.gz: 38a1e20a6a08fc178d25737ff9443fecfd8f48bbbc10f1b69eda8fd929f472a05f39150ad91d17cbaf94285757c156101510c16346aecee06f7a712e74c9908b
7
- data.tar.gz: 9d6d3192043170c20829ab97fc5513bc392d5eb8af92eb8017042d6ebbd19000730427a5b8c3ac3809095d4a8ec74945424fe854c0d1667ecce1340b3e88b78a
6
+ metadata.gz: 6e7fd6b35fe88507e326370e901b1cc02b7801e1b1a82d2510fa4f3cb41528a43e4465d4c44336ce05ae292a3bc4d1f11b3a382bc779e648c73aab70a33384ea
7
+ data.tar.gz: 919450a3b77827d699c2c071c161d7bb29cc7400e6bb108cc6f745e7e8980137174767e208d3cfae2c72ba9701fcc346415d2ee348817f79f4391e3d0ae39162
@@ -167,6 +167,7 @@ test_gem() {
167
167
 
168
168
  file="${workdir}/_site/index.html"
169
169
 
170
+ file_contains "${file}" "This is a fixture"
170
171
  file_contains "${file}" "class=\"${class}\""
171
172
  file_contains "${file}" "<svg"
172
173
  file_contains "${file}" "<ellipse"
@@ -0,0 +1,103 @@
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::Diagram.new(plantuml, options)
95
+ diagram.convert_to_svg
96
+ end
97
+
98
+ def logger
99
+ @logger ||= ::Kramdown::PlantUml::LogWrapper.init
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,10 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'English'
5
- require 'htmlentities'
6
3
  require_relative 'log_wrapper'
7
- require_relative 'diagram'
4
+ require_relative 'jekyll_page_processor'
8
5
 
9
6
  module Kramdown
10
7
  module PlantUml
@@ -32,20 +29,7 @@ module Kramdown
32
29
  end
33
30
 
34
31
  def needle(plantuml, options)
35
- hash = { 'plantuml' => plantuml, 'options' => options.to_h }
36
-
37
- <<~NEEDLE
38
- <!--#kramdown-plantuml.start#-->
39
- #{hash.to_json}
40
- <!--#kramdown-plantuml.end#-->
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
32
+ JekyllPageProcessor.needle(plantuml, options)
49
33
  end
50
34
 
51
35
  private
@@ -63,55 +47,23 @@ module Kramdown
63
47
 
64
48
  def register_hook
65
49
  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
50
+ site_post_write(site)
74
51
  end
75
52
  end
76
53
 
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)
54
+ def site_post_write(site)
55
+ logger.debug 'Jekyll:site:post_write triggered.'
56
+ @site_destination_dir ||= site.dest
82
57
 
83
- html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
84
- json = $LAST_MATCH_INFO[:json]
85
- return replace_needle(json)
86
- end
87
- end
58
+ site.pages.each do |page|
59
+ processor = JekyllPageProcessor.new(page)
88
60
 
89
- def replace_needle(json)
90
- logger.debug 'Replacing Jekyll needle.'
61
+ next unless processor.should_process?
91
62
 
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
63
+ processor.process(site.dest)
105
64
  end
106
65
  end
107
66
 
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
-
115
67
  def load_jekyll
116
68
  require 'jekyll'
117
69
  ::Jekyll
@@ -10,7 +10,7 @@ module Kramdown
10
10
 
11
11
  def initialize(options_hash = {})
12
12
  @logger = LogWrapper.init
13
- @options = massage(options_hash)
13
+ @options = massage(options_hash) || {}
14
14
  @raise_errors = extract_raise_errors(@options)
15
15
  extract_theme_options(@options)
16
16
  end
@@ -44,9 +44,9 @@ module Kramdown
44
44
  end
45
45
 
46
46
  def extract_theme_options(options)
47
- return if options.empty? || !options.key?(:theme)
47
+ return if options.nil? || options.empty? || !options.key?(:theme)
48
48
 
49
- theme = options[:theme] || {}
49
+ theme = options[:theme]
50
50
 
51
51
  unless theme.is_a?(Hash)
52
52
  @logger.warn ":theme is not a Hash: #{theme}"
@@ -58,12 +58,10 @@ module Kramdown
58
58
  end
59
59
 
60
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
61
+ return true if options.nil? || options.empty? || !options.key?(:raise_errors)
65
62
 
66
- true
63
+ raise_errors = options[:raise_errors]
64
+ boolean(raise_errors, true)
67
65
  end
68
66
 
69
67
  def massage(options_hash)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kramdown
4
4
  module PlantUml
5
- VERSION = '1.1.9'
5
+ VERSION = '1.1.13'
6
6
  end
7
7
  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.9
4
+ version: 1.1.13
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-03 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -187,6 +187,7 @@ files:
187
187
  - lib/kramdown-plantuml/console_logger.rb
188
188
  - lib/kramdown-plantuml/diagram.rb
189
189
  - lib/kramdown-plantuml/executor.rb
190
+ - lib/kramdown-plantuml/jekyll_page_processor.rb
190
191
  - lib/kramdown-plantuml/jekyll_provider.rb
191
192
  - lib/kramdown-plantuml/log_wrapper.rb
192
193
  - lib/kramdown-plantuml/options.rb