Class: Nagoro::Pipe::Tidy

Inherits:
Base
  • Object
show all
Defined in:
lib/nagoro/pipe/tidy.rb

Overview

Small wrapper that pipes the template through tidy.

For configuration see the FLAGS, it’s an array of arguments passed to the tidy command.

We are not using the ruby tidy library to avoid memory-leaks and dependencies. Please make sure you do have a binary called ‘tidy` in your `PATH` before using this library.

This pipe relies on open3 from the standard library.

Regarding Windows

There have been numerous reports that open3 doesn’t work on Windows, since it relies on Kernel#fork, as syscall that is not supported on that platform.

Two possible solutions exist:

  • There is a win32-popen implementation in RAA

  • Kernel#fork works in cygwin.

I don’t have a copy of windows, so it’s hard for me to try either of these options. Please send me a patch if you find a cross-platform way of implementing this functionality.

Constant Summary collapse

FLAGS =

Possible flags can be found in ‘tidy -help` and `tidy -help-config`

%w[-utf8 -asxhtml -quiet -indent --tidy-mark no]

Constants inherited from Base

Base::EMPTY_TAG

Instance Method Summary collapse

Methods inherited from Base

#append, #doctype, #initialize, #instruction, #tag_end, #tag_start, #tag_with, #text

Constructor Details

This class inherits a constructor from Nagoro::Pipe::Base

Instance Method Details

#resultObject



34
35
36
37
# File 'lib/nagoro/pipe/tidy.rb', line 34

def result
  @scanner.stream
  tidy(@body.join)
end

#tidy(string) ⇒ String

Pipe given string through the tidy binary.

Parameters:

  • string (#to_s)

Returns:

  • (String)

Author:

  • manveru



44
45
46
# File 'lib/nagoro/pipe/tidy.rb', line 44

def tidy(string)
  Nagoro::Tidy.tidy(string, FLAGS)
end