Method: WindClutter::Processor.auto_process

Defined in:
lib/windclutter/processor.rb

.auto_process(file_content, collections) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/windclutter/processor.rb', line 22

def self.auto_process(file_content, collections)
  return if file_content.nil?

  regex = /class="(?:(?!#{@key_tag}:)[^"])*"/
  class_occurrences = file_content.scan(regex)

  class_occurrences.each do |occurrence|
    gen_class = Generator.random_class
    file_content = file_content.gsub(/#{occurrence}/, "class=\"#{gen_class}\"")

    collections.push({
                       generated_name: gen_class,
                       provided_name: nil,
                       class: occurrence.to_s.match(/class="([^"]*)"/)[1],
                       named: false
                     })
  end
  file_content
end