-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(plugins/kuma): refactor custom block plugins specific to Kuma
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
1 parent
cf768ec
commit ecc57ad
Showing
3 changed files
with
29 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.