Skip to content

Commit

Permalink
refactor(plugins/kuma): refactor custom block plugins specific to Kuma (
Browse files Browse the repository at this point in the history
#8082)

Remove separate `tip.rb` and `warning.rb` plugins, which were just copies of
the same code with only difference in a block name. Now the code is the same
and just registered for different tags.

It also correctly maps different class names between Kong and Kuma docs.

Signed-off-by: Bart Smykla <[email protected]>
  • Loading branch information
bartsmykla authored Oct 24, 2024
1 parent 2c909ea commit be91aae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 46 deletions.
29 changes: 29 additions & 0 deletions app/_plugins/kuma-specific/custom_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Jekyll
class CustomBlock < Liquid::Block
def initialize(tag_name, markup, options)
super
# Classes differs between Kuma and Kong docs, but they have the same
# underlying meanings
@class_name = {
'tip' => 'note',
'warning' => 'important',
'danger' => 'warning'
}.fetch(tag_name, 'note')
end

def render(context)
content = Kramdown::Document.new(super).to_html
<<~HTML
<blockquote class="#{@class_name}">
<p>#{content}</p>
</blockquote>
HTML
end
end
end

Liquid::Template.register_tag('tip', Jekyll::CustomBlock)
Liquid::Template.register_tag('warning', Jekyll::CustomBlock)
Liquid::Template.register_tag('danger', Jekyll::CustomBlock)
22 changes: 0 additions & 22 deletions app/_plugins/kuma-specific/tip.rb

This file was deleted.

24 changes: 0 additions & 24 deletions app/_plugins/kuma-specific/warning.rb

This file was deleted.

0 comments on commit be91aae

Please sign in to comment.