Module: Landable::TidyService
- Defined in:
- app/services/landable/tidy_service.rb
Defined Under Namespace
Classes: Result, TidyError
Constant Summary
collapse
- @@options =
[
'-utf8',
'-indent',
'--wrap 0',
'--clean true',
'--bare true',
'--quote-ampersand true',
'--break-before-br true',
'--merge-divs false',
'--quiet true',
'--show-warnings false',
]
- @@liquid_elements =
[
'template',
'title_tag',
'meta_tags',
'img_tag',
]
Class Method Summary
collapse
Class Method Details
.call(input, runtime_options = {}) ⇒ Object
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
79
80
81
82
|
# File 'app/services/landable/tidy_service.rb', line 53
def self.call input, runtime_options={}
if not tidyable?
raise 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 $?.exitstatus >= 2 and runtime_options[:raise_on_error]
raise TidyError, "Tidy exited with status #{$?} - check stderr."
end
output = unwrap_liquid output
Result.new output
end
|
.call!(input) ⇒ Object
49
50
51
|
# File 'app/services/landable/tidy_service.rb', line 49
def self.call! input
self.call input, raise_on_error: true
end
|
.tidyable? ⇒ Boolean
84
85
86
|
# File 'app/services/landable/tidy_service.rb', line 84
def self.tidyable?
@@is_tidyable ||= Kernel.system('which tidy > /dev/null')
end
|