Commit d5f5fbd0895c67584a9a6610bb8bcce9cc165630

Authored by Leandro Santos
1 parent c70a99e9

replace Hpricot to Nokogiri

plugins/comment_paragraph/lib/ext/article.rb
@@ -21,12 +21,12 @@ class Article @@ -21,12 +21,12 @@ class Article
21 def comment_paragraph_plugin_parse_html 21 def comment_paragraph_plugin_parse_html
22 comment_paragraph_plugin_set_initial_value unless persisted? 22 comment_paragraph_plugin_set_initial_value unless persisted?
23 return unless comment_paragraph_plugin_activated? 23 return unless comment_paragraph_plugin_activated?
24 -  
25 if body && (body_changed? || setting_changed?(:comment_paragraph_plugin_activate)) 24 if body && (body_changed? || setting_changed?(:comment_paragraph_plugin_activate))
26 parsed_paragraphs = [] 25 parsed_paragraphs = []
27 updated = body_changed? ? body_change[1] : body 26 updated = body_changed? ? body_change[1] : body
28 - doc = Hpricot(updated)  
29 - doc.search("/*").each do |paragraph| 27 + doc = Nokogiri::HTML(updated).css('body')
  28 +
  29 + doc.children.each do |paragraph|
30 if paragraph.to_html =~ /^<div(.*)paragraph_comment(.*)$/ || paragraph.to_html =~ /^<p>\W<\/p>$/ 30 if paragraph.to_html =~ /^<div(.*)paragraph_comment(.*)$/ || paragraph.to_html =~ /^<p>\W<\/p>$/
31 parsed_paragraphs << paragraph.to_html 31 parsed_paragraphs << paragraph.to_html
32 else 32 else
plugins/comment_paragraph/test/unit/allow_comment_test.rb
@@ -32,12 +32,14 @@ class AllowCommentTest &lt; ActiveSupport::TestCase @@ -32,12 +32,14 @@ class AllowCommentTest &lt; ActiveSupport::TestCase
32 end 32 end
33 33
34 should 'not parse contents outside content viewer controller' do 34 should 'not parse contents outside content viewer controller' do
  35 + article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner')
35 content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article) 36 content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article)
36 controller.expects(:kind_of?).with(ContentViewerController).returns(false) 37 controller.expects(:kind_of?).with(ContentViewerController).returns(false)
37 assert_equal 'inner', instance_eval(&content) 38 assert_equal 'inner', instance_eval(&content)
38 end 39 end
39 40
40 should 'not parse contents if comment_paragraph is not activated' do 41 should 'not parse contents if comment_paragraph is not activated' do
  42 + article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner')
41 article.expects(:comment_paragraph_plugin_activated?).returns(false) 43 article.expects(:comment_paragraph_plugin_activated?).returns(false)
42 content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article) 44 content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article)
43 controller.expects(:kind_of?).with(ContentViewerController).returns(true) 45 controller.expects(:kind_of?).with(ContentViewerController).returns(true)