m2a 0.0.1
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/Gemfile +2 -0
- data/Gemfile.lock +14 -0
- data/README +1 -0
- data/bin/m2a +4 -0
- data/data/success_kid.jpg +0 -0
- data/lib/m2a.rb +20 -0
- data/lib/m2a/cli.rb +24 -0
- data/lib/m2a/cli/argparse.rb +54 -0
- data/lib/m2a/core/exceptions.rb +3 -0
- data/lib/m2a/core/lookup_meme.rb +28 -0
- data/lib/m2a/core/m2a.rb +38 -0
- data/m2a.gemspec +13 -0
- metadata +59 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Provides minimal ascii memination
|
data/bin/m2a
ADDED
Binary file
|
data/lib/m2a.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module M2A
|
2
|
+
extend self
|
3
|
+
def new(*args)
|
4
|
+
Renderer.new(*args)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
%w[m2a exceptions lookup_meme].each do |filename|
|
9
|
+
require "m2a/core/#{filename}"
|
10
|
+
end
|
11
|
+
|
12
|
+
%w[cli].each do |filename|
|
13
|
+
require "m2a/#{filename}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Check to make sure jp2a is installed
|
17
|
+
# FIXME win32
|
18
|
+
unless `which jp2a >/dev/null`
|
19
|
+
STDERR.puts "jp2a not found in path, this will not go well"
|
20
|
+
end
|
data/lib/m2a/cli.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module M2A::CLI
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def run!
|
5
|
+
opts = Argparse::Argparser.new.opts
|
6
|
+
m2a = M2A.new.tap do |m2a|
|
7
|
+
m2a.configure do |conf|
|
8
|
+
conf.width = opts.width if opts.width
|
9
|
+
conf.height = opts.height if opts.height
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
meme = M2A.lookup_meme(opts.meme)
|
14
|
+
|
15
|
+
puts m2a.render(meme)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
%w[argparse].each do |filename|
|
23
|
+
require "m2a/cli/#{filename}"
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
module M2A::CLI
|
4
|
+
module Argparse
|
5
|
+
|
6
|
+
class Argparser
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@optparser = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: ascii_meme <meme_name>"
|
11
|
+
|
12
|
+
opts.on('-w', '--width WIDTH', Float, "Output WIDTH characters wide") do |width| #{{{
|
13
|
+
options[:width] = width.to_i
|
14
|
+
end #}}}
|
15
|
+
opts.on('-h', '--height HEIGHT', Float, "Output HEIGHT characters high") do |height|#{{{
|
16
|
+
options[:height] = height.to_i
|
17
|
+
end #}}}
|
18
|
+
|
19
|
+
opts.on('--help', "Print this help screen") do
|
20
|
+
puts opts
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# idempotent
|
27
|
+
def opts
|
28
|
+
@opts ||= parsed_options!
|
29
|
+
end
|
30
|
+
|
31
|
+
def parsed_options!
|
32
|
+
@optparser.parse!
|
33
|
+
if ARGV.empty? == 0
|
34
|
+
print_help_and_exit
|
35
|
+
else
|
36
|
+
options[:meme] = ARGV.join(" ")
|
37
|
+
end
|
38
|
+
|
39
|
+
OpenStruct.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_help_and_exit
|
43
|
+
puts @optparser.help
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
|
47
|
+
def options
|
48
|
+
@options ||= Hash.new
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module M2A
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def lookup_meme(meme)
|
5
|
+
Meme.new(_lookup_meme(meme))
|
6
|
+
end
|
7
|
+
|
8
|
+
def _lookup_meme(meme)
|
9
|
+
case meme
|
10
|
+
when "success kid"
|
11
|
+
return "data/success_kid.jpg"
|
12
|
+
else
|
13
|
+
if File.exist?(meme)
|
14
|
+
return meme
|
15
|
+
else
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Meme
|
22
|
+
attr_accessor :path
|
23
|
+
def initialize(meme_path)
|
24
|
+
@path = meme_path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/m2a/core/m2a.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module M2A
|
2
|
+
class Renderer
|
3
|
+
attr_accessor :width, :height
|
4
|
+
|
5
|
+
def configure(&block)
|
6
|
+
if block_given?
|
7
|
+
yield self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(meme)
|
12
|
+
validate_args!
|
13
|
+
|
14
|
+
if height && width
|
15
|
+
size = "--size=#{width}x#{height}"
|
16
|
+
elsif height
|
17
|
+
size = "--height=#{height}"
|
18
|
+
elsif width
|
19
|
+
size = "--width=#{width}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# XXX Bail is size is unset?
|
23
|
+
|
24
|
+
puts "jp2a #{size} #{meme.path}"
|
25
|
+
|
26
|
+
return `jp2a #{size} #{meme.path}`
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def validate_args!
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
data/m2a.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "m2a"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.authors = ["Rich Healey"]
|
5
|
+
s.email = ["richo@psych0tik.net"]
|
6
|
+
s.homepage = "http://github.com/richoH/m2a"
|
7
|
+
s.summary = "Tool and API for creating ascii versions of memes"
|
8
|
+
s.description = s.summary
|
9
|
+
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m2a
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rich Healey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Tool and API for creating ascii versions of memes
|
15
|
+
email:
|
16
|
+
- richo@psych0tik.net
|
17
|
+
executables:
|
18
|
+
- m2a
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README
|
25
|
+
- bin/m2a
|
26
|
+
- data/success_kid.jpg
|
27
|
+
- lib/m2a.rb
|
28
|
+
- lib/m2a/cli.rb
|
29
|
+
- lib/m2a/cli/argparse.rb
|
30
|
+
- lib/m2a/core/exceptions.rb
|
31
|
+
- lib/m2a/core/lookup_meme.rb
|
32
|
+
- lib/m2a/core/m2a.rb
|
33
|
+
- m2a.gemspec
|
34
|
+
homepage: http://github.com/richoH/m2a
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.23
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Tool and API for creating ascii versions of memes
|
58
|
+
test_files: []
|
59
|
+
has_rdoc:
|