Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace Nokogiri/loofah with Hpricot, which preserves HTML entities.

Nokogiri appears to not be able to leave them unchanges after parsing.
  • Loading branch information...
commit 7225bf1bc7f61de9ca274f3bf45b9b0d87524ea5 1 parent b5415ec
@aceofspades authored
View
4 app/models/caloris/content_page.rb
@@ -82,8 +82,8 @@ def wrapped_contents
def contents
unless @contents
@contents = {}
- doc.search('.caloris-content').each do |content|
- key = content.attributes['data-content-for'].try(:value)
+ doc.search('//.caloris-content').each do |content|
+ key = content.attributes.to_hash['data-content-for']
@contents[key] = content.inner_html.strip
end
end
View
5 app/models/caloris/metadata.rb
@@ -16,8 +16,9 @@ def self.parse fragment
select_attrs = %w(data-content data-scheme)
metadata = Hash[fragment.search('div').map {|elem|
#puts elem.attributes.inspect
- attrs = Hash[elem.attributes.slice(*select_attrs).map{|k, v| [k, v.value]}]
- [elem.attributes['data-name'].value, attrs]}]
+ attrs = elem.attributes.to_hash
+ good_attrs = Hash[attrs.slice(*select_attrs).map{|k, v| [k, v]}]
+ [attrs['data-name'], good_attrs]}]
new(metadata)
end
View
10 app/models/caloris/page.rb
@@ -1,5 +1,4 @@
-require 'nokogiri'
-require 'loofah'
+require 'hpricot'
require 'tilt_ext'
module Caloris
@@ -70,7 +69,8 @@ def render
end
def render_page
- "<% content_for :page do %>#{page_content}<% end %>"
+ html = Tilt.new(identifier) { page_content }.render_tidy
+ "<% content_for :page do %>\n#{html}<% end %>\n"
end
# Return body for search
@@ -131,11 +131,11 @@ def page_content_html
end
def doc
- @doc ||= ::Nokogiri::HTML.fragment(page_content_html)
+ @doc ||= Hpricot(page_content_html)
end
def content_doc
- @content_doc ||= Loofah.fragment(Caloris::ErbString.new(page_content).gsub(/<erb>.*<\/erb>/, ' '))
+ @content_doc ||= Hpricot(Caloris::ErbString.new(page_content).gsub(/<erb>.*<\/erb>/, ' '))
end
def render_tidy
View
3  caloris.gemspec
@@ -26,8 +26,7 @@ Gem::Specification.new do |s|
# s.add_dependency "jquery-rails"
s.add_dependency "mercury-rails"
#s.add_dependency "tilt"
- s.add_dependency "nokogiri", "~> 1.5.0"
- s.add_dependency "loofah"
+ s.add_dependency "hpricot"
s.add_dependency "tidy_ffi"
s.add_dependency "grit"
s.add_dependency "bootstrap-sass"
Please sign in to comment.
Something went wrong with that request. Please try again.