Skip to content

Commit

Permalink
Merge pull request #10 from Yoomee/bug/document-regexrc
Browse files Browse the repository at this point in the history
Switch to using Nokogiri for parsing document slugs
  • Loading branch information
ArayB authored Aug 15, 2016
2 parents 17638db + 651136b commit bf54b9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/trough/pig/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ def determine_text_change(key, content_chunk)
def find_documents(value)
# Find all links to /documents/:slug and return the slugs
return [] if value.nil?
value.scan(/href=\S*\/documents\/(\S+[^\\])\\?['"]>/).flatten
html = Nokogiri::HTML(value)
links = find_links_for_documents(html)
grab_slugs_from_links(links)
end

def find_links_for_documents(html)
html.xpath("//a[contains(@href, '/documents/')]")
end

def grab_slugs_from_links(links)
links.map do |link|
link[:href].split("/documents/").last
end
end

def unlink_document_usages
Expand Down
1 change: 1 addition & 0 deletions trough.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency "refile-s3"
s.add_dependency "aws-sdk"
s.add_dependency 'formtastic-bootstrap', '~> 3.0'
s.add_dependency "nokogiri"

s.add_development_dependency "sqlite3"
end

0 comments on commit bf54b9b

Please sign in to comment.