diff options
author | Marcia Ramos <virtua.creative@gmail.com> | 2018-04-17 19:51:38 +0300 |
---|---|---|
committer | Marcia Ramos <virtua.creative@gmail.com> | 2018-04-17 19:51:38 +0300 |
commit | ae32b71aaca0c024d7fabfb81850626b042a548a (patch) | |
tree | a3db85fde5ab82c8d0575a3ad6964f39e40b2c8d /lib | |
parent | bea80f92f7d9fe2ad61e736466f4aab00a4b32e4 (diff) |
Add badges to docs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filters/badges.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/filters/badges.rb b/lib/filters/badges.rb new file mode 100644 index 00000000..556d2ea9 --- /dev/null +++ b/lib/filters/badges.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +# GitLab price / tiers badge +# +# This allows us to add visual Badges to our documentation using standard Markdown +# that will render in any markdown editor. +# +# The available pattern is `**[<BADGE_TYPE> <MODIFIER>]**` +# The following TIERS are supported: CORE, STARTER, PREMIUM, ULTIMATE +# The following MODIFIERS are supported: ONLY +# +# When you have ONLY as MODIFIER, it means, it applies only for on premise instances +# so we are not going to expand "STARTER" to "BRONZE" as well. +class BadgesFilter < Nanoc::Filter + identifier :badges + + BADGES_PATTERN = %r{ + (?:^|[^`]) # must be start of the line or anything except backtick + \*\*\[ + (?<badge_type>CORE|STARTER|PREMIUM|ULTIMATE)(?:\s+(?<only>ONLY)) + ?\]\*\* + (?:$|[^`]) # must end of line or anything except backtick + }x + + def run(content, params = {}) + content.gsub(BADGES_PATTERN) { generate(Regexp.last_match[:badge_type].downcase, !Regexp.last_match[:only].nil?) } + end + + def generate(badge_type, only) + if only + %[<span class="badge-trigger #{badge_type}-only"></span>] + else + %[<span class="badge-trigger #{badge_type}"></span>] + end + end +end |