gasciiart 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/bin/gasciiart +34 -0
- data/lib/gasciiart.rb +20 -0
- data/lib/gasciiart/builder.rb +104 -0
- data/lib/gasciiart/version.rb +3 -0
- data/spec/builder_spec.rb +29 -0
- data/spec/gasciiart_spec.rb +7 -0
- data/spec/spec_helper.rb +27 -0
- metadata +109 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Drew Blas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Gasciiart
|
2
|
+
|
3
|
+
Gasciiart creates an animated git repository. Each frame of ASCII animation is a separate commit.
|
4
|
+
|
5
|
+
Using the run.sh script, the repository will "play" itself by checking out each commit in turn and displaying it.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'gasciiart'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gasciiart
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You should have an input directory where each frame to be animated is a separate file. e.g.:
|
24
|
+
|
25
|
+
- input/
|
26
|
+
- 00001.txt
|
27
|
+
- 00002.txt
|
28
|
+
- 00003.txt
|
29
|
+
- 00004.txt
|
30
|
+
|
31
|
+
(The filenames are sorted by Ruby, so use any naming scheme as long as the sort results in the order you want)
|
32
|
+
|
33
|
+
Run the command:
|
34
|
+
|
35
|
+
gasciiart --source input/ --target output/
|
36
|
+
|
37
|
+
(The output directory must **not** exist beforehand)
|
38
|
+
|
39
|
+
The output directory will have the run.sh script to start the animation.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
48
|
+
|
49
|
+
## Copyright
|
50
|
+
|
51
|
+
Copyright (c) 2012 Drew Blas. See LICENSE.txt for further details.
|
52
|
+
|
data/bin/gasciiart
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'gasciiart'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
source = './'
|
9
|
+
target = "output"
|
10
|
+
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: gasciiart [options]"
|
13
|
+
|
14
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
15
|
+
options[:verbose] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-t", "--target DIRECTORY", "Targets an EMPTY directory as the output for the resulting repo. Defaults to 'output'") do |file|
|
19
|
+
target = file
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on("-s", "--source DIRECTORY", "Source directory of inputs") do |file|
|
23
|
+
source = file
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-h', '--help', 'Dispaly this screen') do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end.parse!
|
31
|
+
|
32
|
+
b = Gasciiart::Builder.new(source, target, options)
|
33
|
+
b.build!
|
34
|
+
|
data/lib/gasciiart.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'gasciiart/version'
|
2
|
+
require 'gasciiart/builder'
|
3
|
+
|
4
|
+
module Gasciiart
|
5
|
+
RUNNER = <<-EOF
|
6
|
+
#!/bin/bash
|
7
|
+
|
8
|
+
echo "\033[0;40m"
|
9
|
+
|
10
|
+
for ref in `git rev-list HEAD --reverse`
|
11
|
+
do
|
12
|
+
git checkout $ref > /dev/null 2> /dev/null
|
13
|
+
clear
|
14
|
+
cat animation.txt
|
15
|
+
sleep 0.05
|
16
|
+
done
|
17
|
+
|
18
|
+
git checkout HEAD
|
19
|
+
EOF
|
20
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Gasciiart::Builder
|
4
|
+
attr_reader :source, :target, :options
|
5
|
+
|
6
|
+
def initialize(source, target, options = {})
|
7
|
+
@source, @target, @options = source, target, options
|
8
|
+
@source = "#{@source}/" unless @source[-1..-1] == '/'
|
9
|
+
@target = "#{@target}/" unless @target[-1..-1] == '/'
|
10
|
+
@verbose = options[:verbose]
|
11
|
+
|
12
|
+
@starting_dir = Dir.pwd
|
13
|
+
@target_animation = "#{@target}animation.txt"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Where all the magic happens
|
17
|
+
# Setups up the output and loops through each file from the source (in `ls` order)
|
18
|
+
# Creating a commit for each file
|
19
|
+
def build!
|
20
|
+
test_git!
|
21
|
+
|
22
|
+
file_list = Dir.glob("#{@source}*").sort # Pull the file list before creating the target directory
|
23
|
+
|
24
|
+
setup_target
|
25
|
+
|
26
|
+
add_runner
|
27
|
+
|
28
|
+
file_list.each do |infile_name|
|
29
|
+
rewrite_animation_frame infile_name
|
30
|
+
create_commit infile_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Creates and git inits the target directory
|
35
|
+
def setup_target
|
36
|
+
log "Setting up #{@target}"
|
37
|
+
|
38
|
+
if File.exists? @target
|
39
|
+
raise ArgumentError, %{Target directory "#{@target}" already exists}
|
40
|
+
end
|
41
|
+
|
42
|
+
FileUtils.mkdir @target
|
43
|
+
|
44
|
+
run "git init ."
|
45
|
+
|
46
|
+
# TODO: Create runner file
|
47
|
+
end
|
48
|
+
|
49
|
+
def rewrite_animation_frame(infile_name)
|
50
|
+
log "Writing #{infile_name}"
|
51
|
+
File.open(infile_name) do |infile|
|
52
|
+
File.open(@target_animation, 'w') do |outfile|
|
53
|
+
outfile.write infile.read # This could be streamed, but a single animation frame is small enough. Let's start simple
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_commit(infile_name)
|
59
|
+
run %{git add animation.txt && git commit -m "#{infile_name}"}
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_runner
|
63
|
+
filename = "#{@target}run.sh"
|
64
|
+
File.open(filename, 'w') do |f|
|
65
|
+
f.write Gasciiart::RUNNER
|
66
|
+
end
|
67
|
+
|
68
|
+
File.chmod 0755, filename
|
69
|
+
|
70
|
+
run %{git add run.sh && git commit -m "Added run.sh"}
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
# Log the message if verbose is on
|
76
|
+
def log(msg)
|
77
|
+
puts msg if @verbose
|
78
|
+
end
|
79
|
+
|
80
|
+
# Ensures there is the git command available
|
81
|
+
# TODO: Test git version
|
82
|
+
def test_git!
|
83
|
+
result = `which git`
|
84
|
+
if $?.exitstatus != 0
|
85
|
+
raise IOError, "Can't find git"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Runs the specified command
|
90
|
+
#
|
91
|
+
# All run commands happen in the target dir
|
92
|
+
# but all file paths are relative to the starting directory, so all the switching happens here
|
93
|
+
def run(cmd)
|
94
|
+
Dir.chdir @target
|
95
|
+
|
96
|
+
log "Running: #{cmd}"
|
97
|
+
`#{cmd}`
|
98
|
+
# if $?.exitstatus != 0
|
99
|
+
# raise IOError, %{Error executing command: "#{cmd}"}
|
100
|
+
# end
|
101
|
+
|
102
|
+
Dir.chdir @starting_dir
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gasciiart::Builder do
|
4
|
+
let(:builder) { Gasciiart::Builder.new('./', 'output') }
|
5
|
+
subject { builder }
|
6
|
+
|
7
|
+
it 'should initialize' do
|
8
|
+
b = nil
|
9
|
+
|
10
|
+
# Not really necessary, since this exception isn't caught,
|
11
|
+
# but that's all this spec does, so let's be explicit
|
12
|
+
expect {
|
13
|
+
b = Gasciiart::Builder.new('./', 'output')
|
14
|
+
}.not_to raise_exception
|
15
|
+
|
16
|
+
b.source.should == './'
|
17
|
+
b.target.should == 'output/'
|
18
|
+
b.options.should == {}
|
19
|
+
end
|
20
|
+
|
21
|
+
context "setup_target" do
|
22
|
+
it "should create the directory" do
|
23
|
+
builder.setup_target
|
24
|
+
File.directory?("output/").should == true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
# require 'fakefs'
|
3
|
+
require 'fakefs/spec_helpers'
|
4
|
+
require 'gasciiart'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.include FakeFS::SpecHelpers
|
8
|
+
|
9
|
+
config.color_enabled = true
|
10
|
+
config.formatter = 'documentation'
|
11
|
+
end
|
12
|
+
|
13
|
+
# require 'rubygems'
|
14
|
+
# require 'bundler'
|
15
|
+
# begin
|
16
|
+
# Bundler.setup(:default, :development)
|
17
|
+
# rescue Bundler::BundlerError => e
|
18
|
+
# $stderr.puts e.message
|
19
|
+
# $stderr.puts "Run `bundle install` to install missing gems"
|
20
|
+
# exit e.status_code
|
21
|
+
# end
|
22
|
+
# require 'test/unit'
|
23
|
+
# require 'shoulda'
|
24
|
+
|
25
|
+
# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
26
|
+
# $LOAD_PATH.unshift(File.dirname(__FILE__))
|
27
|
+
# require 'gasciiart'
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gasciiart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Drew Blas
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-05-07 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 39
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 10
|
32
|
+
- 0
|
33
|
+
version: 2.10.0
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakefs
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 15
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 4
|
48
|
+
- 0
|
49
|
+
version: 0.4.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Use this gem to create a git repo that can play it's file frames as a git animation
|
53
|
+
email:
|
54
|
+
- drew.blas@gmail.com
|
55
|
+
executables:
|
56
|
+
- gasciiart
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- lib/gasciiart.rb
|
63
|
+
- lib/gasciiart/builder.rb
|
64
|
+
- lib/gasciiart/version.rb
|
65
|
+
- bin/gasciiart
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/gasciiart_spec.rb
|
70
|
+
- spec/builder_spec.rb
|
71
|
+
homepage: http://github.com/drewblas/gasciiart
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 23
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 3
|
97
|
+
- 6
|
98
|
+
version: 1.3.6
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.19
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: A generator for git-based asciiart animations
|
106
|
+
test_files:
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/gasciiart_spec.rb
|
109
|
+
- spec/builder_spec.rb
|