Class: TidyFFI::Tidy
- Inherits:
-
Object
- Object
- TidyFFI::Tidy
- Defined in:
- lib/tidy_ffi/tidy.rb
Overview
Clean and simple interface to Tidy
Defined Under Namespace
Classes: InvalidOptionName, InvalidOptionValue
Constant Summary collapse
- OptionsContainer =
TidyFFI::OptionsContainer
Class Attribute Summary collapse
-
.validate_options ⇒ Object
writeonly
Sets the attribute validate_options.
Class Method Summary collapse
-
.clean(str, options = {}) ⇒ Object
Returns cleaned string.
-
.default_options ⇒ Object
Default options for tidy.
-
.default_options=(options) ⇒ Object
Default options for tidy.
-
.validate_options? ⇒ Boolean
When true it validates name and option type (default is true).
-
.with_options(options) ⇒ Object
Returns a proxy class with options.
Instance Method Summary collapse
-
#clean ⇒ Object
Returns cleaned string.
-
#errors ⇒ Object
Returns errors for string.
-
#initialize(str, options = {}) ⇒ Tidy
constructor
Initializing object.
-
#options ⇒ Object
Proxy for options.
-
#options=(options) ⇒ Object
Assigns options for tidy.
Constructor Details
#initialize(str, options = {}) ⇒ Tidy
Initializing object.
-
str is a string to tidy
-
options are options for tidy
11 12 13 14 15 |
# File 'lib/tidy_ffi/tidy.rb', line 11 def initialize(str, = {}) @string = str @options = OptionsContainer.new(self.class.) self. = end |
Class Attribute Details
.validate_options=(value) ⇒ Object (writeonly)
Sets the attribute validate_options
81 82 83 |
# File 'lib/tidy_ffi/tidy.rb', line 81 def (value) @validate_options = value end |
Class Method Details
.clean(str, options = {}) ⇒ Object
Returns cleaned string
29 30 31 |
# File 'lib/tidy_ffi/tidy.rb', line 29 def self.clean(str, = {}) new(str, ).clean end |
.default_options ⇒ Object
Default options for tidy. Works just like options method
61 62 63 |
# File 'lib/tidy_ffi/tidy.rb', line 61 def @default_options ||= OptionsContainer.new end |
.default_options=(options) ⇒ Object
Default options for tidy. Works just like options= method
66 67 68 |
# File 'lib/tidy_ffi/tidy.rb', line 66 def () @default_options.() end |
.validate_options? ⇒ Boolean
When true it validates name and option type (default is true).
78 79 80 |
# File 'lib/tidy_ffi/tidy.rb', line 78 def @validate_options != false end |
.with_options(options) ⇒ Object
Returns a proxy class with options. Example:
TidyFFI::Tidy.with_options(:show_body_only => true).with_options(:wrap_asp => true).new('test)
73 74 75 |
# File 'lib/tidy_ffi/tidy.rb', line 73 def () OptionsContainer::Proxy.new(self, @default_options, ) end |
Instance Method Details
#clean ⇒ Object
Returns cleaned string
18 19 20 21 22 23 24 25 26 |
# File 'lib/tidy_ffi/tidy.rb', line 18 def clean @clean ||= TidyFFI::Interface.with_doc do |doc| doc.(@options.to_hash!) doc.string = @string doc.clean @errors = doc.errors doc.output end end |
#errors ⇒ Object
Returns errors for string
34 35 36 37 38 39 |
# File 'lib/tidy_ffi/tidy.rb', line 34 def errors @errors ||= begin clean @errors end end |
#options ⇒ Object
Proxy for options. Supports set and get
tidy..show_body_only #=> nil
tidy..show_body_only = true
tidy..show_body_only #=> true
55 56 57 |
# File 'lib/tidy_ffi/tidy.rb', line 55 def @options end |
#options=(options) ⇒ Object
Assigns options for tidy. It merges options, not deletes old ones.
tidy.= {:wrap_asp => true}
tidy.= {:show_body_only => true}
Will send to tidy both options.
46 47 48 |
# File 'lib/tidy_ffi/tidy.rb', line 46 def () @options.() end |