kramdown-plantuml 1.1.11 → 1.1.12

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: '0307159bac1bde4c2f9d21a19fde7e2c3a474df622f5a0fd54d368d71e7c6884'
4
- data.tar.gz: 440a8b11f5398ffc6f73ebf67c9d1eb5e5c91e3fc63fb9a15455033bf413a882
3
+ metadata.gz: '09e8c86eb711f1566f32fce47684f204a1daaef68fd53c7d9837dea2af47eedc'
4
+ data.tar.gz: 5393660894a40a510b0d709dc5d6c8bfa738a7584c1f59c5f549526827fd99ef
5
5
  SHA512:
6
- metadata.gz: d9a7db962e92eebd1729c3e043d6a6ba0fca49c8365d7eecdacd5120737eda1d0af58c423bdf8cdd7d6101e3421a19c778f9a3fee22148d9948b46f8f0a2d542
7
- data.tar.gz: 5fe6ae9a8ffb8941825da89f0bf7f28229631292615938fcd9edd507553148a1feaab272c48fac9509dedffebd70e0cec8a3a6209a5d2ddb74323f575c606b01
6
+ metadata.gz: f74720e634e10a0688ee87bc8c85277e07865583f85e87e86b87747e1aec03362ab98a7c85d92a14d399ad06eb6525b12647757809128af77f3d35d782e6bbba
7
+ data.tar.gz: 013a677b39a48aa8e401fb1d6dfd5340e66e01f564b2188a17fe5437201df7324ed0f4fd37704c137594867513c614ac33f7c8ce26948988225a11f8cd75da23
@@ -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,105 @@
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
+ puts page.class
17
+
18
+ @page = page
19
+ end
20
+
21
+ def process(site_destination_directory)
22
+ @page.output = do_process
23
+ @page.data[PROCESSED_KEY] = true
24
+ @page.write(site_destination_directory)
25
+ end
26
+
27
+ def should_process?
28
+ return false unless @page.output_ext == '.html'
29
+
30
+ if !@page.data.nil? && @page.data.key?(PROCESSED_KEY) && @page.data[PROCESSED_KEY]
31
+ logger.debug "Skipping #{@page.path} because it has already been processed."
32
+ return false
33
+ end
34
+
35
+ true
36
+ end
37
+
38
+ class << self
39
+ def needle(plantuml, options)
40
+ hash = { 'plantuml' => plantuml, 'options' => options.to_h }
41
+
42
+ <<~NEEDLE
43
+ <!--#kramdown-plantuml.start#-->
44
+ #{hash.to_json}
45
+ <!--#kramdown-plantuml.end#-->
46
+ NEEDLE
47
+ rescue StandardError => e
48
+ raise e if options.nil? || options.raise_errors?
49
+
50
+ logger.error 'Error while placing needle.'
51
+ logger.error e.to_s
52
+ logger.debug_multiline plantuml
53
+ end
54
+
55
+ def logger
56
+ @logger ||= ::Kramdown::PlantUml::LogWrapper.init
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def do_process
63
+ logger.debug "Replacing Jekyll needles in #{@page.path}"
64
+
65
+ html = @page.output
66
+
67
+ return html if html.nil? || html.empty? || !html.is_a?(String)
68
+
69
+ html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
70
+ json = $LAST_MATCH_INFO ? $LAST_MATCH_INFO[:json] : nil
71
+ replace_needle(json) unless json.nil?
72
+ end
73
+ end
74
+
75
+ def replace_needle(json)
76
+ logger.debug 'Replacing Jekyll needle.'
77
+
78
+ needle_hash = JSON.parse(json)
79
+ options_hash = needle_hash['options']
80
+ options = ::Kramdown::PlantUml::Options.new({ plantuml: options_hash })
81
+
82
+ begin
83
+ decode_and_convert(needle_hash, options)
84
+ rescue StandardError => e
85
+ raise e if options.raise_errors?
86
+
87
+ logger.error 'Error while replacing Jekyll needle.'
88
+ logger.error e.to_s
89
+ logger.debug_multiline json
90
+ end
91
+ end
92
+
93
+ def decode_and_convert(hash, options)
94
+ encoded_plantuml = hash['plantuml']
95
+ plantuml = HTMLEntities.new.decode encoded_plantuml
96
+ diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
97
+ diagram.convert_to_svg
98
+ end
99
+
100
+ def logger
101
+ @logger ||= ::Kramdown::PlantUml::LogWrapper.init
102
+ end
103
+ end
104
+ end
105
+ 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,54 +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 = ::Kramdown::PlantUml::Options.new({ plantuml: options_hash })
95
-
96
- begin
97
- decode_and_convert(needle_hash, options)
98
- rescue StandardError => e
99
- raise e if options.raise_errors?
100
-
101
- logger.error 'Error while replacing Jekyll needle.'
102
- logger.error e.to_s
103
- logger.debug_multiline json
63
+ processor.process(site.dest)
104
64
  end
105
65
  end
106
66
 
107
- def decode_and_convert(hash, options)
108
- encoded_plantuml = hash['plantuml']
109
- plantuml = HTMLEntities.new.decode encoded_plantuml
110
- diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
111
- diagram.convert_to_svg
112
- end
113
-
114
67
  def load_jekyll
115
68
  require 'jekyll'
116
69
  ::Jekyll
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kramdown
4
4
  module PlantUml
5
- VERSION = '1.1.11'
5
+ VERSION = '1.1.12'
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.11
4
+ version: 1.1.12
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-04 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