Sha256: 64debfbf8218ef59bcb46a9af35b393ee538f3bd5ec192e2a1693caf01942735

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

def images
  local_image_path = File.expand_path("~/.memegen")
  base = File.join(File.dirname(__FILE__), "..", "..", "generators")
  Dir.glob(["#{base}/*", "#{local_image_path}/*.*"])
end

def usage
  puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c] [--help|-h] [--install-autocomplete]'
  exit 1
end

def list_generators
  names = images.map { |path|
    File.basename(path).gsub(/\..*/, '')
  }.sort

  names.each { |name| puts name }
  exit 0
end

def parse_path(string)
  if string =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
    path = "/tmp/memegen-download-#{Time.now.to_i}"
    `curl "#{image}" -o #{path} --silent`
  elsif path = images.find { |p| p =~ /\/#{string}\..*$/ }
  else
    puts "Error: Image not found. Use --list to view installed images."
    exit 1
  end
  path
end

def generate(path, top, bottom, campfire)
  if top || bottom
    output_path = MemeGenerator.generate(path, top, bottom)

    if campfire
      MemeGenerator::Campfire.upload(output_path)
    else
      puts output_path
    end
    exit 0
  else
    puts "Error: You must provide at least one piece of text"
    usage
  end
end

def install_autocomplete
  path = File.join(File.dirname(__FILE__), "..", "..", "script", "autocomplete.sh")
  puts <<-END
Source autocomplete.sh in your ~/.bashrc:

    $ echo "source #{path}" >> ~/.bashrc

Then source the profile:

    $ source ~/.bashrc

You can copy the path to autocomplete.sh somewhere in your home directory if
you upgrade gem versions, but it should always work.

(Sorry, this sucks but I don't know a foolproof way to do this)
END
  exit 0
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
memegen-1.0.4 lib/meme_generator/cli.rb