<commit_before>require 'fileutils'
require 'launchy'
require 'zip'

module FontelloRailsConverter
  class Cli
    include ColorizedOutput

    def initialize(options)
      @options = options
      @fontello_api = FontelloApi.new @options
    end

    def open
      @fontello_api.new_session_from_config  unless @options[:open_existing] == true
      Launchy.open @fontello_api.session_url
    end

    def download
      @fontello_api.new_session_from_config  if @options[:use_config] == true
      File.open(@options[:zip_file], "w+") do |file|
        file.write @fontello_api.download_zip_body
      end
    end

    def convert
      self.download  unless @options[:no_download] == true || !config_file_exists?
      self.prepare_directories

      Zip::File.open(@options[:zip_file]) do |zipfile|
        zipfile.each do |file|
          filename = file.to_s.split("/").last

          # stylesheets
          if filename.end_with? '.css'
            # extract stylesheet to target location
            target_file = File.join @options[:stylesheet_dir], filename.gsub('.css', @options[:stylesheet_extension])
            zipfile.extract(file, target_file) { true }
            puts green("copied #{target_file}")

            if !filename.end_with? "animation.css", "-ie7.css", "-codes.css", "-ie7-codes.css", "-embedded.css"
              converted_css = self.convert_main_stylesheet File.read(target_file).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
              File.open(target_file, 'w') { |f| f.write(converted_css) }
              puts green("converted #{target_file} for Sass & asset pipeline")
            end

          # font files<commit_msg>if theres no config file... don't fail and show instructions instead<commit_after>require 'fileutils'
require 'launchy'
require 'zip'

module FontelloRailsConverter
  class Cli
    include ColorizedOutput

    def initialize(options)
      @options = options
      @fontello_api = FontelloApi.new @options
    end

    def open
      if config_file_exists?
        @fontello_api.new_session_from_config  unless @options[:open_existing] == true
        Launchy.open @fontello_api.session_url
      else
        puts red("there's no config file yet!")
        puts red("follow these instructions: https://github.com/railslove/fontello_rails_converter#initial-usage")
        puts red("to setup your project")
      end
    end

    def download
      @fontello_api.new_session_from_config  if @options[:use_config] == true
      File.open(@options[:zip_file], "w+") do |file|
        file.write @fontello_api.download_zip_body
      end
    end

    def convert
      self.download  unless @options[:no_download] == true || !config_file_exists?
      self.prepare_directories

      Zip::File.open(@options[:zip_file]) do |zipfile|
        zipfile.each do |file|
          filename = file.to_s.split("/").last

          # stylesheets
          if filename.end_with? '.css'
            # extract stylesheet to target location
            target_file = File.join @options[:stylesheet_dir], filename.gsub('.css', @options[:stylesheet_extension])
            zipfile.extract(file, target_file) { true }
            puts green("copied #{target_file}")

            if !filename.end_with? "animation.css", "-ie7.css", "-codes.css", "-ie7-codes.css", "-embedded.css"
              converted_css = self.convert_main_stylesheet File.read(target_file).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
              File.open(target_file, 'w') { |f| f.write(converted_css) }
              puts green("converted #{target_file} for Sass & asset pipeline")
            end

          # font files
{'fraction_non_alphanumeric': 0.11459459459459459, 'fraction_numerical': 0.0016216216216216215, 'mean_word_length': 2.8233471074380163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3934405', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1077, 'n_words': 247}