summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-09-01 14:58:40 -0400
committerRobert Speicher <rspeicher@gmail.com>2017-09-06 12:48:25 -0400
commitfc27ca62dd3d8df86ce2e0f85668f561b0db43fe (patch)
tree612b2f616e0d24899a8be3a49e67f2b95af48f63
parentb43aefbd9d606d01c37c5e16b081950d389e3386 (diff)
downloadgitlab-ce-fc27ca62dd3d8df86ce2e0f85668f561b0db43fe.tar.gz
Refactor `HeaderNode#find_parent`
Now the instance variable assignment is all contained within `#initialize`, and the `children.push` behavior is more explicit.
-rw-r--r--lib/banzai/filter/table_of_contents_filter.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb
index eda94bea5e0..5522986ba21 100644
--- a/lib/banzai/filter/table_of_contents_filter.rb
+++ b/lib/banzai/filter/table_of_contents_filter.rb
@@ -86,7 +86,8 @@ module Banzai
@href = href
@children = []
- find_parent(previous_header)
+ @parent = find_parent(previous_header)
+ @parent.children.push(self) if @parent
end
def level
@@ -107,15 +108,15 @@ module Banzai
return unless previous_header
if level == previous_header.level
- @parent = previous_header.parent
+ parent = previous_header.parent
elsif level > previous_header.level
- @parent = previous_header
+ parent = previous_header
else
- @parent = previous_header
- @parent = @parent.parent while @parent.level >= level
+ parent = previous_header
+ parent = parent.parent while parent.level >= level
end
- @parent.children.push(self)
+ parent
end
end
end