Commit fc27ca62 authored by Robert Speicher's avatar Robert Speicher

Refactor `HeaderNode#find_parent`

Now the instance variable assignment is all contained within
`#initialize`, and the `children.push` behavior is more explicit.
parent b43aefbd
...@@ -86,7 +86,8 @@ module Banzai ...@@ -86,7 +86,8 @@ module Banzai
@href = href @href = href
@children = [] @children = []
find_parent(previous_header) @parent = find_parent(previous_header)
@parent.children.push(self) if @parent
end end
def level def level
...@@ -107,15 +108,15 @@ module Banzai ...@@ -107,15 +108,15 @@ module Banzai
return unless previous_header return unless previous_header
if level == previous_header.level if level == previous_header.level
@parent = previous_header.parent parent = previous_header.parent
elsif level > previous_header.level elsif level > previous_header.level
@parent = previous_header parent = previous_header
else else
@parent = previous_header parent = previous_header
@parent = @parent.parent while @parent.level >= level parent = parent.parent while parent.level >= level
end end
@parent.children.push(self) parent
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment