memegen 0.0.8 → 0.0.9

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.
data/README.md CHANGED
@@ -49,6 +49,14 @@ You can add images to your local `~/.memegen` folder:
49
49
  $ ls ~/.memegen
50
50
  my_custom_image.png
51
51
 
52
+ ## Upload to Campfire
53
+
54
+ If you have a [Campfire](http://campfirenow.com/) account and token, you can automatically upload your image:
55
+
56
+ $ memegen a_dog "Hello" "Campfire world" --campfire
57
+
58
+ It will prompt you for your subdomain, token, and room name the first time.
59
+
52
60
  ## Bash completion
53
61
 
54
62
  Source or copy `script/autocomplete.sh` inside `~/.bashrc` to get image name autocompletion.
data/bin/memegen CHANGED
@@ -7,12 +7,12 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
7
7
  URL_REGEX = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
8
8
 
9
9
  def images
10
- local_generator_dir = File.expand_path("~/.memegen")
11
- Dir.glob(["generators/*", "#{local_generator_dir}/*"])
10
+ local_image_path = File.expand_path("~/.memegen")
11
+ Dir.glob(["generators/*", "#{local_image_path}/*."])
12
12
  end
13
13
 
14
14
  def usage
15
- puts 'usage: memegen <generator> <top text> <bottom text> [--list]'
15
+ puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c]'
16
16
  exit 1
17
17
  end
18
18
 
@@ -20,7 +20,7 @@ end
20
20
  image, top, bottom = ARGV[0..2]
21
21
 
22
22
  # List
23
- if image == "--list"
23
+ if ARGV.delete("--list")
24
24
  names = images.map { |path|
25
25
  File.basename(path).gsub(/\..*/, '')
26
26
  }.sort
@@ -29,6 +29,13 @@ if image == "--list"
29
29
  exit 0
30
30
  end
31
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
+
32
39
  # URL
33
40
  if image =~ URL_REGEX
34
41
  path = "/tmp/memegen-download-#{Time.now.to_i}"
@@ -43,7 +50,13 @@ end
43
50
  # Require at least one text argument
44
51
  if top || bottom
45
52
  require "meme_generator"
46
- MemeGenerator.generate(path, top, bottom)
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
47
60
  exit 0
48
61
  else
49
62
  puts "Error: You must provide at least one piece of text"
@@ -1,12 +1,12 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
- require "RMagick"
4
3
 
5
4
  class MemeGenerator
6
- VERSION = "0.0.8"
5
+ VERSION = "0.0.9"
7
6
 
8
7
  class << self
9
8
  def generate(path, top, bottom)
9
+ require "RMagick"
10
10
  top = top.upcase
11
11
  bottom = bottom.upcase
12
12
 
@@ -54,8 +54,7 @@ class MemeGenerator
54
54
 
55
55
  output_path = "/tmp/meme-#{Time.now.to_i}.jpeg"
56
56
  canvas.write(output_path)
57
- puts output_path
58
- exit 0
57
+ output_path
59
58
  end
60
59
 
61
60
  private
@@ -0,0 +1,66 @@
1
+ class MemeGenerator
2
+ class Campfire
3
+ CONFIG_PATH = File.join(File.expand_path("~/.memegen"), ".campfire")
4
+
5
+ class << self
6
+ def config
7
+ return unless File.exists?(CONFIG_PATH)
8
+ @config ||= read_config
9
+ end
10
+
11
+ def prompt_config
12
+ puts "Set your Campfire credentials..."
13
+ print "Subdomain : "
14
+ subdomain = gets.strip
15
+ print "Token : "
16
+ token = gets.strip
17
+ print "Room : "
18
+ room = gets.strip
19
+
20
+ write_config([subdomain, token, room])
21
+
22
+ puts "Config saved successfully!"
23
+ end
24
+
25
+ def upload(path)
26
+ require 'tinder'
27
+ require 'open-uri'
28
+
29
+ puts "Uploading... "
30
+ silence_stream(STDERR) do
31
+ campfire = Tinder::Campfire.new config[:subdomain], :token => config[:token]
32
+ room = campfire.rooms.detect { |room| room.name == config[:room] }
33
+ room.upload(path)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def silence_stream(stream)
40
+ old_stream = stream.dup
41
+ stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
42
+ stream.sync = true
43
+ yield
44
+ ensure
45
+ stream.reopen(old_stream)
46
+ end
47
+
48
+ # Lame format is to keep dependencies at a minimum
49
+ def read_config
50
+ data = File.read(CONFIG_PATH)
51
+ values = data.split("|")
52
+ {
53
+ :subdomain => values[0],
54
+ :token => values[1],
55
+ :room => values[2]
56
+ }
57
+ end
58
+
59
+ def write_config(config)
60
+ File.open(CONFIG_PATH, "w") do |file|
61
+ file.write(config.join("|"))
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memegen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 8
10
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
11
10
  platform: ruby
12
11
  authors:
13
12
  - Brandon Keene
@@ -15,22 +14,33 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-05-08 00:00:00 Z
17
+ date: 2011-05-08 00:00:00 -04:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
+ name: rmagick
22
+ prerelease: false
21
23
  requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
24
  requirements:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
- hash: 3
27
27
  segments:
28
28
  - 0
29
29
  version: "0"
30
+ type: :runtime
30
31
  version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: tinder
31
34
  prerelease: false
32
- name: rmagick
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
33
42
  type: :runtime
43
+ version_requirements: *id002
34
44
  description: Locally generate two-caption 'Advice Dog'-style meme images
35
45
  email:
36
46
  - bkeene@gmail.com
@@ -42,9 +52,11 @@ extra_rdoc_files: []
42
52
 
43
53
  files:
44
54
  - bin/memegen
55
+ - lib/meme_generator/campfire.rb
45
56
  - lib/meme_generator.rb
46
57
  - LICENSE
47
58
  - README.md
59
+ has_rdoc: true
48
60
  homepage: http://github.com/cmdrkeene/memegen
49
61
  licenses: []
50
62
 
@@ -54,20 +66,16 @@ rdoc_options: []
54
66
  require_paths:
55
67
  - lib
56
68
  required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
69
  requirements:
59
70
  - - ">="
60
71
  - !ruby/object:Gem::Version
61
- hash: 3
62
72
  segments:
63
73
  - 0
64
74
  version: "0"
65
75
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
76
  requirements:
68
77
  - - ">="
69
78
  - !ruby/object:Gem::Version
70
- hash: 23
71
79
  segments:
72
80
  - 1
73
81
  - 3
@@ -76,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
84
  requirements: []
77
85
 
78
86
  rubyforge_project:
79
- rubygems_version: 1.7.2
87
+ rubygems_version: 1.3.6
80
88
  signing_key:
81
89
  specification_version: 3
82
90
  summary: Two-caption meme generator CLI