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
@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
......
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