class HtmlToHaml::Html::CommentConversionUseCase
Constants
- HTML_COMMENT_REGEX
- HTML_USING_HAML_COMMENT_SYNTAX
Public Class Methods
new(html)
click to toggle source
# File lib/html_to_haml/use_cases/html/comment_conversion_use_case.rb, line 8 def initialize(html) @html = html end
Public Instance Methods
convert()
click to toggle source
# File lib/html_to_haml/use_cases/html/comment_conversion_use_case.rb, line 12 def convert haml = @html.gsub(/#{HTML_COMMENT_REGEX}|#{HTML_USING_HAML_COMMENT_SYNTAX}/) do |comment| case comment when /#{HTML_COMMENT_REGEX}/ "\n/ #{format_html_comment_for_haml(comment: comment)}\n" when /#{HTML_USING_HAML_COMMENT_SYNTAX}/ escape_misleading_forward_slash(comment: comment) end end haml.gsub(/\n\s*\n/, "\n") end
Private Instance Methods
escape_misleading_forward_slash(comment:)
click to toggle source
# File lib/html_to_haml/use_cases/html/comment_conversion_use_case.rb, line 30 def escape_misleading_forward_slash(comment:) comment.gsub(/^(\s*)\//, '\1\/') end
format_html_comment_for_haml(comment:)
click to toggle source
# File lib/html_to_haml/use_cases/html/comment_conversion_use_case.rb, line 26 def format_html_comment_for_haml(comment:) comment.gsub(/\n\s*/, "\n/ ")[4..-4].strip end