kramdown-plantuml 1.1.8 → 1.1.9

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: f873d08b8ab86ebe4ea964c30ad59a43a75c28d042d6627af1694d1ff262cbfd
4
- data.tar.gz: cca59110bbdac25b41dc4c7ef41f9df0f84b17aa4a6da662feab19a73ca61724
3
+ metadata.gz: 4ffc24d5b020aac9204946744f85793d0ae07da2fe95a27b9301f104aee78c13
4
+ data.tar.gz: 83ae8392c10526f3382d327497fee2b85c297f9eb7599798f1e789f947084800
5
5
  SHA512:
6
- metadata.gz: bbe10bc2e73c25b0a2bd09651e9bd73b2aeb612fa26f0470df0e9f0477c8f8f69f3c69d428b136826264e975068dc073724fcf4ab5e10b93e59585001983ada8
7
- data.tar.gz: b74471596aadcf0bde3bf7878864918fb5bd6297172f69b5f9d30c214f84c1f67dfe2c11b7b6e1dc78bfb85c817c0a2c4a26e5bb9c420c519d490b5567b29fe8
6
+ metadata.gz: 38a1e20a6a08fc178d25737ff9443fecfd8f48bbbc10f1b69eda8fd929f472a05f39150ad91d17cbaf94285757c156101510c16346aecee06f7a712e74c9908b
7
+ data.tar.gz: 9d6d3192043170c20829ab97fc5513bc392d5eb8af92eb8017042d6ebbd19000730427a5b8c3ac3809095d4a8ec74945424fe854c0d1667ecce1340b3e88b78a
@@ -11,6 +11,8 @@ module Kramdown
11
11
  # Provides an instance of Jekyll if available.
12
12
  module JekyllProvider
13
13
  class << self
14
+ attr_reader :site_destination_dir
15
+
14
16
  def jekyll
15
17
  return @jekyll if defined? @jekyll
16
18
 
@@ -20,16 +22,8 @@ module Kramdown
20
22
  def install
21
23
  return @installed = false if jekyll.nil?
22
24
 
23
- logger.debug 'Jekyll detected, hooking into :site:post_render'
24
-
25
- Jekyll::Hooks.register :site, :post_render do |site|
26
- logger.debug ':site:post_render triggered.'
27
-
28
- site.pages.each do |page|
29
- page.output = replace_needles(page.output)
30
- end
31
- end
32
-
25
+ find_site_destination_dir
26
+ register_hook
33
27
  @installed = true
34
28
  end
35
29
 
@@ -56,7 +50,34 @@ module Kramdown
56
50
 
57
51
  private
58
52
 
59
- def replace_needles(html)
53
+ def find_site_destination_dir
54
+ if jekyll.sites.nil? || jekyll.sites.empty?
55
+ logger.debug 'Jekyll detected, hooking into :site:post_write.'
56
+ return nil
57
+ end
58
+
59
+ @site_destination_dir = jekyll.sites.first.dest
60
+ logger.debug "Jekyll detected, hooking into :site:post_write of '#{@site_destination_dir}'."
61
+ @site_destination_dir
62
+ end
63
+
64
+ def register_hook
65
+ 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
74
+ end
75
+ end
76
+
77
+ def replace_needles(page)
78
+ logger.debug "Replacing Jekyll needle in #{page.path}"
79
+
80
+ html = page.output
60
81
  return html if html.nil? || html.empty? || !html.is_a?(String)
61
82
 
62
83
  html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
@@ -66,16 +87,19 @@ module Kramdown
66
87
  end
67
88
 
68
89
  def replace_needle(json)
69
- hash = JSON.parse(json)
70
- options_hash = hash['options']
90
+ logger.debug 'Replacing Jekyll needle.'
91
+
92
+ needle_hash = JSON.parse(json)
93
+ options_hash = needle_hash['options']
94
+ options_hash[:site_destination_dir] = @site_destination_dir
71
95
  options = ::Kramdown::PlantUml::Options.new({ plantuml: options_hash })
72
96
 
73
97
  begin
74
- decode_and_convert(hash, options)
98
+ decode_and_convert(needle_hash, options)
75
99
  rescue StandardError => e
76
100
  raise e if options.raise_errors?
77
101
 
78
- logger.error 'Error while replacing needle.'
102
+ logger.error 'Error while replacing Jekyll needle.'
79
103
  logger.error e.to_s
80
104
  logger.debug_multiline json
81
105
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'options'
4
4
  require_relative 'log_wrapper'
5
+ require_relative 'jekyll_provider'
5
6
 
6
7
  module Kramdown
7
8
  module PlantUml
@@ -13,9 +14,10 @@ module Kramdown
13
14
  raise ArgumentError, 'options cannot be nil' if options.nil?
14
15
  raise ArgumentError, "options must be a '#{Options}'." unless options.is_a?(Options)
15
16
 
17
+ @raise_errors = options.raise_errors?
16
18
  @logger = LogWrapper.init
17
19
  @name = options.theme_name
18
- @directory = options.theme_directory
20
+ @directory = resolve options.theme_directory
19
21
  end
20
22
 
21
23
  def apply(plantuml)
@@ -34,6 +36,28 @@ module Kramdown
34
36
 
35
37
  private
36
38
 
39
+ def resolve(directory)
40
+ jekyll = JekyllProvider
41
+
42
+ return directory if directory.nil? || directory.empty? || !jekyll.installed?
43
+
44
+ directory = File.absolute_path(directory, jekyll.site_destination_dir)
45
+
46
+ log_or_raise "The theme directory '#{directory}' cannot be found" unless Dir.exist?(directory)
47
+
48
+ theme_path = File.join(directory, "puml-theme-#{@name}.puml")
49
+
50
+ log_or_raise "The theme '#{theme_path}' cannot be found" unless File.exist?(theme_path)
51
+
52
+ directory
53
+ end
54
+
55
+ def log_or_raise(message)
56
+ raise IOError, message if @raise_errors
57
+
58
+ logger.warn message
59
+ end
60
+
37
61
  def theme(plantuml)
38
62
  startuml = '@startuml'
39
63
  startuml_index = plantuml.index(startuml) + startuml.length
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kramdown
4
4
  module PlantUml
5
- VERSION = '1.1.8'
5
+ VERSION = '1.1.9'
6
6
  end
7
7
  end
data/lib/kramdown_html.rb CHANGED
@@ -43,6 +43,7 @@ module Kramdown
43
43
  rescue StandardError => e
44
44
  raise e if options.raise_errors?
45
45
 
46
+ logger = ::Kramdown::PlantUml::LogWrapper.init
46
47
  logger.error "Error while replacing needle: #{e.inspect}"
47
48
  end
48
49
  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.8
4
+ version: 1.1.9
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-01 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities