jekyll-kroki 0.2.1 → 0.2.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: 22cd7bfae1fa5a37266559c800563db4352a1f7323a65ce15a8058ddae6a7e55
4
- data.tar.gz: d76013092f50d163ab83efde344705ec02e8252043d5cd90eadd68903aec472e
3
+ metadata.gz: 0f353846f7017642be1207c60d318604e0f9c0ee211aee558efe6dc7f4bfbff4
4
+ data.tar.gz: d65f5ac400887790313a64244d528169238df4820d5828eccc5adf94d06efb46
5
5
  SHA512:
6
- metadata.gz: eeeeb8d251bcdbaa85429189d11c5ab3aae798b34a28fc4b7742fb195e5ba50af9d450f33dc14db629dc901b5a4e632da77d48abb599ed97b16ae2aa80cd5fee
7
- data.tar.gz: 1d2bf0763f3551576b8e1d0f47b4aa8d62f14b01fe25698bd7ad1d043f4dad1a0c723f7ec607db4cae11bb4c4183be4018ae62b56a7803e8622ad83ac57aa12d
6
+ metadata.gz: 2c0a8a1ad9834f230721440ec19ba2bc9d847ee7f4509e99ddc780a108ffe8fd8d3ccf45182242c88eb088445a92de5dc3a9ebc754466b56b928bb485d65755b
7
+ data.tar.gz: 8131425affe90d14a5df9f61cf9806b66311f90a5827284e2b191c057c503031b69f58c1bd655ff367695ef59ff2df156439792067b461b0be3446638d892767
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "Ruby",
3
+ "image": "mcr.microsoft.com/devcontainers/ruby:3.0-bullseye"
4
+ }
data/.rubocop.yml CHANGED
@@ -12,4 +12,4 @@ Style/StringLiteralsInInterpolation:
12
12
  Layout/LineLength:
13
13
  Max: 120
14
14
  Metrics/MethodLength:
15
- Max: 12
15
+ Max: 14
@@ -0,0 +1,7 @@
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.rulers": [
4
+ 120
5
+ ],
6
+ "rubyLsp.formatter": "rubocop"
7
+ }
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
+ ![Main Workflow](https://github.com/felixvanoost/jekyll-kroki/actions/workflows/main.yml/badge.svg)
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll-kroki.svg)](https://badge.fury.io/rb/jekyll-kroki)
3
+
1
4
  # jekyll-kroki
2
- A Jekyll plugin to convert diagram descriptions into images using Kroki
5
+ A [Jekyll](https://jekyllrb.com/) plugin to convert diagram descriptions into images using [Kroki](https://kroki.io/).
3
6
 
4
7
  ## Installation
5
8
 
@@ -13,9 +16,9 @@ end
13
16
 
14
17
  ## Usage
15
18
 
16
- [Kroki](https://github.com/yuzutech/kroki) supports over 20 popular diagram languages spanning several dozen diagram types. The [examples](https://kroki.io/examples.html) page provides a taste of what's possible.
19
+ Kroki supports over 25 popular diagram scripting languages, including Blockdiag, D2, GraphViz, Mermaid, and PlantUML. The [examples](https://kroki.io/examples.html) page and complete list of [supported diagram languages](https://kroki.io/#support) provide a taste of what's possible.
17
20
 
18
- In Markdown, simply write your diagram description inside a fenced code block with the language specified:
21
+ In Markdown, simply write your diagram descriptions inside a fenced code block with the language specified:
19
22
 
20
23
  ````
21
24
  ```plantuml
@@ -27,13 +30,13 @@ Kroki --> Jekyll: Rendered diagram in SVG format
27
30
  ```
28
31
  ````
29
32
 
30
- When Jekyll builds your site, the `jekyll-kroki` plugin will encode the diagram, send it to the Kroki server for rendering, then replace the diagram description in the generated HTML with the rendered diagram in SVG format:
33
+ When Jekyll builds your site, the `jekyll-kroki` plugin will encode the diagrams, send them to the Kroki server for rendering, then replace the diagram descriptions in the generated HTML with the rendered images in SVG format:
31
34
 
32
35
  ![sample-diagram](https://github.com/felixvanoost/jekyll-kroki/assets/10233016/244d2ec4-b09b-4a5f-8164-3851574c3dd2)
33
36
 
34
- The site remains truly static as the SVG is directly embedded in the HTML files that Jekyll serves. Jekyll only depends on the Kroki server (which can also be run locally) during the build stage, and all of the client-side processing that is normally used to render diagrams into images is eliminated.
37
+ The site remains truly static as the images are directly embedded in the HTML files that Jekyll serves. Jekyll only depends on the Kroki server (which can also be run locally) during the build stage, and all of the client-side processing that is normally used to render diagrams into images is eliminated.
35
38
 
36
- `jekyll-kroki` uses the same Markdown fenced code syntax as the [GitLab Kroki integration](https://docs.gitlab.com/ee/administration/integration/kroki.html), allowing diagram descriptions in Markdown files to be displayed seamlessly in both the GitLab UI and on GitLab Pages sites generated using Jekyll.
39
+ `jekyll-kroki` uses the same Markdown fenced code syntax as the [GitLab Kroki integration](https://docs.gitlab.com/ee/administration/integration/kroki.html), allowing diagram descriptions in Markdown files to be displayed seamlessly as images in both the GitLab UI and on GitLab Pages sites generated using Jekyll.
37
40
 
38
41
  ### Configuration
39
42
 
@@ -44,7 +47,7 @@ kroki:
44
47
  url: "https://my-kroki.server"
45
48
  ```
46
49
 
47
- This is useful if you want to run a Kroki instance locally or your organisation maintains its own private Kroki server. `jekyll-kroki` will use the public Kroki instance https://kroki.io by default if a URL is not specified.
50
+ This is useful if you want to run a Kroki instance locally or your organisation maintains its own private Kroki server. The public Kroki instance https://kroki.io is used by default.
48
51
 
49
52
  ### Security
50
53
 
data/jekyll-kroki.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Felix van Oost"]
9
9
 
10
10
  spec.summary = "A Jekyll plugin to convert diagram descriptions into images using Kroki"
11
- spec.description = "Replaces diagram descriptions written in any Kroki-supported language in HTML files generated by
12
- Jekyll with their visual representation in SVG format."
11
+ spec.description = "A Jekyll plugin to convert diagram descriptions written in over 25 popular diagram scripting
12
+ languages into images using Kroki"
13
13
  spec.homepage = "https://github.com/felixvanoost/jekyll-kroki"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_runtime_dependency "faraday", ["~> 2.7"]
32
32
  spec.add_runtime_dependency "faraday-retry", ["~> 2.2"]
33
+ spec.add_runtime_dependency "httpx", ["~> 1.1"]
33
34
  spec.add_runtime_dependency "jekyll", ["~> 4"]
34
35
  spec.add_runtime_dependency "nokogiri", ["~> 1.15"]
35
36
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class Kroki
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
data/lib/jekyll/kroki.rb CHANGED
@@ -5,6 +5,7 @@ require_relative "kroki/version"
5
5
  require "base64"
6
6
  require "faraday"
7
7
  require "faraday/retry"
8
+ require "httpx/adapters/faraday"
8
9
  require "jekyll"
9
10
  require "nokogiri"
10
11
  require "zlib"
@@ -24,27 +25,29 @@ module Jekyll
24
25
  kroki_url = kroki_url(site.config)
25
26
  puts "[jekyll-kroki] Rendering diagrams using Kroki instance at '#{kroki_url}'"
26
27
 
27
- # Set up a Faraday connection
28
28
  connection = setup_connection(kroki_url)
29
+ supported_languages = get_supported_languages(connection)
29
30
 
30
- # Parse the page, render and embed the diagrams, then convert it back into HTML
31
31
  site.pages.each do |page|
32
32
  next unless embeddable?(page)
33
33
 
34
+ # Parse the page, render and embed the diagrams, then convert it back into HTML
34
35
  parsed_page = Nokogiri::HTML(page.output)
35
- embed_page(connection, parsed_page)
36
+ embed_page(connection, supported_languages, parsed_page)
36
37
  page.output = parsed_page.to_html
37
38
  end
39
+ rescue StandardError => e
40
+ exit(e)
38
41
  end
39
42
 
40
43
  # Renders all diagram descriptions in any Kroki-supported language and embeds them in an HTML document.
41
44
  #
42
45
  # @param [Faraday::Connection] The Faraday connection to use
46
+ # @param [Array] The supported diagram languages
43
47
  # @param [Nokogiri::HTML4::Document] The parsed HTML document
44
- def embed_page(connection, parsed_doc)
45
- # Iterate through every diagram description in each of the supported languages
46
- get_supported_languages(connection).each do |language|
47
- parsed_doc.css("code[class~='language-#{language}']").each do |diagram_desc|
48
+ def embed_page(connection, supported_languages, parsed_page)
49
+ supported_languages.each do |language|
50
+ parsed_page.css("code[class~='language-#{language}']").each do |diagram_desc|
48
51
  # Replace the diagram description with the SVG representation rendered by Kroki
49
52
  diagram_desc.replace(render_diagram(connection, diagram_desc, language))
50
53
  end
@@ -102,12 +105,13 @@ module Jekyll
102
105
  # @param [Faraday::Connection] The Faraday connection to use
103
106
  # @return [Array] The supported diagram languages
104
107
  def get_supported_languages(connection)
105
- begin
106
- response = connection.get("health")
107
- rescue Faraday::Error => e
108
- raise e.response[:body]
109
- end
110
- response.body["version"].keys
108
+ response = connection.get("health")
109
+ supported_languages = response.body["version"]&.keys
110
+ raise "'#{connection.url_prefix}' does not point to a valid Kroki instance" if supported_languages.nil?
111
+
112
+ supported_languages
113
+ rescue Faraday::Error => e
114
+ raise e
111
115
  end
112
116
 
113
117
  # Sets up a new Faraday connection.
@@ -118,7 +122,8 @@ module Jekyll
118
122
  retry_options = { max: HTTP_MAX_RETRIES, interval: 0.1, interval_randomness: 0.5, backoff_factor: 2,
119
123
  exceptions: [Faraday::RequestTimeoutError, Faraday::ServerError] }
120
124
 
121
- Faraday.new(url: kroki_url) do |builder|
125
+ Faraday.new(url: kroki_url, request: { timeout: 5 }) do |builder|
126
+ builder.adapter :httpx, persistent: true
122
127
  builder.request :retry, retry_options
123
128
  builder.response :json, content_type: /\bjson$/
124
129
  builder.response :raise_error
@@ -147,6 +152,23 @@ module Jekyll
147
152
  def embeddable?(doc)
148
153
  doc.output_ext == ".html" && (doc.is_a?(Jekyll::Page) || doc.write?)
149
154
  end
155
+
156
+ # Exits the Jekyll process without returning a stack trace. This method does not return because the process is
157
+ # abruptly terminated.
158
+ #
159
+ # @param [StandardError] The error to display in the termination message
160
+ # @param [int] The caller index to display in the termination message. The default index is 1, which means the
161
+ # calling method. To specify the calling method's caller, pass in 2.
162
+ #
163
+ # Source: https://www.mslinn.com/ruby/2200-crash-exit.html
164
+ def exit(error, caller_index = 1)
165
+ raise error
166
+ rescue StandardError => e
167
+ file, line_number, caller = e.backtrace[caller_index].split(":")
168
+ caller = caller.tr("`", "'")
169
+ warn %([jekyll-kroki] "#{error.message}" #{caller} on line #{line_number} of #{file}).red
170
+ exec "echo ''"
171
+ end
150
172
  end
151
173
  end
152
174
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kroki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix van Oost
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-23 00:00:00.000000000 Z
11
+ date: 2023-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpx
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: jekyll
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,14 +123,16 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '1.21'
111
125
  description: |-
112
- Replaces diagram descriptions written in any Kroki-supported language in HTML files generated by
113
- Jekyll with their visual representation in SVG format.
126
+ A Jekyll plugin to convert diagram descriptions written in over 25 popular diagram scripting
127
+ languages into images using Kroki
114
128
  email:
115
129
  executables: []
116
130
  extensions: []
117
131
  extra_rdoc_files: []
118
132
  files:
133
+ - ".devcontainer/devcontainer.json"
119
134
  - ".rubocop.yml"
135
+ - ".vscode/settings.json"
120
136
  - LICENSE
121
137
  - README.md
122
138
  - Rakefile
@@ -144,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
160
  - !ruby/object:Gem::Version
145
161
  version: '0'
146
162
  requirements: []
147
- rubygems_version: 3.3.5
163
+ rubygems_version: 3.2.33
148
164
  signing_key:
149
165
  specification_version: 4
150
166
  summary: A Jekyll plugin to convert diagram descriptions into images using Kroki