kramdown-plantuml 1.1.1 → 1.1.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: 488e793ad6c95b20619319fdec43866b7a96369321767eb415c441b2d8946c0c
4
- data.tar.gz: 2f9b7957b2b7d09ebe2758d1fc3f3600c7464f2ccee53d5ea11f04bf25b0df33
3
+ metadata.gz: 494e1d003f565fb2e076daa61be11c187248776f6ab76145d7c4f6963d771355
4
+ data.tar.gz: 2acbb2c1e2142dbfb1e732013a63f70a9a70d65a6e77c4107970b151a25736b9
5
5
  SHA512:
6
- metadata.gz: 4e4547033622f876ea2c63eb4af2f73433e57fa4cbe8bdd818bbcb5261f4bef829f50da55b9f5485023e5c040d7c260844f27fcf2a67f17858839aa4e9f0dab3
7
- data.tar.gz: cd38086b669bf27b64ccae97f45005a23a508fdfd94647e40c2f8e9960a89edc0abd2781c74fb42493c1b1df7bd5c0aaee6c19acd63cf20394d594c077cc072d
6
+ metadata.gz: ed8130982476ebe4b9bda233ef2f9bef82bcc9519d5ad9bc463b5d4f2bc858b9357d2a190567261616f7fbf2b485554e4e6895235a104d0159a25a42abe87af1
7
+ data.tar.gz: 2423d0759e06ff233f11904c94aaccb5d61d37aa3f2748352b6df3990d7ed49d683c7e5b4456e34ac32db7592bb3a65a3e668f549a08b4e768c0800a0fe281a2
@@ -9,8 +9,8 @@ module Kramdown
9
9
 
10
10
  def initialize(name)
11
11
  @name = name
12
- @value = ENV.key?(name) ? ENV[name] : nil
13
- @value = @value.to_s.downcase unless @value.nil?
12
+ value = ENV.fetch(name, nil)
13
+ @value = value.to_s.downcase unless value.nil?
14
14
  end
15
15
 
16
16
  def true?
@@ -34,7 +34,7 @@ module Kramdown
34
34
  return false unless write_message?(level)
35
35
 
36
36
  pipe = pipe_for(level)
37
- pipe.write("\n#{message}")
37
+ pipe.write("#{message}\n")
38
38
  end
39
39
 
40
40
  def write_message?(level_of_message)
@@ -17,9 +17,14 @@ module Kramdown
17
17
  end
18
18
 
19
19
  def convert_plantuml_to_svg(plantuml)
20
+ if plantuml.nil? || plantuml.empty?
21
+ @logger.warn 'kramdown-plantuml: PlantUML diagram is empty'
22
+ return plantuml
23
+ end
24
+
20
25
  plantuml = @themer.apply_theme(plantuml)
21
26
  plantuml = plantuml.strip
22
- @logger.debug "PlantUML converting diagram:\n#{plantuml}"
27
+ log(plantuml)
23
28
  result = @executor.execute(plantuml)
24
29
  result.validate(plantuml)
25
30
  svg = result.without_xml_prologue
@@ -37,6 +42,11 @@ module Kramdown
37
42
 
38
43
  "#{wrapper_element_start}#{svg}#{wrapper_element_end}"
39
44
  end
45
+
46
+ def log(plantuml)
47
+ @logger.debug 'kramdown-plantuml: PlantUML converting diagram:'
48
+ @logger.debug_with_prefix 'kramdown-plantuml: ', plantuml
49
+ end
40
50
  end
41
51
  end
42
52
  end
@@ -26,11 +26,11 @@ module Kramdown
26
26
  ' -nometadata'
27
27
  end
28
28
 
29
- @logger.debug "PlantUML executing: #{cmd}"
29
+ @logger.debug "kramdown-plantuml: Executing '#{cmd}'."
30
30
 
31
31
  stdout, stderr, status = Open3.capture3 cmd, stdin_data: stdin
32
32
 
33
- @logger.debug "PlantUML exit code: #{status.exitstatus}"
33
+ @logger.debug "kramdown-plantuml: PlantUML exit code '#{status.exitstatus}'."
34
34
 
35
35
  PlantUmlResult.new(stdout, stderr, status)
36
36
  end
@@ -17,19 +17,28 @@ module Kramdown
17
17
  end
18
18
 
19
19
  def debug(message)
20
- @logger.debug(message)
20
+ @logger.debug message
21
+ end
22
+
23
+ def debug_with_prefix(prefix, string)
24
+ return if string.nil? || string.empty?
25
+
26
+ lines = string.lines
27
+ lines.each do |line|
28
+ @logger.debug "#{prefix}#{line.rstrip}"
29
+ end
21
30
  end
22
31
 
23
32
  def info(message)
24
- @logger.info(message)
33
+ @logger.info message
25
34
  end
26
35
 
27
36
  def warn(message)
28
- @logger.warn(message)
37
+ @logger.warn message
29
38
  end
30
39
 
31
40
  def error(message)
32
- @logger.error(message)
41
+ @logger.error message
33
42
  end
34
43
 
35
44
  def debug?
@@ -44,10 +53,10 @@ module Kramdown
44
53
  require 'jekyll'
45
54
  inner = Jekyll.logger
46
55
  rescue LoadError
47
- inner = ConsoleLogger.new(level)
56
+ inner = ConsoleLogger.new level
48
57
  end
49
58
 
50
- Logger.new(inner)
59
+ Logger.new inner
51
60
  end
52
61
 
53
62
  def level
@@ -42,7 +42,8 @@ module Kramdown
42
42
 
43
43
  return if @stderr.nil? || @stderr.empty?
44
44
 
45
- @logger.debug("PlantUML log:\n#{@stderr}")
45
+ @logger.debug 'kramdown-plantuml: PlantUML log:'
46
+ @logger.debug_with_prefix 'kramdown-plantuml: ', @stderr
46
47
  end
47
48
  end
48
49
  end
@@ -10,34 +10,30 @@ module Kramdown
10
10
  attr_reader :theme_name, :theme_directory
11
11
 
12
12
  def initialize(options = {})
13
- options = options.symbolize_keys
13
+ options = options.symbolize_keys unless options.nil?
14
14
  @logger = Logger.init
15
- @logger.debug(options)
15
+ @logger.debug "kramdown-plantuml: Options: #{options}"
16
16
  @theme_name, @theme_directory = theme_options(options)
17
17
  end
18
18
 
19
19
  def apply_theme(plantuml)
20
- return plantuml if plantuml.nil? || plantuml.empty? || @theme_name.nil? || @theme_name.empty?
21
-
22
- startuml = '@startuml'
23
- startuml_index = plantuml.index(startuml) + startuml.length
24
-
25
- return plantuml if startuml_index.nil?
26
-
27
- /@startuml.*/.match(plantuml) do |match|
28
- theme_string = "\n!theme #{@theme_name}"
29
- theme_string << " from #{@theme_directory}" unless @theme_directory.nil?
20
+ if plantuml.nil? || plantuml.empty?
21
+ @logger.debug 'kramdown-plantuml: Empty diagram.'
22
+ return plantuml
23
+ end
30
24
 
31
- return plantuml.insert match.end(0), theme_string
25
+ if @theme_name.nil? || @theme_name.empty?
26
+ @logger.debug 'kramdown-plantuml: No theme to apply.'
27
+ return plantuml
32
28
  end
33
29
 
34
- plantuml
30
+ theme(plantuml)
35
31
  end
36
32
 
37
33
  private
38
34
 
39
35
  def theme_options(options)
40
- return nil unless options.key?(:theme)
36
+ return nil if options.nil? || !options.key?(:theme)
41
37
 
42
38
  theme = options[:theme] || {}
43
39
  theme_name = theme.key?(:name) ? theme[:name] : nil
@@ -45,6 +41,24 @@ module Kramdown
45
41
 
46
42
  [theme_name, theme_directory]
47
43
  end
44
+
45
+ def theme(plantuml)
46
+ startuml = '@startuml'
47
+ startuml_index = plantuml.index(startuml) + startuml.length
48
+
49
+ return plantuml if startuml_index.nil?
50
+
51
+ theme_string = "\n!theme #{@theme_name}"
52
+ theme_string << " from #{@theme_directory}" unless @theme_directory.nil?
53
+
54
+ @logger.debug "kramdown-plantuml: Applying #{theme_string}"
55
+
56
+ /@startuml.*/.match(plantuml) do |match|
57
+ return plantuml.insert match.end(0), theme_string
58
+ end
59
+
60
+ plantuml
61
+ end
48
62
  end
49
63
  end
50
64
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kramdown
4
4
  module PlantUml
5
- VERSION = '1.1.1'
5
+ VERSION = '1.1.2'
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.1
4
+ version: 1.1.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-07-31 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown