asciidoctor-kroki 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8c9c6ddeb0a82d775506971be5d140b80f3b06a0799a740430c109e7718312f4
4
+ data.tar.gz: 9f354c2a63e2426e40471ba6db010088e14163bc0a7bcd3cb3e9693a70685521
5
+ SHA512:
6
+ metadata.gz: fde22365b6ce1ac9379bfefd955324b07ada0dbc3bc51e8edc90efce696c15bb1142068819d2ad56cedcf1315290d22451fe36d1caf10d891384d98bf9ca0e91
7
+ data.tar.gz: 2b1906da6dea90f743e104cfd0cb279f3b469b08c8ed791e9e39e10c0945568b60cdd2a2d374e45636847ccb04282d9391d804138ed7a57683af55ce4c874978
@@ -0,0 +1 @@
1
+ pkg/
@@ -0,0 +1,14 @@
1
+ Style/Encoding:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 160
6
+
7
+ Metrics/MethodLength:
8
+ Max: 50
9
+
10
+ Metrics/CyclomaticComplexity:
11
+ Max : 10
12
+
13
+ Metrics/AbcSize:
14
+ Max: 25
@@ -0,0 +1 @@
1
+ 2.6.5
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,101 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ asciidoctor-kroki (0.1.0)
5
+ asciidoctor (~> 2.0)
6
+ asciidoctor-pdf (= 1.5.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ Ascii85 (1.0.3)
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ afm (0.2.2)
15
+ asciidoctor (2.0.10)
16
+ asciidoctor-pdf (1.5.3)
17
+ asciidoctor (>= 1.5.3, < 3.0.0)
18
+ concurrent-ruby (~> 1.1.0)
19
+ prawn (~> 2.2.0)
20
+ prawn-icon (~> 2.5.0)
21
+ prawn-svg (~> 0.30.0)
22
+ prawn-table (~> 0.2.0)
23
+ prawn-templates (~> 0.1.0)
24
+ safe_yaml (~> 1.0.0)
25
+ thread_safe (~> 0.3.0)
26
+ treetop (~> 1.6.0)
27
+ ttfunk (~> 1.5.0, >= 1.5.1)
28
+ ast (2.4.1)
29
+ concurrent-ruby (1.1.6)
30
+ css_parser (1.7.1)
31
+ addressable
32
+ diff-lcs (1.3)
33
+ hashery (2.1.2)
34
+ jaro_winkler (1.5.4)
35
+ parallel (1.19.1)
36
+ parser (2.7.1.3)
37
+ ast (~> 2.4.0)
38
+ pdf-core (0.7.0)
39
+ pdf-reader (2.4.0)
40
+ Ascii85 (~> 1.0.0)
41
+ afm (~> 0.2.1)
42
+ hashery (~> 2.0)
43
+ ruby-rc4
44
+ ttfunk
45
+ polyglot (0.3.5)
46
+ prawn (2.2.2)
47
+ pdf-core (~> 0.7.0)
48
+ ttfunk (~> 1.5)
49
+ prawn-icon (2.5.0)
50
+ prawn (>= 1.1.0, < 3.0.0)
51
+ prawn-svg (0.30.0)
52
+ css_parser (~> 1.6)
53
+ prawn (>= 0.11.1, < 3)
54
+ prawn-table (0.2.2)
55
+ prawn (>= 1.3.0, < 3.0.0)
56
+ prawn-templates (0.1.2)
57
+ pdf-reader (~> 2.0)
58
+ prawn (~> 2.2)
59
+ public_suffix (4.0.5)
60
+ rainbow (3.0.0)
61
+ rake (12.3.3)
62
+ rspec (3.8.0)
63
+ rspec-core (~> 3.8.0)
64
+ rspec-expectations (~> 3.8.0)
65
+ rspec-mocks (~> 3.8.0)
66
+ rspec-core (3.8.2)
67
+ rspec-support (~> 3.8.0)
68
+ rspec-expectations (3.8.6)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.8.0)
71
+ rspec-mocks (3.8.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.8.0)
74
+ rspec-support (3.8.3)
75
+ rubocop (0.74.0)
76
+ jaro_winkler (~> 1.5.1)
77
+ parallel (~> 1.10)
78
+ parser (>= 2.6)
79
+ rainbow (>= 2.2.2, < 4.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (>= 1.4.0, < 1.7)
82
+ ruby-progressbar (1.10.1)
83
+ ruby-rc4 (0.1.5)
84
+ safe_yaml (1.0.5)
85
+ thread_safe (0.3.6)
86
+ treetop (1.6.10)
87
+ polyglot (~> 0.3)
88
+ ttfunk (1.5.1)
89
+ unicode-display_width (1.6.1)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ asciidoctor-kroki!
96
+ rake (~> 12.3.2)
97
+ rspec (~> 3.8.0)
98
+ rubocop (~> 0.74.0)
99
+
100
+ BUNDLED WITH
101
+ 1.17.3
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob('tasks/*.rake').each { |file| load file }
4
+
5
+ task default: %w[lint spec]
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'asciidoctor-kroki'
5
+ s.version = '0.1.0'
6
+ s.summary = 'Asciidoctor extension to convert diagrams to images using Kroki'
7
+ s.description = 'An extension for Asciidoctor to convert diagrams to images using https://kroki.io'
8
+
9
+ s.authors = ['Guillaume Grossetie']
10
+ s.email = ['ggrossetie@yuzutech.fr']
11
+ s.homepage = 'https://github.com/Mogztter/asciidoctor-kroki'
12
+ s.license = 'MIT'
13
+ s.metadata = {
14
+ 'bug_tracker_uri' => 'https://github.com/Mogztter/asciidoctor-kroki/issues',
15
+ 'source_code_uri' => 'https://github.com/Mogztter/asciidoctor-kroki'
16
+ }
17
+ s.files = `git ls-files`.split($RS)
18
+ s.test_files = s.files.grep(%r{^(test|spec|features|tasks)/})
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_runtime_dependency 'asciidoctor', '~> 2.0'
22
+ s.add_runtime_dependency 'asciidoctor-pdf', '1.5.3'
23
+
24
+ s.add_development_dependency 'rake', '~> 12.3.2'
25
+ s.add_development_dependency 'rspec', '~> 3.8.0'
26
+ s.add_development_dependency 'rubocop', '~> 0.74.0'
27
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
4
+ require_relative 'asciidoctor_kroki/extension'
5
+
6
+ Asciidoctor::Extensions.register do
7
+ names = %w[plantuml ditaa graphviz blockdiag seqdiag actdiag nwdiag packetdiag rackdiag c4plantuml erd mermaid nomnoml svgbob umlet vega vegalite wavedrom]
8
+ names.each do |name|
9
+ block_macro ::AsciidoctorExtensions::KrokiBlockMacroProcessor, name
10
+ block ::AsciidoctorExtensions::KrokiBlockProcessor, name
11
+ end
12
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
4
+ require 'stringio'
5
+ require 'zlib'
6
+
7
+ # Asciidoctor extensions
8
+ #
9
+ module AsciidoctorExtensions
10
+ include Asciidoctor
11
+
12
+ # A block extension that converts a diagram into an image.
13
+ #
14
+ class KrokiBlockProcessor < Extensions::BlockProcessor
15
+ use_dsl
16
+
17
+ on_context :listing, :literal
18
+ name_positional_attributes 'target', 'format'
19
+
20
+ def process(parent, reader, attrs)
21
+ diagram_type = @name
22
+ diagram_text = reader.string
23
+ KrokiProcessor.process(self, parent, attrs, diagram_type, diagram_text)
24
+ end
25
+ end
26
+
27
+ # A block macro extension that converts a diagram into an image.
28
+ #
29
+ class KrokiBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
30
+ use_dsl
31
+
32
+ def process(parent, target, attrs)
33
+ diagram_type = @name
34
+ target = parent.apply_subs(target, ['attributes'])
35
+ diagram_text = read(target)
36
+ KrokiProcessor.process(self, parent, attrs, diagram_type, diagram_text)
37
+ end
38
+
39
+ def read(target)
40
+ if target.start_with?('http://') || target.start_with?('https://')
41
+ require 'open-uri'
42
+ URI.open(target, &:read)
43
+ else
44
+ File.open(target, &:read)
45
+ end
46
+ end
47
+ end
48
+
49
+ # Internal processor
50
+ #
51
+ class KrokiProcessor
52
+ class << self
53
+ def process(processor, parent, attrs, diagram_type, diagram_text)
54
+ doc = parent.document
55
+ diagram_text = prepend_plantuml_config(diagram_text, diagram_type, doc)
56
+ # If "subs" attribute is specified, substitute accordingly.
57
+ # Be careful not to specify "specialcharacters" or your diagram code won't be valid anymore!
58
+ if (subs = attrs['subs'])
59
+ diagram_text = parent.apply_subs(diagram_text, parent.resolve_subs(subs))
60
+ end
61
+ title = attrs.delete('title')
62
+ caption = attrs.delete('caption')
63
+ attrs.delete('opts')
64
+ role = attrs['role']
65
+ format = get_format(doc, attrs, diagram_type)
66
+ attrs['role'] = get_role(format, role)
67
+ attrs['alt'] = get_alt(attrs)
68
+ attrs['target'] = create_image_src(doc, diagram_type, format, diagram_text)
69
+ attrs['format'] = format
70
+ block = processor.create_image_block(parent, attrs)
71
+ block.title = title
72
+ block.assign_caption(caption, 'figure')
73
+ block
74
+ end
75
+
76
+ private
77
+
78
+ def prepend_plantuml_config(diagram_text, diagram_type, doc)
79
+ if diagram_type == :plantuml && doc.attr?('kroki-plantuml-include')
80
+ # TODO: this behaves different than the JS version
81
+ # The file should be added by !include #{plantuml_include}" once we have a preprocessor for ruby
82
+ config = File.read(doc.attr('kroki-plantuml-include'))
83
+ diagram_text = config + '\n' + diagram_text
84
+ end
85
+ diagram_text
86
+ end
87
+
88
+ def get_alt(attrs)
89
+ if (title = attrs['title'])
90
+ title
91
+ elsif (target = attrs['target'])
92
+ target
93
+ else
94
+ 'Diagram'
95
+ end
96
+ end
97
+
98
+ def get_role(format, role)
99
+ if role
100
+ if format
101
+ "#{role} kroki-format-#{format} kroki"
102
+ else
103
+ "#{role} kroki"
104
+ end
105
+ else
106
+ 'kroki'
107
+ end
108
+ end
109
+
110
+ def get_format(doc, attrs, diagram_type)
111
+ format = attrs['format'] || 'svg'
112
+ # The JavaFX preview doesn't support SVG well, therefore we'll use PNG format...
113
+ if doc.attr?('env-idea') && format == 'svg'
114
+ # ... unless the diagram library does not support PNG as output format!
115
+ # Currently, mermaid, nomnoml, svgbob, wavedrom only support SVG as output format.
116
+ svg_only_diagram_types = %w[:mermaid :nomnoml :svgbob :wavedrom]
117
+ format = 'png' unless svg_only_diagram_types.include?(diagram_type)
118
+ end
119
+ format
120
+ end
121
+
122
+ def create_image_src(doc, type, format, text)
123
+ data = Base64.urlsafe_encode64(Zlib::Deflate.deflate(text, 9))
124
+ "#{server_url(doc)}/#{type}/#{format}/#{data}"
125
+ end
126
+
127
+ def server_url(doc)
128
+ doc.attr('kroki-server-url') || 'https://kroki.io'
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,5 @@
1
+ inherit_from:
2
+ - ../.rubocop.yml
3
+
4
+ Metrics/BlockLength:
5
+ Max: 500
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'asciidoctor'
4
+ require_relative '../lib/asciidoctor/extensions/asciidoctor_kroki'
5
+
6
+ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
7
+ context 'convert to html5' do
8
+ it 'should convert a PlantUML block to an image' do
9
+ input = <<~'ADOC'
10
+ [plantuml]
11
+ ....
12
+ alice -> bob: hello
13
+ ....
14
+ ADOC
15
+ output = Asciidoctor.convert(input, standalone: false)
16
+ (expect output).to eql %(<div class="imageblock kroki">
17
+ <div class="content">
18
+ <img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
19
+ </div>
20
+ </div>)
21
+ end
22
+ it 'should use png if env-idea is defined' do
23
+ input = <<~'ADOC'
24
+ [plantuml]
25
+ ....
26
+ alice -> bob: hello
27
+ ....
28
+ ADOC
29
+ output = Asciidoctor.convert(input, attributes: { 'env-idea' => '' }, standalone: false)
30
+ (expect output).to eql %(<div class="imageblock kroki">
31
+ <div class="content">
32
+ <img src="https://kroki.io/plantuml/png/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
33
+ </div>
34
+ </div>)
35
+ end
36
+ it 'should include the plantuml-include file' do
37
+ input = <<~'ADOC'
38
+ [plantuml]
39
+ ....
40
+ alice -> bob: hello
41
+ ....
42
+ ADOC
43
+ output = Asciidoctor.convert(input, attributes: { 'env-idea' => '', 'kroki-plantuml-include' => 'spec/fixtures/config.puml' }, standalone: false)
44
+ (expect output).to eql %(<div class="imageblock kroki">
45
+ <div class="content">
46
+ <img src="https://kroki.io/plantuml/png/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5YrJS8zJTE5V0LVTSMpPslLISM3JyQcArVsRHA==" alt="Diagram">
47
+ </div>
48
+ </div>)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ skinparam monochrome true
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/gem_tasks'
5
+ rescue LoadError
6
+ warn $ERROR_INFO.message
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new :lint
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new :spec
6
+ rescue LoadError
7
+ warn $ERROR_INFO.message
8
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-kroki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillaume Grossetie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: asciidoctor-pdf
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 12.3.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 12.3.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.8.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.74.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.74.0
83
+ description: An extension for Asciidoctor to convert diagrams to images using https://kroki.io
84
+ email:
85
+ - ggrossetie@yuzutech.fr
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".ruby-version"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - Rakefile
96
+ - asciidoctor-kroki.gemspec
97
+ - lib/asciidoctor/extensions/asciidoctor_kroki.rb
98
+ - lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
99
+ - spec/.rubocop.yml
100
+ - spec/asciidoctor_kroki_spec.rb
101
+ - spec/fixtures/config.puml
102
+ - tasks/bundler.rake
103
+ - tasks/lint.rake
104
+ - tasks/rspec.rake
105
+ homepage: https://github.com/Mogztter/asciidoctor-kroki
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ bug_tracker_uri: https://github.com/Mogztter/asciidoctor-kroki/issues
110
+ source_code_uri: https://github.com/Mogztter/asciidoctor-kroki
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Asciidoctor extension to convert diagrams to images using Kroki
130
+ test_files:
131
+ - spec/.rubocop.yml
132
+ - spec/asciidoctor_kroki_spec.rb
133
+ - spec/fixtures/config.puml
134
+ - tasks/bundler.rake
135
+ - tasks/lint.rake
136
+ - tasks/rspec.rake