Class: FontelloRailsConverter::Cli

Inherits:
Object
  • Object
show all
Includes:
ColorizedOutput
Defined in:
lib/fontello_rails_converter/cli.rb

Instance Method Summary collapse

Methods included from ColorizedOutput

#colorize

Constructor Details

#initialize(options) ⇒ Cli

Returns a new instance of Cli.



9
10
11
12
# File 'lib/fontello_rails_converter/cli.rb', line 9

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

Instance Method Details

#convertObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fontello_rails_converter/cli.rb', line 36

def convert
  if @options[:no_download] == true
    puts "Use existing '#{@options[:zip_file]}' file due to `--no-download` switch"
  else
    self.download
  end

  puts "---- convert -----"
  prepare_directories

  if zip_file_exists?
    Zip::File.open(@options[:zip_file]) do |zipfile|
      grouped_files = zipfile.group_by{ |file| file.to_s.split("/")[1] }

      copy_and_convert_stylesheets(zipfile, grouped_files['css'])
      copy_font_files(zipfile, grouped_files['font'])
      copy_and_convert_icon_guide(zipfile, grouped_files['demo.html'].first)
    end
  end
end

#downloadObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fontello_rails_converter/cli.rb', line 22

def download
  puts "---- download ----"

  if @options[:use_config] == true && config_file_exists?
    puts "Using '#{options[:config_file]}' to create new fontello session"
    @fontello_api.new_session_from_config
  end

  File.open(@options[:zip_file], "w+") do |file|
    file.write @fontello_api.download_zip_body
  end
  puts green "Downloaded '#{@options[:zip_file]}' from fontello (#{@fontello_api.session_url})"
end

#openObject



14
15
16
17
18
19
20
# File 'lib/fontello_rails_converter/cli.rb', line 14

def open
  puts "---- open ----"
  if config_file_exists?
    @fontello_api.new_session_from_config  unless @options[:open_existing] == true
    Launchy.open @fontello_api.session_url
  end
end