class TidyFFI::Tidy

Clean and simple interface to Tidy

Constants

OptionsContainer

Attributes

validate_options[W]

Public Class Methods

clean(str, options = {}) click to toggle source

Returns cleaned string

# File lib/tidy_ffi/tidy.rb, line 29
def self.clean(str, options = {})
  new(str, options).clean
end
default_options() click to toggle source

Default options for tidy. Works just like options method

# File lib/tidy_ffi/tidy.rb, line 61
def default_options
  @default_options ||= OptionsContainer.new
end
default_options=(options) click to toggle source

Default options for tidy. Works just like options= method

# File lib/tidy_ffi/tidy.rb, line 66
def default_options=(options)
  @default_options.merge_with_options(options)
end
new(str, options = {}) click to toggle source

Initializing object.

  • str is a string to tidy

  • options are options for tidy

# File lib/tidy_ffi/tidy.rb, line 11
def initialize(str, options = {})
  @string = str
  @options = OptionsContainer.new(self.class.default_options)
  self.options = options
end
validate_options?() click to toggle source

When true it validates name and option type (default is true).

# File lib/tidy_ffi/tidy.rb, line 78
def validate_options?
  @validate_options != false
end
with_options(options) click to toggle source

Returns a proxy class with options. Example:

TidyFFI::Tidy.with_options(:show_body_only => true).with_options(:wrap_asp => true).new('test)
# File lib/tidy_ffi/tidy.rb, line 73
def with_options(options)
  OptionsContainer::Proxy.new(self, @default_options, options)
end

Public Instance Methods

clean() click to toggle source

Returns cleaned string

# File lib/tidy_ffi/tidy.rb, line 18
def clean
  @clean ||= TidyFFI::Interface.with_doc do |doc|
    doc.apply_options(@options.to_hash!)
    doc.string = @string
    doc.clean
    @errors = doc.errors
    doc.output
  end
end
errors() click to toggle source

Returns errors for string

# File lib/tidy_ffi/tidy.rb, line 34
def errors
  @errors ||= begin
    clean
    @errors
  end
end
options() click to toggle source

Proxy for options. Supports set and get

tidy.options.show_body_only #=> nil
tidy.options.show_body_only = true
tidy.options.show_body_only #=> true
# File lib/tidy_ffi/tidy.rb, line 55
def options
  @options
end
options=(options) click to toggle source

Assigns options for tidy. It merges options, not deletes old ones.

tidy.options= {:wrap_asp => true}
tidy.options= {:show_body_only => true}

Will send to tidy both options.

# File lib/tidy_ffi/tidy.rb, line 46
def options=(options)
  @options.merge_with_options(options)
end