meem 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Meem
2
2
 
3
- Meem is a command-line tool to create memes.
3
+ Meem is a command-line tool to create memes. It's pretty awesome.
4
4
 
5
5
  ### Usage
6
6
 
@@ -0,0 +1,40 @@
1
+ require "pathname"
2
+ require "open-uri"
3
+
4
+ module Meem::Templates
5
+ PATHS = [
6
+ Pathname.new("#{ENV['HOME']}/.meem/"),
7
+ Pathname.new("#{DIRECTORY}/../templates/")
8
+ ]
9
+
10
+ # List templates.
11
+ #
12
+ # Returns an Array of Pathname instances.
13
+ def self.list
14
+ PATHS.map do |path|
15
+ path.children.select { |child| child.extname == ".jpg" }
16
+ end.flatten
17
+ end
18
+
19
+ # Find a given template.
20
+ #
21
+ # template - A String describing a template.
22
+ #
23
+ # Return a Pathname instance.
24
+ def self.find template
25
+ list.find { |file| file.basename.to_s =~ /#{template}/ }
26
+ end
27
+
28
+ # Load a template from file or the internet.
29
+ #
30
+ # template - A String describing a template.
31
+ #
32
+ # Returns a File.
33
+ def self.load template
34
+ if template[/^http:\/\//]
35
+ return open template
36
+ else
37
+ find template
38
+ end
39
+ end
40
+ end
data/lib/meem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Meem
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/meem.rb CHANGED
@@ -1,31 +1,30 @@
1
+ DIRECTORY = File.expand_path File.dirname __FILE__
2
+
1
3
  require "meem/version"
4
+ require "meem/templates"
2
5
  require "optparse"
3
6
  require "ostruct"
4
7
  require "meme_captain"
5
- require "open-uri"
6
- require "pathname"
7
-
8
- DIRECTORY = File.expand_path File.dirname __FILE__
9
8
 
10
9
  module Meem
11
- PATHS = [
12
- "#{ENV['HOME']}/.meem/",
13
- "#{DIRECTORY}/../templates/"
14
- ]
15
-
16
10
  def self.run arguments
17
11
  options = parse arguments
18
12
 
19
- image = MemeCaptain.meme_top_bottom fetch(options.meme), options.top, options.bottom,
20
- font: "#{DIRECTORY}/../fonts/impact.ttf"
13
+ template = Templates.load options.meme
14
+
15
+ if template
16
+ image = generate template, options.top, options.bottom
21
17
 
22
- if STDOUT.tty?
23
- path = "/tmp/meme.jpg"
18
+ if STDOUT.tty?
19
+ path = "/tmp/meme.jpg"
24
20
 
25
- image.write path
26
- puts path
21
+ image.write path
22
+ puts path
23
+ else
24
+ puts image.to_blob
25
+ end
27
26
  else
28
- puts image.to_blob
27
+ error "meme not found"
29
28
  end
30
29
  end
31
30
 
@@ -41,11 +40,14 @@ module Meem
41
40
 
42
41
  OptionParser.new do |opts|
43
42
  opts.program_name = "meem"
44
- opts.banner = "usage: meem <meme> <top text> <bottom text>"
43
+ opts.banner = "usage: meem <meme> [options]"
45
44
  opts.version = Meem::VERSION
46
45
 
47
46
  opts.on "-l", "--list", "List memes" do
48
- list
47
+ Templates.list.each do |file|
48
+ puts file.basename.to_s[/(.*)\.jpg/, 1]
49
+ end
50
+
49
51
  exit
50
52
  end
51
53
 
@@ -71,19 +73,17 @@ module Meem
71
73
  options
72
74
  end
73
75
 
74
- # List memes.
75
- def self.list
76
- PATHS.each do |path|
77
- Dir.glob "#{path}/*.jpg" do |file|
78
- file = Pathname.new file
76
+ private
79
77
 
80
- puts "* " + file.basename.to_s[/(.*)\.jpg/, 1]
81
- end
82
- end
78
+ # Generate a meme.
79
+ #
80
+ # template - A File describing a template.
81
+ # top - A String describing the top caption.
82
+ # bottom - A String describing the bottom caption.
83
+ def self.generate template, top, bottom
84
+ MemeCaptain.meme_top_bottom template, top, bottom, font: "#{DIRECTORY}/../fonts/impact.ttf"
83
85
  end
84
86
 
85
- private
86
-
87
87
  # Print a message and exit.
88
88
  #
89
89
  # message - A String describing the message.
@@ -92,25 +92,4 @@ module Meem
92
92
  puts "meem: #{message}"
93
93
  exit code
94
94
  end
95
-
96
- # Load a meme.
97
- #
98
- # meme - A String describing a meme.
99
- #
100
- # Returns a File.
101
- def self.fetch meme
102
- if meme[/^http:\/\//]
103
- return open meme
104
- else
105
- PATHS.each do |path|
106
- image = path + "#{meme}.jpg"
107
-
108
- if File.exists? image
109
- return open image
110
- end
111
- end
112
-
113
- error "meme not found"
114
- end
115
- end
116
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -91,6 +91,7 @@ files:
91
91
  - bin/meem
92
92
  - fonts/impact.ttf
93
93
  - lib/meem.rb
94
+ - lib/meem/templates.rb
94
95
  - lib/meem/version.rb
95
96
  - meem.gemspec
96
97
  - spec/meem_spec.rb
@@ -123,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  segments:
125
126
  - 0
126
- hash: 2090817232039969754
127
+ hash: -3622821011475249863
127
128
  required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  none: false
129
130
  requirements:
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  version: '0'
133
134
  segments:
134
135
  - 0
135
- hash: 2090817232039969754
136
+ hash: -3622821011475249863
136
137
  requirements: []
137
138
  rubyforge_project:
138
139
  rubygems_version: 1.8.23