Module: MasterView::TidyHelper

Defined in:
lib/masterview/filter_helpers.rb

Overview

Helper services to support a preprocessing filter to run a template document through HTML Tidy to automatically clean up the markup to ensure valid xhtml. Optionally applied to all incoming templates prior to MasterView processing if the MasterView :tidy parser option is enabled.

Unlike web browsers, which for historical and cultural reasons typically accept all sorts of mangled and invalid html and attempt to always produce some form of rendering, MasterView’s template parsing is based on XML parsing technology and requires a syntactically valid xhtml document. If you’re not sure your templates are well-formed, you can turn on the MasterView :tidy parser option to have tidy automatically applied as a preprocessing filter on your templates. (Requires that you have tidy installed on your system; use the MasterView :tidy_path option to specify how MasterView should invoke tidy)

Class Method Summary collapse

Class Method Details

.tidy(html) ⇒ Object

Run HTML tidy on an html document and return the tidy’d output.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/masterview/filter_helpers.rb', line 24

def self.tidy(html)
  Tidy.path = ::MasterView::TidyPath unless Tidy.path
  xml = Tidy.open do |tidy|
    tidy.options.output_xml = true
    tidy.options.indent = true
    tidy.options.wrap = 0
    xml = tidy.clean(html)
  end
  xml = ::MasterView::EscapeErbHelper.escape_erb(xml)
  ::MasterView::Log.debug { 'tidy corrected xml='+xml }
  xml
end