Permalink
Browse files

Using XLST to pretty-print, wip.

  • Loading branch information...
1 parent 54b9544 commit 6f2e46f18b0488d7f506fbaab5099abb30e6b30f @aceofspades committed Jan 19, 2012
Showing with 16 additions and 1 deletion.
  1. +12 −0 config/pretty_print.xslt
  2. +4 −1 lib/caloris/page.rb
View
12 config/pretty_print.xslt
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:strip-space elements="*" />
+ <xsl:output omit-xml-declaration="yes" method="xml" indent="yes" />
+
+ <xsl:template match="node()|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="node()|@*" />
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
View
5 lib/caloris/page.rb
@@ -27,13 +27,16 @@ def initialize site, path
def update data
html = read
- doc = ::Nokogiri::HTML.parse(html)
+ #doc = ::Nokogiri::XML.fragment(html)
+ doc = ::Nokogiri::XML.parse(html)
data.each do |id, elem_data|
elem = doc.search("##{id}").try(:first)
raise "Element ##{id} not found" unless elem.present?
elem.inner_html = elem_data['value']
end
+ # http://emmanueloga.wordpress.com/2009/09/29/pretty-printing-xhtml-with-nokogiri-and-xslt/
+ @xsl = Nokogiri::XSLT(File.read(File.expand_path('../../../config/pretty_print.xslt', __FILE__)))
new_html = @xsl.apply_to(doc).to_s
#new_html = self.class.tidy(doc.to_html)
write(new_html)

0 comments on commit 6f2e46f

Please sign in to comment.