Module: Landable::TidyService
- Defined in:
- app/services/landable/tidy_service.rb
Defined Under Namespace
Classes: Result, TidyError
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.liquid_elements ⇒ Object
Returns the value of attribute liquid_elements.
7
8
9
|
# File 'app/services/landable/tidy_service.rb', line 7
def liquid_elements
@liquid_elements
end
|
.options ⇒ Object
Returns the value of attribute options.
6
7
8
|
# File 'app/services/landable/tidy_service.rb', line 6
def options
@options
end
|
Class Method Details
.call(input, runtime_options = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/services/landable/tidy_service.rb', line 49
def self.call(input, runtime_options = {})
unless tidyable?
fail TidyError, 'Your system doesn\'t seem to have tidy installed. Please see https://github.com/w3c/tidy-html5.'
end
input = wrap_liquid input
output = IO.popen("tidy #{options.join(' ')}", 'r+') do |io|
io.puts input
io.close_write
io.read
end
if $CHILD_STATUS.exitstatus >= 2 && runtime_options[:raise_on_error]
fail TidyError, "Tidy exited with status #{$CHILD_STATUS} - check stderr."
end
output = unwrap_liquid output
Result.new output
end
|
.call!(input) ⇒ Object
45
46
47
|
# File 'app/services/landable/tidy_service.rb', line 45
def self.call!(input)
call input, raise_on_error: true
end
|
.tidyable? ⇒ Boolean
80
81
82
|
# File 'app/services/landable/tidy_service.rb', line 80
def self.tidyable?
@is_tidyable ||= Kernel.system('which tidy > /dev/null')
end
|