groupmeme 0.1.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.
Files changed (7) hide show
  1. data/History.txt +101 -0
  2. data/Manifest.txt +6 -0
  3. data/README.txt +68 -0
  4. data/Rakefile +17 -0
  5. data/bin/meme +6 -0
  6. data/lib/meme.rb +236 -0
  7. metadata +72 -0
data/History.txt ADDED
@@ -0,0 +1,101 @@
1
+ === 1.9 / 2010-03-28
2
+
3
+ * Minor Enhancements
4
+ * meme_generator will use pasteboard if it is installed. This allows memes
5
+ to easily be used in any OS X app which handles image data.
6
+ * Added Challenge Accepted. Pull Request #27 by Mark Turner.
7
+
8
+ * Bug Fix
9
+ * Only add the default line when it is present. Pull Request #26 by Matt
10
+ Margolis.
11
+
12
+ === 1.8 / 2011-03-22
13
+
14
+ * Minor Enhancements
15
+ * Added Bear Grylls. Pull Request #25 by Lee Jarvis.
16
+ * Added Batman/Joker. Pull Request #22 by Arthur Chiu.
17
+ * Added Neo/Agent Smith. Pull Request #22 by Arthur Chiu.
18
+ * Added The Rock Driving. Pull Request #22 by Arthur Chiu.
19
+ * Added Snob. Pull Request #22 by Arthur Chiu.
20
+
21
+ === 1.7.1 / 2011-03-18
22
+
23
+ * Bug Fix
24
+ * Meme::advice_dog now accepts an optional first line.
25
+
26
+ === 1.7 / 2011-03-18
27
+
28
+ * Minor enhancement
29
+ * Inception now supports more than two lines. Pull Request #20 by Arthur
30
+ Chiu.
31
+
32
+ === 1.6 / 2011-03-17
33
+
34
+ * Minor enhancements
35
+ * <tt>meme --list</tt> is now sorted.
36
+ * +meme+ now accepts multiple lines. Not every generator accepts multiple
37
+ lines so use with care. Pull Request #18 by Arthur Chiu.
38
+ * Added Anteater. Pull Request #14 by Aaron Patterson.
39
+ * Added Cool Story House. Pull Request #16 by Dean Strelau.
40
+ * Added Creeper. Pull Request #15 by Aaron Patterson.
41
+ * Added Futurama Fry. Pull Request #16 by Dean Strelau.
42
+ * Added High Expectations Asian Father. Pull Request #18 by Arthur Chiu.
43
+ * Added Inception. Pull Request #18 by Arthur Chiu.
44
+ * Added Keanu. Pull Request #16 by Dean Strelau.
45
+ * Added Minecraft. Pull Request #15 by Aaron Patterson.
46
+ * Added ORLY Owl. Pull Request #18 by Arthur Chiu.
47
+ * Added Spiderman. Pull Request #18 by Arthur Chiu.
48
+ * Added Uncle Sam Points. Pull Request #13 by Aaron Patteron.
49
+ * Added Unicorn Boy. Pull Request #19 by Aaron Patterson.
50
+ * Added Victory Baby. Pull Request #16 by Dean Strelau.
51
+ * GENERATORS hash additions are now aligned. Pull Request #16 by Dean
52
+ Strelau.
53
+
54
+ === 1.5 / 2011-03-16
55
+
56
+ * Minor enhancement
57
+ * Added Swedish Chef, bork bork bork. Pull Request #12 by Aaron Patterson.
58
+
59
+ === 1.4 / 2011-03-15
60
+
61
+ * Minor enhancement
62
+ * Added Butthurt Dweller. Pull Request #11 by Pete Higgins.
63
+
64
+ === 1.3 / 2011-03-10
65
+
66
+ * Minor enhancements
67
+ * Added Scumbag Steve. Pull Request #9 by Aaron Patterson
68
+ * <tt>meme > foo.jpg</tt> will download the generated image. Pull Request
69
+ #9 by Aaron Patterson
70
+ * Added Most Interesting Man in the World and Courage Wolf. Pull Request
71
+ #10 by postmodern.
72
+
73
+ === 1.2.2 / 2011-02-22
74
+
75
+ * Bug Fix
76
+ * Don't print ERROR when we're exiting normally.
77
+
78
+ === 1.2.1 / 2011-02-22
79
+
80
+ * Bug Fix
81
+ * A proper error is now printed (instead of crashing) when `meme` is run
82
+ without both lines. Bug #7 by Trevor Hartman.
83
+
84
+ === 1.2 / 2011-02-11
85
+
86
+ * Minor enhancements
87
+ * Added Hipster mermaid. Pull Request #6 by Josep M. Bach.
88
+ * Support xclip on linux. Pull Request #5 by Matthew M. Boedicker.
89
+
90
+ === 1.1 / 2011-02-09
91
+
92
+ * Minor enhancements
93
+ * Added 13 new templates. Pull Request #4 by Josep M. Bach.
94
+ * Meme::run now returns the link. Pull Request #2 by Josep M. Bach.
95
+ * Better template lookup. Patch by James Tucker.
96
+
97
+ === 1.0 / 2011-02-08
98
+
99
+ * Major enhancements
100
+ * Birthday!
101
+
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/meme
6
+ lib/meme.rb
data/README.txt ADDED
@@ -0,0 +1,68 @@
1
+ = meme_generator
2
+
3
+ * http://github.com/drbrain/meme
4
+ * http://docs.seattlerb.org/meme_generator
5
+
6
+ == DESCRIPTION:
7
+
8
+ Generate meme images using http://memegenerator.net! Save yourself some time!
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Features many popular meme pictures
13
+ * No tests
14
+
15
+ == SYNOPSIS:
16
+
17
+ Generate a Y U NO meme:
18
+
19
+ $ meme Y_U_NO 'write tests?'
20
+
21
+ See a list of available generators
22
+
23
+ $ meme --list
24
+
25
+ You can also drive it like an API.
26
+
27
+ == REQUIREMENTS:
28
+
29
+ * nokogiri
30
+ * internet connection
31
+
32
+ == INSTALL:
33
+
34
+ gem install meme_generator
35
+
36
+ == DEVELOPERS:
37
+
38
+ After checking out the source, run:
39
+
40
+ $ rake newb
41
+
42
+ This task will install any missing dependencies, run the tests/specs,
43
+ and generate the RDoc.
44
+
45
+ == LICENSE:
46
+
47
+ (The MIT License)
48
+
49
+ Copyright (c) 2011 Eric Hodel
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining
52
+ a copy of this software and associated documentation files (the
53
+ 'Software'), to deal in the Software without restriction, including
54
+ without limitation the rights to use, copy, modify, merge, publish,
55
+ distribute, sublicense, and/or sell copies of the Software, and to
56
+ permit persons to whom the Software is furnished to do so, subject to
57
+ the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be
60
+ included in all copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
63
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
66
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
67
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
68
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :git
7
+
8
+ Hoe.spec 'meme_generator' do
9
+ developer 'Eric Hodel', 'drbrain@segment7.net'
10
+
11
+ rdoc_locations <<
12
+ 'docs.seattlerb.org:/data/www/docs.seattlerb.org/meme_generator/'
13
+
14
+ extra_deps << ['nokogiri', '~> 1.4']
15
+ end
16
+
17
+ # vim: syntax=ruby
data/bin/meme ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/local/bin/ruby19
2
+
3
+ require 'meme'
4
+
5
+ Meme.run ARGV
6
+
data/lib/meme.rb ADDED
@@ -0,0 +1,236 @@
1
+ require 'net/http'
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+
6
+ ##
7
+ # Generate memes using http://memegenerator.net
8
+
9
+ class Meme
10
+
11
+ ##
12
+ # Sometimes your meme will have an error, fix it!
13
+
14
+ class Error < RuntimeError; end
15
+
16
+ ##
17
+ # Every meme generator needs a version
18
+
19
+ VERSION = '1.9.1'
20
+
21
+ ##
22
+ # For statistics!
23
+
24
+ USER_AGENT = "meme/#{VERSION} Ruby/#{RUBY_VERSION}"
25
+
26
+ ##
27
+ # We have some generators up-in-here
28
+
29
+ GENERATORS = Hash.new do |_, k|
30
+ raise Error, "unknown generator #{k}"
31
+ end
32
+
33
+ ##
34
+ # For creating advice-dog type meme images.
35
+ #
36
+ # These can accept up to two lines of text
37
+
38
+ def self.advice_dog name, id, template_name, first_line = nil
39
+ template = [id, 'AdviceDogSpinoff', template_name, first_line]
40
+ template.compact
41
+
42
+ GENERATORS[name] = template
43
+ end
44
+
45
+ ##
46
+ # For creating vertical type meme images
47
+ #
48
+ # These can accept multiple lines of text
49
+
50
+ def self.vertical name, id, template_name
51
+ GENERATORS[name] = [id, 'Vertical', template_name]
52
+ end
53
+
54
+ # keep generators in alphabetical order
55
+ advice_dog 'ANTEATER', 41191, 'anteater'
56
+ advice_dog 'A_DODSON', 106375, 'Antoine-Dodson'
57
+ advice_dog 'A_DOG', 940, 'Advice-Dog'
58
+ advice_dog 'A_FATHER', 1436, 'High-Expectations-Asian-Father'
59
+ advice_dog 'BEAR-GRYLLS', 89714, 'Bear-Grylls'
60
+ advice_dog 'BUTTHURT_DWELLER', 1438, 'Butthurt-Dweller'
61
+ advice_dog 'B_FROG', 1211, 'Foul-Bachelorette-Frog'
62
+ advice_dog 'B_FROG2', 1045, 'Foul-Bachelor-Frog'
63
+ advice_dog 'CHALLENGE_ACCEPTED', 275025, 'Challenge-Accepted'
64
+ advice_dog 'COOL_STORY_HOUSE', 16948, 'cool-story-bro-house'
65
+ advice_dog 'CREEPER', 173501, 'Minecraft-Creeper'
66
+ advice_dog 'C_WOLF', 931, 'Courage-Wolf'
67
+ advice_dog 'F_FRY', 84688, 'Futurama-Fry'
68
+ advice_dog 'G_GRANDPA', 185650, 'Grumpy-Grandpa'
69
+ advice_dog 'H_MERMAID', 405224, 'Hipster-Mermaid'
70
+ advice_dog 'I_DONT_ALWAYS', 38926, 'The-Most-Interesting-Man-in-the-World'
71
+ advice_dog 'I_WOLF', 926, 'Insanity-Wolf'
72
+ advice_dog 'J_DUCREUX', 1356, 'Joseph-Ducreux'
73
+ advice_dog 'KEANU', 47718, 'Keanu-reeves'
74
+ advice_dog 'MINECRAFT', 122309, 'Minecraft'
75
+ advice_dog 'O-RLY-OWL', 117041, 'O-RLY-OWL', 'ORLY???'
76
+ advice_dog 'OBAMA', 1332, 'Obama-'
77
+ advice_dog 'PHILOSORAPTOR', 984, 'Philosoraptor'
78
+ advice_dog 'P_OAK', 24321, 'Professor-Oak'
79
+ advice_dog 'R_BLACK', 574812, 'Rebecca-Black-Meme'
80
+ advice_dog 'SCUMBAG', 364688, 'Scumbag-Steve'
81
+ advice_dog 'SERIOUS_FISH', 6374627,'Spongebob-Serious-Fish'
82
+ advice_dog 'SNOB', 2994, 'Snob'
83
+ advice_dog 'SPARTA', 1013, 'sparta'
84
+ advice_dog 'SPIDERMAN', 1037, 'Question-Spiderman'
85
+ advice_dog 'SWEDISH_CHEF', 186651, 'Swedish-Chef'
86
+ advice_dog 'S_AWKWARD_PENGUIN', 983, 'Socially-Awkward-Penguin'
87
+ advice_dog 'TOWNCRIER', 434537, 'Towncrier'
88
+ advice_dog 'TROLLFACE', 1030, 'Troll-Face'
89
+ advice_dog 'UNICORN_BOY', 57022, 'unicorn-boy'
90
+ advice_dog 'US_POINT', 131083, 'Uncle-Sam-Point', 'I WANT YOU'
91
+ advice_dog 'V_BABY', 11140, 'Victory-Baby'
92
+ advice_dog 'XZIBIT', 3114, 'XZIBIT'
93
+ advice_dog 'Y_U_NO', 165241, 'Y-U-NO', 'Y U NO'
94
+
95
+ vertical 'BATMAN', 148359, 'batman-panal-ryan'
96
+ vertical 'INCEPTION', 107949, 'Inception'
97
+ vertical 'NEO', 173419, 'Neo'
98
+ vertical 'THE_ROCK', 417195, 'The-Rock-driving'
99
+
100
+ # keep generators in alphabetical order
101
+
102
+ ##
103
+ # Looks up generator name
104
+
105
+ def GENERATORS.match(name)
106
+ # TODO meme Y U NO DEMETAPHONE?
107
+ return self[name] if has_key? name
108
+ matcher = Regexp.new(name, Regexp::IGNORECASE)
109
+ _, generator = find { |k,v| matcher =~ k || v.grep(matcher).any? }
110
+ generator || self[name] # raises the error if generator is nil
111
+ end
112
+
113
+ ##
114
+ # Interface for the executable
115
+
116
+ def self.run argv = ARGV
117
+ generator = ARGV.shift
118
+
119
+ if generator == '--list' then
120
+ width = GENERATORS.keys.map { |command| command.length }.max
121
+
122
+ GENERATORS.sort.each do |command, (id, name, _)|
123
+ puts "%-*s %s" % [width, command, name]
124
+ end
125
+
126
+ exit
127
+ end
128
+
129
+ abort "#{$0} [GENERATOR|--list] LINE [ADDITONAL_LINES]" if ARGV.empty?
130
+
131
+ meme = new generator
132
+ link = meme.generate *ARGV
133
+
134
+ meme.paste link
135
+
136
+ if $stdout.tty?
137
+ puts link
138
+ else
139
+ puts meme.fetch link
140
+ end
141
+ link
142
+ rescue Interrupt
143
+ exit
144
+ rescue SystemExit
145
+ raise
146
+ rescue Exception => e
147
+ abort "ERROR: #{e.message} (#{e.class})"
148
+ end
149
+
150
+ ##
151
+ # Generates links for +generator+
152
+
153
+ def initialize generator
154
+ @template_id, @template_type, @generator_name, @default_line = GENERATORS.match generator
155
+ end
156
+
157
+ ##
158
+ # Generates a meme with +line1+ and +line2+. For some generators you only
159
+ # have to supply one line because the first line is defaulted for you.
160
+ # Isn't that great?
161
+
162
+ def generate *args
163
+ url = URI.parse 'http://memegenerator.net/Instance/CreateOrEdit'
164
+ res = nil
165
+ location = nil
166
+
167
+ # Prepend the default line if this meme has one and we only had 1 text input
168
+ args.unshift @default_line if @default_line and args.size <= 1
169
+
170
+ raise Error, "two lines are required for #{@generator_name}" unless
171
+ args.size > 1
172
+
173
+ post_data = { 'templateType' => @template_type,
174
+ 'templateID' => @template_id,
175
+ 'generatorName' => @generator_name }
176
+
177
+ # go through each argument and add it back into the post data as textN
178
+ (0..args.size).map {|num| post_data.merge! "text#{num}" => args[num] }
179
+
180
+ Net::HTTP.start url.host do |http|
181
+ post = Net::HTTP::Post.new url.path
182
+ post['User-Agent'] = USER_AGENT
183
+ post.set_form_data post_data
184
+
185
+ res = http.request post
186
+
187
+ location = res['Location']
188
+ redirect = url + location
189
+
190
+ get = Net::HTTP::Get.new redirect.request_uri
191
+ get['User-Agent'] = USER_AGENT
192
+
193
+ res = http.request get
194
+ end
195
+
196
+ doc = Nokogiri.HTML res.body
197
+ doc.css("a[href=\"#{location}\"] img").first['src']
198
+ end
199
+
200
+ def fetch link
201
+ url = URI.parse link
202
+ res = nil
203
+
204
+ Net::HTTP.start url.host do |http|
205
+ get = Net::HTTP::Get.new url.request_uri
206
+ get['User-Agent'] = USER_AGENT
207
+
208
+ res = http.request get
209
+ end
210
+ res.body
211
+ end
212
+
213
+ ##
214
+ # Tries to find clipboard copy executable and if found puts +link+ in your
215
+ # clipboard.
216
+
217
+ def paste link
218
+ require 'pasteboard'
219
+
220
+ clipboard = Pasteboard.new
221
+
222
+ jpeg = fetch link
223
+
224
+ clipboard.put_jpeg_url jpeg, link
225
+ rescue LoadError
226
+ clipboard = %w{
227
+ /usr/bin/pbcopy
228
+ /usr/bin/xclip
229
+ }.find { |path| File.exist? path }
230
+
231
+ if clipboard
232
+ IO.popen clipboard, 'w' do |io| io.write link end
233
+ end
234
+ end
235
+
236
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: groupmeme
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - THE INTERNET
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-06 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: dev@groupme.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
34
+ - Rakefile
35
+ - bin/meme
36
+ - lib/meme.rb
37
+ has_rdoc: true
38
+ homepage:
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.4.1
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: GroupMe fork of meme_generator
71
+ test_files: []
72
+