class HtmlToHaml::NonHtmlSelectorBlocks::BasicConversionUseCase
Constants
- RUBY_HAML_REGEX
Public Class Methods
new(special_html)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 14 def initialize(special_html) @special_html = special_html end
Public Instance Methods
convert()
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 18 def convert indentation_tracker = IndentationTracker.new(indented: false, adjust_whitespace: false) haml = @special_html.gsub(/#{opening_tag_regex}|#{closing_tag_regex}|#{RUBY_HAML_REGEX}|(\n\s*)/) do |tag| replace_tag_value(tag: tag, indentation_tracker: indentation_tracker) end remove_haml_whitespace(haml: haml) end
Private Instance Methods
adjust_whitespace?(indentation_tracker:, tag:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 64 def adjust_whitespace?(indentation_tracker:, tag:) tag_indented = tag.include?(indentation) tag =~ /\n/ && indentation_tracker.adjust_whitespace?(reset_value: !tag_indented) end
close_tag(indentation_tracker:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 51 def close_tag(indentation_tracker:) indentation_tracker.outdent "\n" end
indentation()
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 69 def indentation " " * HtmlToHaml::INDENTATION_AMOUNT end
open_tag(tag:, indentation_tracker:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 42 def open_tag(tag:, indentation_tracker:) indentation_tracker.indent opening_tag(tag: tag) end
opening_tag(tag:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 47 def opening_tag(tag:) ":#{tag_type(tag: tag)}\n#{indentation}" end
replace_tag_value(tag:, indentation_tracker:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 28 def replace_tag_value(tag:, indentation_tracker:) if opening_tag?(tag: tag, in_block: indentation_tracker.indented) open_tag(tag: tag, indentation_tracker: indentation_tracker) elsif closing_tag?(tag: tag, in_block: indentation_tracker.indented) close_tag(indentation_tracker: indentation_tracker) elsif use_string_interpolation?(tag: tag, in_block: indentation_tracker.indented) string_interpolated_ruby(tag: tag) elsif adjust_whitespace?(tag: tag, indentation_tracker: indentation_tracker) "#{tag}#{indentation}" else tag end end
string_interpolated_ruby(tag:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 60 def string_interpolated_ruby(tag:) "\#{#{tag.strip[1..-1].strip}}" end
use_string_interpolation?(tag:, in_block:)
click to toggle source
# File lib/html_to_haml/use_cases/non_html_selector_blocks/basic_conversion_use_case.rb, line 56 def use_string_interpolation?(tag:, in_block:) in_block && tag =~ /#{RUBY_HAML_REGEX}/ end