le_meme 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bcc7f74f26c2187c45681071a58826936f99eb0
4
- data.tar.gz: dccfc1dfe06b788abe1aee13ed938b44aff09677
3
+ metadata.gz: d259d15403afedfcf9afff3d29004ea4d778f180
4
+ data.tar.gz: 509820a6f6e562852d82e0494ad3e4e2f81be81e
5
5
  SHA512:
6
- metadata.gz: 17335ec81d74e308ce8ae8f7cbd016361194509576c039bf04f309f3074a0d9b5ef01e6ec0e06e20949ae08e320785df0658c4c872e6d3282e5a55a1b44c0744
7
- data.tar.gz: dbcc9831a22cbab608f00282453ff10f0a83222a97a4bd26c7a5496a7297ab3fe1394586c3e86e4debd7cef8f3506fbe750355415d7cc8f1b57f59ae782b5243
6
+ metadata.gz: a432b9ba98e2390e5409a1dd327a4d6ee3b9d059c3b76b2b0185e71e4833e16841a394e175efc9b8509d668abd9a1473d0ed2176b7b84be3b562e0b2a3c202a6
7
+ data.tar.gz: 82c70074224e66c354f074d1786747c1d820756371c7dd403337136a994ddaede68f2a83094f64d2821614eb185a7bf4bff806099530e01684968e66449e017c
data/bin/meme CHANGED
@@ -4,8 +4,7 @@ require 'le_meme'
4
4
  require 'slop'
5
5
 
6
6
  memegen = LeMeme.new
7
-
8
- opts = Slop.parse!(strict: true, help: true) do
7
+ opts = Slop.new(strict: true, help: true) do
9
8
  banner <<-HEREDOC
10
9
  Usage: meme [options] [top-text] [bottom-text]
11
10
 
@@ -20,6 +19,7 @@ HEREDOC
20
19
  on 'p', 'path=', 'path to an image to use for the meme'
21
20
  on 'w', 'watermark=', 'text to watermark the image'
22
21
  on 'o', 'outpath=', 'path to save the final meme to'
22
+ on 'O', 'open', "Open the file in your system's default image viewer"
23
23
 
24
24
  on 'templates', 'list all the meme templates' do
25
25
  puts memegen.memes.keys.join("\n")
@@ -30,15 +30,36 @@ HEREDOC
30
30
  exit
31
31
  end
32
32
  end
33
+ if ARGV.empty?
34
+ $stdout.puts opts if $stdout.tty?
35
+ exit(0)
36
+ end
33
37
 
38
+ opts.parse!
34
39
 
35
40
  top = opts[:top] || ARGV[0]
36
41
  bottom = opts[:bottom] || ARGV[1]
37
42
 
43
+
38
44
  if opts[:path]
39
- $stdout.puts memegen.meme(path: opts[:path], top: top, bottom: bottom, watermark: opts[:watermark], outpath: opts[:outpath])
45
+ output = memegen.meme(path: opts[:path], top: top, bottom: bottom, watermark: opts[:watermark], outpath: opts[:outpath])
46
+ else
47
+ name = opts[:meme].strip if opts[:meme]
48
+ output = memegen.fast_meme(name: name, top: top, bottom: bottom, watermark: opts[:watermark], outpath: opts[:outpath])
49
+ end
50
+
51
+ if opts[:open]
52
+ case RbConfig::CONFIG['host_os']
53
+ when /mswin|mingw|cygwin/
54
+ `start #{output}`
55
+ when /darwin/
56
+ `open -F #{output}`
57
+ when /linux|bsd/
58
+ `xdg-open #{output}`
59
+ else
60
+ $stderr.puts "Sorry, don't know how to open on your system! (#{RbConfig::Config['host_os']})"
61
+ end
40
62
  else
41
- name = opts[:meme] || ''
42
- $stdout.puts memegen.fast_meme(name: name.strip, top: top, bottom: bottom, watermark: opts[:watermark], outpath: opts[:outpath])
63
+ $stdout.puts output
43
64
  end
44
65
  exit
@@ -29,9 +29,10 @@ class LeMeme
29
29
  # @param top [String] The text you want to appear on the top of the meme.
30
30
  # @param bottom [String] The text you want to appear on the bottom of the meme.
31
31
  # @param watermark [String] The watermark text. If nil it is omitted
32
- # @param outpath [String] Where do you want to put the generated meme. Defaults to /tmp/
33
- # @return [String] Path to the generated meme
34
- def generate(path:, top: nil, bottom: nil, watermark: nil, outpath: nil)
32
+ # @param outpath [String] Where do you want to put the generated meme. Defaults to /tmp/meme-<timestamp>.<extension>
33
+ # @param nowrite [Boolean] Returns the meme as a blob (string) instead of writing to disk.
34
+ # @return [String] Either the generated meme object (if nowrite) or a path to the meme
35
+ def generate(path:, top: nil, bottom: nil, watermark: nil, outpath: nil, nowrite: false)
35
36
  top = (top || '').upcase
36
37
  bottom = (bottom || '').upcase
37
38
 
@@ -57,8 +58,12 @@ class LeMeme
57
58
  end
58
59
 
59
60
  output_path = outpath || "/tmp/meme-#{Time.now.to_i}#{path.extname}"
60
- canvas.write(output_path)
61
- output_path
61
+ if nowrite
62
+ canvas.to_blob
63
+ else
64
+ canvas.write(output_path)
65
+ output_path
66
+ end
62
67
  end
63
68
  alias_method :meme, :generate
64
69
 
@@ -69,9 +74,10 @@ class LeMeme
69
74
  # @param top [String] The text you want to appear on the top of the meme.
70
75
  # @param bottom [String] The text you want to appear on the bottom of the meme.
71
76
  # @param watermark [String] The watermark text. If nil it is omitted
72
- # @param outpath [String] Where do you want to put the generated meme. Defaults to /tmp/
73
- # @return [String] Path to the generated meme
74
- def fast_meme(name: nil, top: nil, bottom: nil, watermark: nil, outpath: nil)
77
+ # @param outpath [String] Where do you want to put the generated meme. Defaults to /tmp/meme-<timestamp>.<extension>
78
+ # @param nowrite [Boolean] Returns the meme as a blob (string) instead of writing to disk.
79
+ # @return [String] Either the generated meme object (if nowrite) or a path to the meme
80
+ def fast_meme(name: nil, top: nil, bottom: nil, watermark: nil, outpath: nil, nowrite: false)
75
81
  if name.nil?
76
82
  path = @memes[@memes.keys.sample]
77
83
  elsif @memes[name].nil?
@@ -79,7 +85,7 @@ class LeMeme
79
85
  else
80
86
  path = @memes[name]
81
87
  end
82
- generate(path: path, top: top, bottom: bottom, watermark: watermark, outpath: outpath)
88
+ generate(path: path, top: top, bottom: bottom, watermark: watermark, outpath: outpath, nowrite: nowrite)
83
89
  end
84
90
  alias_method :m, :fast_meme
85
91
 
@@ -1,3 +1,3 @@
1
1
  class LeMeme
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -14,6 +14,7 @@ describe LeMeme do
14
14
  x = ['text', nil] * 3
15
15
  x.permutation(3).to_a.uniq.each do |top, bottom, watermark|
16
16
  it "should generate a meme with top: '#{top}', bottom: '#{bottom}', and watermark: '#{watermark}'" do
17
+ expect_any_instance_of(Magick::ImageList).to receive(:write).and_return("/tmp/meme-#{Time.now.to_i}.jpg")
17
18
  expect(meme.generate(path: image, top: top, bottom: bottom, watermark: watermark)).to match(%r{/tmp/meme-\d+.jpg})
18
19
  end
19
20
  end
@@ -24,6 +25,12 @@ describe LeMeme do
24
25
  expect(meme.generate(path: image, top: 'top', bottom: 'bottom', outpath: 'test.jpg')).to eq('test.jpg')
25
26
  end
26
27
  end
28
+ context 'with nowrite set to true' do
29
+ it 'should output the meme as a blob string' do
30
+ mymeme = meme.generate(path: image, nowrite: true)
31
+ expect(mymeme.size).to eq(43618)
32
+ end
33
+ end
27
34
  end
28
35
 
29
36
  describe '#meme' do
@@ -47,6 +54,7 @@ describe LeMeme do
47
54
 
48
55
  context 'without a specified template' do
49
56
  it 'should generate a meme' do
57
+ expect_any_instance_of(Magick::ImageList).to receive(:write).and_return("/tmp/meme-#{Time.now.to_i}.jpg")
50
58
  expect(meme.fast_meme).to match(%r{/tmp/meme-\d+.jpg})
51
59
  end
52
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: le_meme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -208,7 +208,6 @@ files:
208
208
  - memes/wonka.jpg
209
209
  - memes/yee.jpg
210
210
  - memes/yuno.jpg
211
- - open
212
211
  - spec/le_meme_spec.rb
213
212
  - spec/spec_helper.rb
214
213
  homepage: http://github.com/paradox460/le_meme
data/open DELETED
@@ -1 +0,0 @@
1
- /tmp/meme-1421208560.jpg