ascii_toons 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc78784331e9692b64aa874b068a24c57432c6e6
4
+ data.tar.gz: 075cfd8b98978e8659a188bd2764614f593391cb
5
+ SHA512:
6
+ metadata.gz: fce8f60e9e7729f6960ef7f288ad6f6c23f4d2843bfce332ddec2b256f06005417757bf4a49ff029d758c0cc63d2c9546d9043143ec123863390900fb18bc50a
7
+ data.tar.gz: 88c69528776bf7989e76f85c767f6d609a028b6723f6263d320d308f6f89365b2e697f7699cfb2d93d23c1a56872e544434e5cd4b5265c7c5ee5e92d38569367
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,51 @@
1
+ # ASCIIToons
2
+
3
+ make your projects more awesomer with customizable ascii art
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install ascii_toons
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```rb
14
+ ASCIIToons::Gandalf.say 'You shall not pass!'
15
+ ASCIIToons::Alien.say 'hello world'
16
+ ASCIIToons::CatInTheHat.say 'you done broke things'
17
+
18
+ module KernelPatch
19
+ AGENT = ASCIIToons::CatInTheHat
20
+ def raise(*args)
21
+ case args.size
22
+ when 0
23
+ e = $! || RuntimeError
24
+ AGENT.say e
25
+ super(e, '', caller)
26
+ when 1
27
+ if args[0] < Exception
28
+ e = args[0]
29
+ msg = e.to_s
30
+ else
31
+ e = RuntimeError
32
+ msg = args[0]
33
+ end
34
+ AGENT.say "#{e.name}: #{msg}"
35
+ super(e, msg, caller)
36
+ when 2
37
+ e, msg = *args
38
+ AGENT.say "#{e}: #{msg}"
39
+ super(e, msg, caller)
40
+ when 3
41
+ e, msg, _ = *args
42
+ AGENT.say "#{e}: #{msg}"
43
+ super(*args)
44
+ end
45
+ end
46
+ end
47
+
48
+ Object.prepend KernelPatch
49
+
50
+ raise 'oh snap'
51
+ ```
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ascii_toons/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ascii_toons"
8
+ spec.version = ASCIIToons::VERSION
9
+ spec.authors = ["Josh Bodah"]
10
+ spec.email = ["jb3689@yahoo.com"]
11
+
12
+ spec.summary = %q{make your projects more awesomer with customizable ascii art}
13
+ spec.homepage = "https://github.com/jbodah/ascii_toons"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest", "~> 5.0"
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'ascii_toons/version'
2
+ require 'ascii_toons/art'
3
+
4
+ module ASCIIToons
5
+ def self.register(name, template)
6
+ ASCIIToons.const_set name, ASCIIToons::Art.new(template)
7
+ end
8
+
9
+ DEFAULT_TEMPLATE_PATH = File.expand_path('../../templates', __FILE__)
10
+
11
+ register :Gandalf, File.join(DEFAULT_TEMPLATE_PATH, 'gandalf.txt')
12
+ register :Alien, File.join(DEFAULT_TEMPLATE_PATH, 'alien.txt')
13
+ register :CatInTheHat, File.join(DEFAULT_TEMPLATE_PATH, 'cat.txt')
14
+ end
@@ -0,0 +1,75 @@
1
+ module ASCIIToons
2
+ class Art
3
+ attr_accessor :message_sentinel, :message_callout_symbol, :message_callout_sentinel, :alignment
4
+
5
+ def initialize(template)
6
+ @alignment = :center
7
+ parse File.read(template)
8
+ end
9
+
10
+ def print(message = nil)
11
+ if message
12
+ # Create a clean slate for the body buffer, we will write over it later
13
+ body_buffer = @body.tr(message_sentinel, ' ')
14
+ body_buffer = body_buffer.tr(message_callout_sentinel, message_callout_symbol) if message_callout_sentinel
15
+ body_buffer = body_buffer.each_line.to_a
16
+
17
+ line_idx_stack = @body.each_line.each_with_index.select { |line, idx| line[/#{Regexp.escape(message_sentinel)}/] }
18
+ message_stack = message.split(' ')
19
+
20
+ current_message = message_stack.pop
21
+ until (current_message.nil? && message_stack.empty?) || line_idx_stack.empty?
22
+ current_line, idx = line_idx_stack.pop
23
+ # TODO making an assumption that lines only have one place to replace text and it is contiguous
24
+ current_line_capacity = current_line[/#{Regexp.escape(message_sentinel)}+/].length
25
+ message_buffer = ''
26
+
27
+ # until no more messages or buffer would overflow
28
+ until current_message.nil? || (current_message.length + (message_buffer.length == 0 ? 0 : message_buffer.length + 1)) > current_line_capacity
29
+ # add message to buffer
30
+ if message_buffer.length > 0
31
+ message_buffer = [current_message, message_buffer].join(' ')
32
+ else
33
+ message_buffer = current_message
34
+ end
35
+ current_message = message_stack.pop
36
+ end
37
+
38
+ # pad the buffer to capacity
39
+ case alignment
40
+ when :left
41
+ message_buffer += ' ' * (current_line_capacity - message_buffer.length)
42
+ when :right
43
+ message_buffer.insert 0, ' ' * (current_line_capacity - message_buffer.length)
44
+ else
45
+ half = (current_line_capacity - message_buffer.length) / 2.0
46
+ message_buffer.insert 0, ' ' * half.floor
47
+ message_buffer += ' ' * half.ceil
48
+ end
49
+
50
+ # flush the buffer
51
+ line = current_line.gsub(/#{Regexp.escape(message_sentinel * current_line_capacity)}/, message_buffer)
52
+ body_buffer[idx] = line
53
+ end
54
+
55
+ if message_stack.empty?
56
+ puts body_buffer.join
57
+ else
58
+ raise
59
+ end
60
+ else
61
+ body = @body.tr(message_sentinel, ' ')
62
+ body = body.tr(message_callout_sentinel, ' ') if message_callout_sentinel
63
+ puts body
64
+ end
65
+ end
66
+
67
+ alias :say :print
68
+
69
+ def parse(template)
70
+ headers, body = template.split("---\n")
71
+ binding.eval headers
72
+ @body = body
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module ASCIIToons
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ @message_sentinel = 'x'
2
+ ---
3
+ ______ ______
4
+ /___ \___\ || /___/ ___\
5
+ //\]/\ ___ \\||// ___ /\[/\\
6
+ \\/[\// _) \/ (_ \\/]\//
7
+ \___/ _/ o o \_ \___/
8
+ _/ \_
9
+ //'VvvvvvvvvvvvvvvV'\\
10
+ ( \.'^^^^^^^^^^^^^^'./ )
11
+ \____ . .. . ____/
12
+ ________ \ . .''. . / ________
13
+ /______ \________)________(________/ _______\
14
+ /| \ \ / / |\
15
+ (\|____ / / \ \ ____|/)
16
+ (\_____>- \/ \/ -<_____/)
17
+ (\_____>- | | -<_____/)
18
+ (\_____>- -<_____/)
19
+ \_____>- -<_____/
20
+ | |
21
+ | |
22
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
23
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
24
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
25
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
26
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
27
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
28
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
29
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
30
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
31
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
32
+ | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
33
+ | |
34
+ | |
35
+ | |
36
+ |____________________________________________|
37
+ / ) ( \
38
+ / / \ \
39
+ / / / /\ \ / /\ \ \ \
40
+ ( ( ( ( ( ) ( ) ) ) ) )
41
+ 'v'v'v'v'(_) (_)'v'v'v'v'
42
+ \) (/
@@ -0,0 +1,40 @@
1
+ @message_sentinel = 'x'
2
+ @message_callout_symbol = '//'
3
+ @message_callout_sentinel = 'y'
4
+ @alignment = :left
5
+ ---
6
+ .;''-.
7
+ .' | `._
8
+ /` ; `'.
9
+ .' \ \
10
+ ,'\| `| |
11
+ | -'_ \ `'.__,J
12
+ ;' `. `'.__.' xxxxxxxxxxxxxxxxxxxxxxxxxx
13
+ | `"-.___ ,' xxxxxxxxxxxxxxxxxxxxxxxxxx
14
+ '-, / xxxxxxxxxxxxxxxxxxxxxxxxxx
15
+ |.-`-.______-| xxxxxxxxxxxxxxxxxxxxxxxxxx
16
+ } __.--'L xxxxxxxxxxxxxxxxxxxxxxxxxx
17
+ ; _,- _.-"`\ ___ xxxxxxxxxxxxxxxxxxxxxxxxxx
18
+ `7-;" ' _,,--._ ,-'`__ `. xxxxxxxxxxxxxxxxxxxxxxxxxx
19
+ |/ ,'- .7'.-"--.7 | _.-' xxxxxxxxxxxxxxxxxxxxxxxxxx
20
+ ; ,' .' .' .-. \/ .' xxxxxxxxxxxxxxxxxxxxxxxxxx
21
+ ; / / .'.- ` |__ .'
22
+ \ | .' / | \_)- `'/ _.-'`` y
23
+ _,.--../ .' \_) '`_ \'`
24
+ '`f-'``'.`\;;' ''` '-` |
25
+ \`.__. ;;;, ) /
26
+ `-._,|;;;,, /\ ,'
27
+ / /<_;;;;' `-._ _,-'
28
+ | '- /;;;;;, `t'` \.
29
+ `'-'`_.|,';;;, '._/|
30
+ ,_.-' \ |;;;;; `-._/
31
+ / `;\ |;;;, `"
32
+ .' `'`\;;, /
33
+ ' ;;;'|
34
+ .--. ;.:`\ _.--,
35
+ | `'./;' _ '_.' |
36
+ \_ `"7f `) /
37
+ |` _.-'`t-'`"-.,__.'
38
+ `'-'`/;; | | \
39
+ ;;; ,' | `
40
+ / '
@@ -0,0 +1,30 @@
1
+ @message_sentinel = 'x'
2
+ @message_callout_symbol = '\\'
3
+ @message_callout_sentinel = 'q'
4
+ ---
5
+ xxxxxxxxxxxxxxxxxxxxxx ,---.
6
+ xxxxxxxxxxxxxxxxxxxxxx / |
7
+ xxxxxxxxxxxxxxxxxxxxxx / |
8
+ xxxxxxxxxxxxxxxxxxxxxx / |
9
+ / |
10
+ q ___,' |
11
+ < -' :
12
+ `-.__..--'``-,_\_
13
+ |o/ <o>` :,.)_`>
14
+ :/ ` ||/)
15
+ (_.).__,-` |\
16
+ /( `.`` `| :
17
+ \'`-.) ` ; ;
18
+ | ` /-<
19
+ | ` / `.
20
+ ,-_-..____ /| ` :__..-'\
21
+ /,'-.__\\ ``-./ :` ; \
22
+ `\ `\ `\\ \ : ( ` / , `. \
23
+ \` \ \\ | | ` : : .\ \
24
+ \ `\_ )) : ; | | ): :
25
+ (`-.-'\ || |\ \ ` ; ; | |
26
+ \-_ `;;._ ( ` / /_ | |
27
+ `-.-.// ,'`-._\__/_,' ; |
28
+ \:: : / ` , / |
29
+ || | ( ,' / / |
30
+ || ,' / |
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ascii_toons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Bodah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - jb3689@yahoo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - ascii_toons.gemspec
68
+ - lib/ascii_toons.rb
69
+ - lib/ascii_toons/art.rb
70
+ - lib/ascii_toons/version.rb
71
+ - templates/alien.txt
72
+ - templates/cat.txt
73
+ - templates/gandalf.txt
74
+ homepage: https://github.com/jbodah/ascii_toons
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: make your projects more awesomer with customizable ascii art
97
+ test_files: []