33module SP
44 # Sets up a tabs with top switcher bar
55 class Tabs < Liquid ::Block
6+ def initialize ( tag_name , markup , tokens )
7+ super
8+ @group = markup . strip . empty? ? 'default' : markup . strip
9+ end
10+
611 def render ( context )
712 tab_bar_content = ''
813 context [ 'tabs' ] = [ ]
14+ context [ 'tab_group' ] = @group
915 result = super
1016
1117 context [ 'tabs' ] . each_with_index do |( label , title ) , index |
1218 res = index . zero? ? ' btn-purple' : ''
1319 tab_bar_content += <<~CONTENT
14- <button class="skhep-bar-item #{ label } -btn btn m-2#{ res } " onclick="openTab('#{ label } ')">#{ title } </button>
20+ <button class="skhep-bar-item #{ @group } - #{ label } -btn btn m-2#{ res } " onclick="openTab('#{ label } ', ' #{ @group } ')">#{ title } </button>
1521 CONTENT
1622 end
1723
@@ -26,8 +32,14 @@ def render(context)
2632
2733 # Sets up tabs without the top switcher bar
2834 class TabBodies < Liquid ::Block
35+ def initialize ( tag_name , markup , tokens )
36+ super
37+ @group = markup . strip . empty? ? 'default' : markup . strip
38+ end
39+
2940 def render ( context )
3041 context [ 'tabs' ] = [ ]
42+ context [ 'tab_group' ] = @group
3143 super
3244 end
3345 end
@@ -42,10 +54,11 @@ def initialize(tag_name, markup, tokens)
4254 def render ( context )
4355 raise SyntaxError , "'tab' be in 'tabs' or 'tabbodies'" unless context . key? ( 'tabs' )
4456
57+ group = context [ 'tab_group' ] || 'default'
4558 res = context [ 'tabs' ] . empty? ? '' : ' style="display:none;"'
4659 context [ 'tabs' ] << [ @label , @title ]
4760 <<~RETURN
48- <div class="skhep-tab #{ @label } -tab" markdown="1"#{ res } >
61+ <div class="skhep-tab #{ group } - #{ @label } -tab" markdown="1"#{ res } >
4962 #{ super }
5063 </div>
5164 RETURN
0 commit comments