Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Commit

Permalink
Adds some nil protection against lookups inside the HTML in the READM…
Browse files Browse the repository at this point in the history
…E manipulator
  • Loading branch information
orta committed Aug 19, 2016
1 parent aa94dd6 commit 883651b
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions classes/readme_manipulator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Takes a readme path and
# Takes a readme path and makes some changes, then passes that
# back to the system as a rendered version of the README

class ReadmeManipulator
include HashInit
Expand Down Expand Up @@ -173,18 +174,19 @@ def remove_dependency_manager_cues(parent_selector = nil)
install = doc.at('h2:contains("Install")')
if install
install_index = main.children.find_index install
first_sibling = nil

# Get first non-empty value
(install_index + 1..main.children.length).each do |index|
child = main.children[index]
next if child.text.strip.empty?
if install_index
first_sibling = nil
# Get first non-empty value
(install_index + 1..main.children.length).each do |index|
child = main.children[index]
next if child.text.strip.empty?

first_sibling = child
break
end

first_sibling = child
break
install.remove if first_sibling.name == "h2"
end

install.remove if first_sibling.name == "h2"
end

File.open(@readme_path, 'w') { |f| f.write(doc) }
Expand Down Expand Up @@ -231,5 +233,4 @@ def remove_two_linked_paragraphs main_element, before, after

main_element
end

end

0 comments on commit 883651b

Please sign in to comment.