Module: Docx::Builder::Cleaners

Defined in:
lib/docx/builder/cleaners.rb

Overview

Methods used for cleaning variables inside template

Class Method Summary collapse

Class Method Details

.ending_tags_without_spaces_cleaner(str) ⇒ Object



11
12
13
# File 'lib/docx/builder/cleaners.rb', line 11

def self.ending_tags_without_spaces_cleaner(str)
  str&.gsub(/%\s*\}\s*\}/, '%}}')
end

.join_dots_and_brackets_cleaner(str) ⇒ Object



31
32
33
# File 'lib/docx/builder/cleaners.rb', line 31

def self.join_dots_and_brackets_cleaner(str)
  str && str.gsub(/\s*\.\s*/, '.').gsub(/\s*\[\s*/, '[').gsub(/\s*\]/, ']')
end

.no_spaces_around_undeline_cleaner(str) ⇒ Object



27
28
29
# File 'lib/docx/builder/cleaners.rb', line 27

def self.no_spaces_around_undeline_cleaner(str)
  str&.gsub(/\s*_\s*/, '_')
end

.question_method_cleaner(str) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/docx/builder/cleaners.rb', line 35

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

.single_quote_cleaner(str) ⇒ Object



15
16
17
# File 'lib/docx/builder/cleaners.rb', line 15

def self.single_quote_cleaner(str)
  str&.gsub(//, '\'')&.gsub(//, '\'')
end

.starting_tags_without_spaces_cleaner(str) ⇒ Object



7
8
9
# File 'lib/docx/builder/cleaners.rb', line 7

def self.starting_tags_without_spaces_cleaner(str)
  str&.gsub(/\{\s*\{\s*%/, '{{%')
end

.var_without_duplicated_spaces_cleaner(str) ⇒ Object



19
20
21
# File 'lib/docx/builder/cleaners.rb', line 19

def self.var_without_duplicated_spaces_cleaner(str)
  str&.gsub(/\s+/, ' ')
end

.var_without_spaces_inside_brackets_cleaner(str) ⇒ Object



23
24
25
# File 'lib/docx/builder/cleaners.rb', line 23

def self.var_without_spaces_inside_brackets_cleaner(str)
  str&.gsub(/\[(.*?)\]/) { |match| match.gsub(/\s/, '') }
end