Class: Prettyp::Formatter::HTML::Tidy

Inherits:
BaseFormatter show all
Defined in:
lib/prettyp/formatter/html/tidy.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFormatter

#check_requirement, inherited, inherited_classes

Methods included from Logger

logger, #logger

Class Method Details

.check_requirementObject



12
13
14
# File 'lib/prettyp/formatter/html/tidy.rb', line 12

def self.check_requirement
  !%x|which #{executeable}|.empty?
end

.executeableObject



10
# File 'lib/prettyp/formatter/html/tidy.rb', line 10

def self.executeable; 'tidy'; end

.languagesObject



6
7
8
# File 'lib/prettyp/formatter/html/tidy.rb', line 6

def self.languages
  ['HTML']
end

Instance Method Details

#format(input, language) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/prettyp/formatter/html/tidy.rb', line 16

def format input, language
  with_file(input) do |file|
    with_tempfile '' do |tmp|
      out = execute_command("#{self.class.executeable} -im #{file.path} -f #{tmp.path} -q",
                            #on_error: Proc.new { |output| raise FormatError, output })
                            on_error: Proc.new { })
      out = File.read(file.path)
      out
    end
  end
end