Class: Nanoc::Tidy::Filter

Inherits:
Filter
  • Object
show all
Includes:
FileUtils, Spawn
Defined in:
lib/nanoc/tidy/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Spawn

#spawn

Class Method Details

.default_argvArray<String>

The default argv for tidy-html5

Examples:

Nanoc::Tidy.default_argv.concat ["-upper"]

Returns:

  • (Array<String>)

    Default argv for tidy-html5



21
22
23
# File 'lib/nanoc/tidy/filter.rb', line 21

def self.default_argv
  @default_argv ||= ["-wrap", "120", "-indent"]
end

Instance Method Details

#run(content, options = {}) ⇒ String

Runs the filter

Parameters:

  • content (String)

    HTML content

  • options (Hash) (defaults to: {})

    Filter options

Returns:

  • (String)

    Returns HTML content (modified)



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nanoc/tidy/filter.rb', line 36

def run(content, options = {})
  options = Ryo(options)
  file = temporary_file(
    File.basename(item.identifier.to_s),
    content
  )
  spawn options.exe || "tidy5",
        [*default_argv, *(options.argv || []), "-modify", file.path]
  File.read(file.path)
ensure
  file ? file.tap(&:unlink).close : nil
end