Sha256: a6ccf36c962ed5002d3d6124361cf71fa211f9dfb552fc7ebbfe49a04596c764

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module WebTranslateIt
  class Util    
    DEFAULT_TERMINAL_COLORS = "\e[0m\e[37m\e[40m"
    MONOCHROME_OUTPUT = "\\1"
    
    def self.colourise_output?
      @colourise_output = !!(RUBY_PLATFORM !~ /mswin/ || defined?(Win32::Console::ANSI)) if @colourise_output.nil?
      @colourise_output
    end

    def self.subs_colour(data)
      data = data.gsub(%r{<b>(.*?)</b>}m, colourise_output? ? "\e[1m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
      data.gsub!(%r{<red>(.*?)</red>}m, colourise_output? ? "\e[1m\e[31m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
      data.gsub!(%r{<green>(.*?)</green>}m, colourise_output? ? "\e[1m\e[32m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
      data.gsub!(%r{<yellow>(.*?)</yellow>}m, colourise_output? ? "\e[1m\e[33m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
      data.gsub!(%r{<banner>(.*?)</banner>}m, colourise_output? ? "\e[33m\e[44m\e[1m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
      data
    end
    
    def self.insert_into(file, line)
      logger.insert "#{line} into #{file}"
      unless options[:pretend] || file_contains?(file, line)
        gsub_file file, /^(class|module) .+$/ do |match|
          "#{match}\n  #{line}"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
web_translate_it-1.4.0 lib/web_translate_it/util.rb