Class: Seo::HtmlPrettyPrinter
- Inherits:
-
BaseService
- Object
- BaseService
- Seo::HtmlPrettyPrinter
- Defined in:
- app/services/seo/html_pretty_printer.rb
Overview
Service object: html pretty printer.
Defined Under Namespace
Classes: Result
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#process(html_fragment) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/seo/html_pretty_printer.rb', line 9 def process(html_fragment) logger.tagged('Seo::HtmlPrettyPrinter') do errors = [] begin # Use HtmlBeautifier to format the HTML pretty_html = HtmlBeautifier.beautify(html_fragment, indent: ' ') Result.new( html_out: pretty_html, errors: errors ) rescue StandardError => e errors << { error: e. } logger.error "Error pretty printing HTML: #{e.}" Result.new( html_out: html_fragment, # Return original HTML if there's an error errors: errors ) end end end |