@@ -43,8 +43,13 @@ def initialize(block_name, markup, tokens)
4343 def render ( context )
4444 environment = context . environments . first
4545 environment [ "tabs-#{ @name } " ] = [ ] # reset every time (so page translations can use the same name)
46- super
47-
46+ if environment [ "CURRENT_TABS_ENV" ] . nil?
47+ environment [ "CURRENT_TABS_ENV" ] = @name
48+ else
49+ raise SyntaxError . new ( "Nested tabs are not supported" )
50+ end
51+ super # super call renders the internal content
52+ environment [ "CURRENT_TABS_ENV" ] = nil # reset after rendering
4853 foundDefault = false
4954
5055 allTabs = environment [ "tabs-#{ @name } " ]
@@ -87,15 +92,17 @@ def render(context)
8792 class TabBlock < Liquid ::Block
8893 alias_method :render_block , :render
8994
90- SYNTAX = /^\s *(#{ Liquid ::QuotedFragment } )\s +(?:for=(#{ Liquid ::QuotedFragment } ))(?:\s +(defaultTab))?/o
95+ SYNTAX = /^\s *(#{ Liquid ::QuotedFragment } )\s +(?:for=(#{ Liquid ::QuotedFragment } ))? (?:\s +(defaultTab))?/o
9196 Syntax = SYNTAX
9297
9398 def initialize ( block_name , markup , tokens )
9499 super
95100
96101 if markup =~ SYNTAX
97102 @tab = Tabs ::unquote ( $1)
98- @name = Tabs ::unquote ( $2)
103+ if $2
104+ @name = Tabs ::unquote ( $2)
105+ end
99106 @anchor = Tabs ::asAnchor ( @tab )
100107 if $3
101108 @defaultTab = true
@@ -113,8 +120,16 @@ def render(context)
113120 content = converter . convert ( pre_content )
114121 tabcontent = TabDetails . new ( label : @tab , anchor : @anchor , defaultTab : @defaultTab , content : content )
115122 environment = context . environments . first
116- environment [ "tabs-#{ @name } " ] ||= [ ]
117- environment [ "tabs-#{ @name } " ] << tabcontent
123+ tab_env = environment [ "CURRENT_TABS_ENV" ]
124+ if tab_env . nil?
125+ raise SyntaxError . new ( "Tab block '#{ tabcontent . label } ' must be inside a tabs block" )
126+ end
127+ if !@name . nil? && tab_env != @name
128+ raise SyntaxError . new (
129+ "Tab block '#{ @tab } ' for=#{ @name } does not match its enclosing tabs block #{ tab_env } " )
130+ end
131+ environment [ "tabs-#{ tab_env } " ] ||= [ ]
132+ environment [ "tabs-#{ tab_env } " ] << tabcontent
118133 end
119134 end
120135 end
0 commit comments