module ErbToSlim

Constants

VERSION

Public Class Methods

start!() click to toggle source
# File lib/erb_to_slim.rb, line 7
def self.start!
  return p(ErbToSlim::VERSION) if ARGV.include? '--version' or ARGV.include? '-v'

  Dir.chdir Dir.pwd do
    Dir['**/*.{html.erb}'].each do |file|
      String.send(:include, ErbToSlim::Engine)

      stream = File.read(file)

      stream.markup_js_tag
      stream.cleanup_close_tag
      stream.replace_html_tag
      stream.replace_erb_exec_tag
      stream.replace_erb_eval_tag
      stream.replace_string_literal
      stream.replace_tag_with_id
      stream.replace_tag_with_class
      stream.finally_clean_up

      slim_file = "#{File.dirname(file)}/#{File.basename(file, '.erb')}.slim"

      File.open(slim_file, "w") do |f|
        f.write(stream)
      end

      puts "==> #{slim_file}"

      File.rename(file, "#{file}.bak")
    end
  end
end