memegen 0.0.10 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,62 +4,16 @@ $LOAD_PATH.unshift File.expand_path("lib")
4
4
  $LOAD_PATH.unshift File.expand_path("../lib")
5
5
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
6
6
 
7
- URL_REGEX = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
7
+ require "meme_generator/cli"
8
8
 
9
- def images
10
- local_image_path = File.expand_path("~/.memegen")
11
- Dir.glob(["generators/*", "#{local_image_path}/*."])
12
- end
13
-
14
- def usage
15
- puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c]'
16
- exit 1
17
- end
18
-
19
- # Process command
20
9
  image, top, bottom = ARGV[0..2]
10
+ help = ARGV.include?("--help") || ARGV.include?("-h")
11
+ list = ARGV.include?("--list") || ARGV.include?("-l")
12
+ campfire = ARGV.include?("--campfire") || ARGV.include?("-c")
21
13
 
22
- # List
23
- if ARGV.delete("--list")
24
- names = images.map { |path|
25
- File.basename(path).gsub(/\..*/, '')
26
- }.sort
27
-
28
- names.each { |name| puts name }
29
- exit 0
30
- end
31
-
32
- # Campfire setup
33
- require "meme_generator/campfire"
34
- campfire = ARGV.delete("--campfire") || ARGV.delete("-c")
35
- if campfire && !MemeGenerator::Campfire.config
36
- MemeGenerator::Campfire.prompt_config
37
- end
38
-
39
- # URL
40
- if image =~ URL_REGEX
41
- path = "/tmp/memegen-download-#{Time.now.to_i}"
42
- `curl "#{image}" -o #{path} --silent`
43
- elsif path = images.find { |p| p =~ /#{image}\./ }
44
- # Success!
45
- else
46
- puts "Error: Image not found. Use --list to view installed images."
47
- exit 1
48
- end
49
-
50
- # Require at least one text argument
51
- if top || bottom
52
- require "meme_generator"
53
- output_path = MemeGenerator.generate(path, top, bottom)
54
-
55
- if campfire
56
- MemeGenerator::Campfire.upload(output_path)
57
- else
58
- puts output_path
59
- end
60
- exit 0
61
- else
62
- puts "Error: You must provide at least one piece of text"
63
- usage
64
- end
14
+ usage if help || ARGV.empty?
15
+ list_generators if list
16
+ setup_campfire if campfire
65
17
 
18
+ path = parse_path(image)
19
+ generate(path, top, bottom, campfire)
@@ -2,7 +2,7 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
 
4
4
  class MemeGenerator
5
- VERSION = "0.0.10"
5
+ VERSION = "1.0.0"
6
6
 
7
7
  class << self
8
8
  def generate(path, top, bottom)
@@ -0,0 +1,55 @@
1
+ def images
2
+ local_image_path = File.expand_path("~/.memegen")
3
+ base = File.join(File.dirname(__FILE__), "..", "..", "generators")
4
+ Dir.glob(["#{base}/*", "#{local_image_path}/*.*"])
5
+ end
6
+
7
+ def usage
8
+ puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c] [--help|-h]'
9
+ exit 1
10
+ end
11
+
12
+ def list_generators
13
+ names = images.map { |path|
14
+ File.basename(path).gsub(/\..*/, '')
15
+ }.sort
16
+
17
+ names.each { |name| puts name }
18
+ exit 0
19
+ end
20
+
21
+ def setup_campfire
22
+ require "meme_generator/campfire"
23
+ if !MemeGenerator::Campfire.config
24
+ MemeGenerator::Campfire.prompt_config
25
+ end
26
+ end
27
+
28
+ def parse_path(string)
29
+ if string =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
30
+ path = "/tmp/memegen-download-#{Time.now.to_i}"
31
+ `curl "#{image}" -o #{path} --silent`
32
+ elsif path = images.find { |p| p =~ /#{path}\./ }
33
+ else
34
+ puts "Error: Image not found. Use --list to view installed images."
35
+ exit 1
36
+ end
37
+ path
38
+ end
39
+
40
+ def generate(path, top, bottom, campfire)
41
+ if top || bottom
42
+ require "meme_generator"
43
+ output_path = MemeGenerator.generate(path, top, bottom)
44
+
45
+ if campfire
46
+ MemeGenerator::Campfire.upload(output_path)
47
+ else
48
+ puts output_path
49
+ end
50
+ exit 0
51
+ else
52
+ puts "Error: You must provide at least one piece of text"
53
+ usage
54
+ end
55
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memegen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 10
10
- version: 0.0.10
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Keene
@@ -57,6 +57,7 @@ extra_rdoc_files: []
57
57
  files:
58
58
  - bin/memegen
59
59
  - lib/meme_generator/campfire.rb
60
+ - lib/meme_generator/cli.rb
60
61
  - lib/meme_generator.rb
61
62
  - generators/a_dog.jpg
62
63
  - generators/angry_arnold.jpg