Skip to content

Commit

Permalink
Merge pull request #8660 from braze-inc/adjust-tab-function
Browse files Browse the repository at this point in the history
normalize tab names better
  • Loading branch information
internetisaiah authored Dec 23, 2024
2 parents 5c81ab0 + 7bf8c0b commit 2c16aa9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions _plugins/tabs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'digest/md5'

module Tags
class TabsBlock < Liquid::Block
def initialize(tag_name, tabonly = 'false', tokens)
Expand All @@ -13,12 +15,15 @@ def render(context)
tabslist = '<ul class="ab-nav ab-nav-tabs ' + @tabclass + '_ul" id="' + @tabid + '_nav">' + "\n"
if tabs.length > 0
tabs.each_with_index do |tab, ind|
tabslug = tab[0].gsub(/[^0-9a-z]/i, '')
tabslug = Digest::MD5.hexdigest(tab[0]) if tabslug.empty?

# scan returns array of results, only care about first match
tabslist += ' <li tabindex="0" class="coderow ' + tab[0].gsub(' ', '-')
tabslist += ' <li tabindex="0" class="coderow ' + tabslug
if ind == 0
tabslist += ' active'
end
tabslist += '"><a class="' + @tabclass + '" data-tab-target="' + @tabid + '" data-tab="' + tab[0].gsub(' ', '-') + '">' + tab[0] + '</a></li>' + "\n"
tabslist += '"><a class="' + @tabclass + '" data-tab-target="' + @tabid + '" data-tab="' + tabslug + '">' + tab[0] + '</a></li>' + "\n"
end
end
tabslist += '</ul>' + "\n"
Expand Down Expand Up @@ -48,7 +53,8 @@ def render(context)
content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super
content = converter.convert(content)
content = content.strip # Strip again to avoid "\n"
tabslug = @tab.gsub(' ', '-')
tabslug = @tab.gsub(/[^0-9a-z]/i, '')
tabslug = Digest::MD5.hexdigest(@tab) if tabslug.empty?

'<div class="ab-tab-pane ' + tabslug + '_tab " data-tab="' + @tab + '">' + content + "</div>"
end
Expand All @@ -66,15 +72,17 @@ def initialize(tag_name, tabonly = 'false', tokens)
def render(context)
tabs = super.scan(/data\-sub\_tab=\"(.*?)\"/)
tabslist = '<ul class="ab-sub_nav ab-sub_nav-sub_tabs ' + @tabclass + '_ul" id="' + @tabid + '_nav">' + "\n"

if tabs.length > 0
tabs.each_with_index do |tab, ind|
tabslug = tab[0].gsub(/[^0-9a-z]/i, '')
tabslug = Digest::MD5.hexdigest(tab[0]) if tabslug.empty?

# scan returns array of results, only care about first match
tabslist += ' <li tabindex="0" class="coderow ' + tab[0].gsub(' ', '-') + '_sub_tab'
tabslist += ' <li tabindex="0" class="coderow ' + tabslug + '_sub_tab'
if ind == 0
tabslist += ' sub_active'
end
tabslist += '"><a class="' + @tabclass + '" data-sub_tab-target="' + @tabid + '" data-sub_tab="' + tab[0].gsub(' ', '-') + '_sub_tab">' + tab[0] + '</a></li>' + "\n"
tabslist += '"><a class="' + @tabclass + '" data-sub_tab-target="' + @tabid + '" data-sub_tab="' + tabslug + '_sub_tab">' + tab[0] + '</a></li>' + "\n"
end
end
tabslist += '</ul>' + "\n"
Expand Down Expand Up @@ -104,7 +112,8 @@ def render(context)
content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super
content = converter.convert(content)
content = content.strip # Strip again to avoid "\n"
tabslug = @tab.gsub(' ', '-')
tabslug = @tab.gsub(/[^0-9a-z]/i, '')
tabslug = Digest::MD5.hexdigest(@tab) if tabslug.empty?

'<div class="ab-sub_tab-pane ' + tabslug + '_sub_tab " data-sub_tab="' + @tab + '">' + content + "</div>"
end
Expand Down

0 comments on commit 2c16aa9

Please sign in to comment.