# frozen_string_literal: true module Docx module Builder # Methods used for cleaning variables inside template module Cleaners def self.starting_tags_without_spaces_cleaner(str) str&.gsub(/\{\s*\{\s*%/, '{{%') end def self.ending_tags_without_spaces_cleaner(str) str&.gsub(/%\s*\}\s*\}/, '%}}') end def self.single_quote_cleaner(str) str&.gsub(/‘/, '\'')&.gsub(/’/, '\'') end def self.var_without_duplicated_spaces_cleaner(str) str&.gsub(/\s+/, ' ') end def self.var_without_spaces_inside_brackets_cleaner(str) str&.gsub(/\[(.*?)\]/) { |match| match.gsub(/\s/, '') } end def self.no_spaces_around_undeline_cleaner(str) str&.gsub(/\s*_\s*/, '_') end def self.join_dots_and_brackets_cleaner(str) str && str.gsub(/\s*\.\s*/, '.').gsub(/\s*\[\s*/, '[').gsub(/\s*\]/, ']') end def self.question_method_cleaner(str) if str && str =~ /\A\{\{\s+if\s*(.*?)\s*\?\s+\}\}\Z/ "{{ if #{Regexp.last_match(1)}\? }}" else str end end end end end