Class: Prettyp::Formatter::XML::Xmllint

Inherits:
BaseFormatter show all
Defined in:
lib/prettyp/formatter/xml/xmllint.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



11
12
13
# File 'lib/prettyp/formatter/xml/xmllint.rb', line 11

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

.executeableObject



10
# File 'lib/prettyp/formatter/xml/xmllint.rb', line 10

def self.executeable; 'xmllint'; end

.languagesObject



6
7
8
# File 'lib/prettyp/formatter/xml/xmllint.rb', line 6

def self.languages
  [:xml, :html]
end

Instance Method Details

#format(input, language) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/prettyp/formatter/xml/xmllint.rb', line 15

def format input, language
  extra_opts = '--html' if language.eql? :html
  with_file(input) do |file|
    out = execute_command("cat #{file.path} | #{self.class.executeable} --format #{extra_opts} -",
                          on_error: Proc.new { |output| raise FormatError, output })
  end
end