git-trip 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +21 -0
- data/Manifest.txt +89 -0
- data/README.txt +60 -0
- data/Rakefile +31 -0
- data/bin/git-trip +0 -0
- data/doc/USAGE.txt +54 -0
- data/lib/core_ext/hash.rb +15 -0
- data/lib/git-trip.rb +23 -0
- data/lib/git-trip/errors.rb +22 -0
- data/lib/git-trip/gitter.rb +10 -0
- data/lib/git-trip/gitter/base.rb +18 -0
- data/lib/git-trip/gitter/dir.rb +32 -0
- data/lib/git-trip/gitter/uri.rb +40 -0
- data/lib/git-trip/paint_mode.rb +52 -0
- data/lib/git-trip/painter.rb +167 -0
- data/spec/core_ext/hash_spec.rb +25 -0
- data/spec/git-trip/errors_spec.rb +43 -0
- data/spec/git-trip/gitter/base_spec.rb +15 -0
- data/spec/git-trip/gitter/dir_spec.rb +37 -0
- data/spec/git-trip/gitter/uri_spec.rb +25 -0
- data/spec/git-trip/gitter_spec.rb +11 -0
- data/spec/git-trip/paint_mode_spec.rb +56 -0
- data/spec/git-trip/painter_spec.rb +173 -0
- data/spec/git_trip_spec.rb +23 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +15 -0
- data/tasks/ditz.rake +42 -0
- data/tasks/docs.rake +68 -0
- data/tasks/gittrip.rake +63 -0
- data/tasks/rspec.rake +22 -0
- data/tasks/site.rake +48 -0
- data/tasks/util.rake +44 -0
- data/vendor/grit/History.txt +6 -0
- data/vendor/grit/Manifest.txt +53 -0
- data/vendor/grit/README.txt +213 -0
- data/vendor/grit/Rakefile +29 -0
- data/vendor/grit/grit.gemspec +16 -0
- data/vendor/grit/lib/grit.rb +37 -0
- data/vendor/grit/lib/grit/actor.rb +36 -0
- data/vendor/grit/lib/grit/blob.rb +117 -0
- data/vendor/grit/lib/grit/commit.rb +208 -0
- data/vendor/grit/lib/grit/config.rb +44 -0
- data/vendor/grit/lib/grit/diff.rb +70 -0
- data/vendor/grit/lib/grit/errors.rb +7 -0
- data/vendor/grit/lib/grit/git.rb +116 -0
- data/vendor/grit/lib/grit/index.rb +77 -0
- data/vendor/grit/lib/grit/lazy.rb +31 -0
- data/vendor/grit/lib/grit/ref.rb +110 -0
- data/vendor/grit/lib/grit/repo.rb +318 -0
- data/vendor/grit/lib/grit/tree.rb +99 -0
- data/vendor/grit/test/fixtures/blame +131 -0
- data/vendor/grit/test/fixtures/cat_file_blob +1 -0
- data/vendor/grit/test/fixtures/cat_file_blob_size +1 -0
- data/vendor/grit/test/fixtures/diff_2 +54 -0
- data/vendor/grit/test/fixtures/diff_2f +19 -0
- data/vendor/grit/test/fixtures/diff_f +15 -0
- data/vendor/grit/test/fixtures/diff_i +201 -0
- data/vendor/grit/test/fixtures/diff_mode_only +1152 -0
- data/vendor/grit/test/fixtures/diff_new_mode +17 -0
- data/vendor/grit/test/fixtures/diff_p +610 -0
- data/vendor/grit/test/fixtures/for_each_ref +0 -0
- data/vendor/grit/test/fixtures/for_each_ref_remotes +0 -0
- data/vendor/grit/test/fixtures/for_each_ref_tags +0 -0
- data/vendor/grit/test/fixtures/ls_tree_a +7 -0
- data/vendor/grit/test/fixtures/ls_tree_b +2 -0
- data/vendor/grit/test/fixtures/ls_tree_commit +3 -0
- data/vendor/grit/test/fixtures/rev_list +26 -0
- data/vendor/grit/test/fixtures/rev_list_count +655 -0
- data/vendor/grit/test/fixtures/rev_list_single +7 -0
- data/vendor/grit/test/fixtures/rev_parse +1 -0
- data/vendor/grit/test/fixtures/show_empty_commit +6 -0
- data/vendor/grit/test/fixtures/simple_config +2 -0
- data/vendor/grit/test/helper.rb +17 -0
- data/vendor/grit/test/profile.rb +21 -0
- data/vendor/grit/test/suite.rb +6 -0
- data/vendor/grit/test/test_actor.rb +35 -0
- data/vendor/grit/test/test_blob.rb +74 -0
- data/vendor/grit/test/test_commit.rb +182 -0
- data/vendor/grit/test/test_config.rb +58 -0
- data/vendor/grit/test/test_diff.rb +18 -0
- data/vendor/grit/test/test_git.rb +52 -0
- data/vendor/grit/test/test_head.rb +22 -0
- data/vendor/grit/test/test_real.rb +19 -0
- data/vendor/grit/test/test_reality.rb +17 -0
- data/vendor/grit/test/test_remote.rb +15 -0
- data/vendor/grit/test/test_repo.rb +278 -0
- data/vendor/grit/test/test_tag.rb +29 -0
- data/vendor/grit/test/test_tree.rb +91 -0
- metadata +179 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
=== 0.0.3 / 2008-07-08
|
2
|
+
|
3
|
+
Many nice changes, including (but not limited to):
|
4
|
+
|
5
|
+
* Better handling of internal images.
|
6
|
+
* Smarter defaults.
|
7
|
+
* More options to GitTrip::Painter
|
8
|
+
* GitTrip::Painter#save
|
9
|
+
* All new GitTrip::PaintMode, which makes your images pretty!
|
10
|
+
* Documentation updates.
|
11
|
+
|
12
|
+
=== 0.0.2 / 2008-07-04
|
13
|
+
|
14
|
+
* Actually functioning!
|
15
|
+
|
16
|
+
=== 0.0.1 / 2008-07-02
|
17
|
+
|
18
|
+
* 1 major enhancement
|
19
|
+
|
20
|
+
* New project.
|
21
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
bin/git-trip
|
6
|
+
doc/USAGE.txt
|
7
|
+
lib/core_ext/hash.rb
|
8
|
+
lib/git-trip.rb
|
9
|
+
lib/git-trip/errors.rb
|
10
|
+
lib/git-trip/gitter.rb
|
11
|
+
lib/git-trip/gitter/base.rb
|
12
|
+
lib/git-trip/gitter/dir.rb
|
13
|
+
lib/git-trip/gitter/uri.rb
|
14
|
+
lib/git-trip/paint_mode.rb
|
15
|
+
lib/git-trip/painter.rb
|
16
|
+
spec/core_ext/hash_spec.rb
|
17
|
+
spec/git-trip/errors_spec.rb
|
18
|
+
spec/git-trip/gitter/base_spec.rb
|
19
|
+
spec/git-trip/gitter/dir_spec.rb
|
20
|
+
spec/git-trip/gitter/uri_spec.rb
|
21
|
+
spec/git-trip/gitter_spec.rb
|
22
|
+
spec/git-trip/paint_mode_spec.rb
|
23
|
+
spec/git-trip/painter_spec.rb
|
24
|
+
spec/git_trip_spec.rb
|
25
|
+
spec/rcov.opts
|
26
|
+
spec/spec.opts
|
27
|
+
spec/spec_helper.rb
|
28
|
+
tasks/ditz.rake
|
29
|
+
tasks/docs.rake
|
30
|
+
tasks/gittrip.rake
|
31
|
+
tasks/rspec.rake
|
32
|
+
tasks/site.rake
|
33
|
+
tasks/util.rake
|
34
|
+
vendor/grit/History.txt
|
35
|
+
vendor/grit/Manifest.txt
|
36
|
+
vendor/grit/README.txt
|
37
|
+
vendor/grit/Rakefile
|
38
|
+
vendor/grit/grit.gemspec
|
39
|
+
vendor/grit/lib/grit.rb
|
40
|
+
vendor/grit/lib/grit/actor.rb
|
41
|
+
vendor/grit/lib/grit/blob.rb
|
42
|
+
vendor/grit/lib/grit/commit.rb
|
43
|
+
vendor/grit/lib/grit/config.rb
|
44
|
+
vendor/grit/lib/grit/diff.rb
|
45
|
+
vendor/grit/lib/grit/errors.rb
|
46
|
+
vendor/grit/lib/grit/git.rb
|
47
|
+
vendor/grit/lib/grit/index.rb
|
48
|
+
vendor/grit/lib/grit/lazy.rb
|
49
|
+
vendor/grit/lib/grit/ref.rb
|
50
|
+
vendor/grit/lib/grit/repo.rb
|
51
|
+
vendor/grit/lib/grit/tree.rb
|
52
|
+
vendor/grit/test/fixtures/blame
|
53
|
+
vendor/grit/test/fixtures/cat_file_blob
|
54
|
+
vendor/grit/test/fixtures/cat_file_blob_size
|
55
|
+
vendor/grit/test/fixtures/diff_2
|
56
|
+
vendor/grit/test/fixtures/diff_2f
|
57
|
+
vendor/grit/test/fixtures/diff_f
|
58
|
+
vendor/grit/test/fixtures/diff_i
|
59
|
+
vendor/grit/test/fixtures/diff_mode_only
|
60
|
+
vendor/grit/test/fixtures/diff_new_mode
|
61
|
+
vendor/grit/test/fixtures/diff_p
|
62
|
+
vendor/grit/test/fixtures/for_each_ref
|
63
|
+
vendor/grit/test/fixtures/for_each_ref_remotes
|
64
|
+
vendor/grit/test/fixtures/for_each_ref_tags
|
65
|
+
vendor/grit/test/fixtures/ls_tree_a
|
66
|
+
vendor/grit/test/fixtures/ls_tree_b
|
67
|
+
vendor/grit/test/fixtures/ls_tree_commit
|
68
|
+
vendor/grit/test/fixtures/rev_list
|
69
|
+
vendor/grit/test/fixtures/rev_list_count
|
70
|
+
vendor/grit/test/fixtures/rev_list_single
|
71
|
+
vendor/grit/test/fixtures/rev_parse
|
72
|
+
vendor/grit/test/fixtures/show_empty_commit
|
73
|
+
vendor/grit/test/fixtures/simple_config
|
74
|
+
vendor/grit/test/helper.rb
|
75
|
+
vendor/grit/test/profile.rb
|
76
|
+
vendor/grit/test/suite.rb
|
77
|
+
vendor/grit/test/test_actor.rb
|
78
|
+
vendor/grit/test/test_blob.rb
|
79
|
+
vendor/grit/test/test_commit.rb
|
80
|
+
vendor/grit/test/test_config.rb
|
81
|
+
vendor/grit/test/test_diff.rb
|
82
|
+
vendor/grit/test/test_git.rb
|
83
|
+
vendor/grit/test/test_head.rb
|
84
|
+
vendor/grit/test/test_real.rb
|
85
|
+
vendor/grit/test/test_reality.rb
|
86
|
+
vendor/grit/test/test_remote.rb
|
87
|
+
vendor/grit/test/test_repo.rb
|
88
|
+
vendor/grit/test/test_tag.rb
|
89
|
+
vendor/grit/test/test_tree.rb
|
data/README.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= GitTrip
|
2
|
+
|
3
|
+
Author:: Dale Campbell <dale@save-state.net>
|
4
|
+
Code:: http://github.com/Oshuma/git-trip/
|
5
|
+
Site:: http://git-trip.rubyforge.org/
|
6
|
+
|
7
|
+
=== DESCRIPTION:
|
8
|
+
|
9
|
+
Visualize git commit SHAs. It's nerd acid!
|
10
|
+
|
11
|
+
=== SYNOPSIS:
|
12
|
+
|
13
|
+
GitTrip is a unique, completely useless, way of visualizing git commit SHA
|
14
|
+
strings. Since a single SHA is 40 characters (0-9a-f), you can (for example)
|
15
|
+
derive 6 RGB colors from each git object. (40/6 == 6 with 4 characters left over)
|
16
|
+
With these 6 colors comes a wide range of possibilities. GitTrip::Painter will
|
17
|
+
support multiple 'rendering modes' which will determine what the resulting
|
18
|
+
commit image will look like.
|
19
|
+
|
20
|
+
If you find bugs, or have suggestions, post them on the RubyForge tracker and
|
21
|
+
forums, respectively.
|
22
|
+
|
23
|
+
Tracker:: http://rubyforge.org/tracker/?group_id=6594
|
24
|
+
Forums:: http://rubyforge.org/forum/?group_id=6594
|
25
|
+
|
26
|
+
=== REQUIREMENTS:
|
27
|
+
|
28
|
+
* RMagick - http://rmagick.rubyforge.org/
|
29
|
+
* Grit - http://grit.rubyforge.org/
|
30
|
+
* JSON - http://json.rubyforge.org/
|
31
|
+
* mime-types - http://mime-types.rubyforge.org/
|
32
|
+
* open4 - http://raa.ruby-lang.org/project/open4/
|
33
|
+
|
34
|
+
=== INSTALL:
|
35
|
+
|
36
|
+
# From Github:
|
37
|
+
$ gem sources -a http://gems.github.com/ # (You only need to do this once.)
|
38
|
+
$ gem install Oshuma-git-trip
|
39
|
+
|
40
|
+
=== USAGE:
|
41
|
+
|
42
|
+
See doc/USAGE.txt.
|
43
|
+
|
44
|
+
=== LICENSE:
|
45
|
+
|
46
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
47
|
+
Version 2, December 2004
|
48
|
+
http://sam.zoy.org/wtfpl/
|
49
|
+
|
50
|
+
|
51
|
+
Copyright (C) 2008 Dale Campbell <dale@save-state.net>
|
52
|
+
|
53
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
54
|
+
copies of this license document, and changing it is allowed as long
|
55
|
+
as the name is changed.
|
56
|
+
|
57
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
58
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
59
|
+
|
60
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require './lib/git-trip.rb'
|
4
|
+
|
5
|
+
APP_ROOT = File.dirname(__FILE__) unless defined?(APP_ROOT)
|
6
|
+
|
7
|
+
task :default => [ :spec ]
|
8
|
+
|
9
|
+
Hoe.new('git-trip', GitTrip::VERSION) do |p|
|
10
|
+
p.developer('Dale Campbell', 'dale@save-state.net')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Load any rakefiles in tasks/
|
14
|
+
custom_tasks = FileList['tasks/**/*.rake'].sort
|
15
|
+
# Load util.rake before any others...
|
16
|
+
load custom_tasks.delete('tasks/util.rake')
|
17
|
+
# ...now load the rest.
|
18
|
+
custom_tasks.each { |task| load task }
|
19
|
+
|
20
|
+
# Remove un-needed tasks.
|
21
|
+
remove_task 'audit'
|
22
|
+
remove_task 'generate_key'
|
23
|
+
remove_task 'multi'
|
24
|
+
remove_task 'post_blog'
|
25
|
+
remove_task 'test'
|
26
|
+
remove_task 'test_deps'
|
27
|
+
|
28
|
+
desc 'Start an irb session with Ridge loaded'
|
29
|
+
task :console do
|
30
|
+
sh "irb -d -I ./lib -r 'git-trip'"
|
31
|
+
end
|
data/bin/git-trip
ADDED
File without changes
|
data/doc/USAGE.txt
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
See the individual class docs for more options and specific examples.
|
2
|
+
|
3
|
+
# Load it up!
|
4
|
+
require 'git-trip'
|
5
|
+
|
6
|
+
# Grab repository information.
|
7
|
+
repo = GitTrip::Gitter::Dir.new('/path/to/repo')
|
8
|
+
# .. or ..
|
9
|
+
repo = GitTrip::Gitter::URI.new('http://domain.com/path/to/repo')
|
10
|
+
|
11
|
+
# Now that you have a repository, you can do cool shit.
|
12
|
+
repo.commits.each do |commit|
|
13
|
+
# GitTrip::Painter requires a commit SHA (string).
|
14
|
+
painter = GitTrip::Painter.new(commit)
|
15
|
+
|
16
|
+
# This does the work of creating a commit specific image.
|
17
|
+
painter.paint!
|
18
|
+
|
19
|
+
# painter's +picture+ now holds a Magick::Image, so all of it's methods are supported.
|
20
|
+
painter.picture.display
|
21
|
+
|
22
|
+
# From this point, you can do something pretty with the image.
|
23
|
+
# GitTrip::PaintMode takes a Magick::Image and a mode type.
|
24
|
+
pretty = GitTrip::PaintMode.new(painter.picture, :pixel)
|
25
|
+
|
26
|
+
# Just as with GitTrip::Painter, pretty's +picture+ now holds a Magick::Image.
|
27
|
+
pretty.picture.display
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
If you wanted to use GitTrip in a Rails application, here's an example controller ##create method.
|
32
|
+
|
33
|
+
# app/controllers/trip_controller.rb
|
34
|
+
class TripController < ApplicationController
|
35
|
+
def create
|
36
|
+
painter = GitTrip::Painter.new(params[:hash])
|
37
|
+
painter.paint!
|
38
|
+
pretty = GitTrip::PaintMode.new(painter.picture, :blend)
|
39
|
+
pretty.picture.format = 'PNG'
|
40
|
+
send_data pretty.picture.to_blob,
|
41
|
+
:filename => 'trip.png',
|
42
|
+
:type => 'image/png',
|
43
|
+
:disposition => 'inline'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# config/routes.rb
|
48
|
+
map.trip 'trip/:hash', :controller => 'trip', :action => 'create'
|
49
|
+
|
50
|
+
Then use it like so:
|
51
|
+
|
52
|
+
<img src="http://domain.com/trip/103d8734bd5fb0958ea0b6fa3fe59de7ada96df7" />
|
53
|
+
|
54
|
+
Slick. Thanks goes to Scott Barron <http://rubyi.st> for that tip.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Extensions to the core Hash class.
|
2
|
+
class Hash
|
3
|
+
# Turn all string keys into symbols. Returns the modified hash.
|
4
|
+
def symbolize_keys
|
5
|
+
inject({}) do |options, (key, value)|
|
6
|
+
options[key.to_sym || key] = value
|
7
|
+
options
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Destructive version of symbolize_keys.
|
12
|
+
def symbolize_keys!
|
13
|
+
self.replace(self.symbolize_keys)
|
14
|
+
end
|
15
|
+
end
|
data/lib/git-trip.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
# Third-party libraries...
|
4
|
+
require 'rubygems'
|
5
|
+
require 'digest/sha1'
|
6
|
+
require 'json'
|
7
|
+
require 'open-uri'
|
8
|
+
require 'RMagick'
|
9
|
+
|
10
|
+
# ...in ./vendor/
|
11
|
+
require 'vendor/grit/lib/grit'
|
12
|
+
|
13
|
+
# GitTrip libraries.
|
14
|
+
require 'core_ext/hash'
|
15
|
+
require 'git-trip/errors'
|
16
|
+
require 'git-trip/gitter'
|
17
|
+
require 'git-trip/paint_mode'
|
18
|
+
require 'git-trip/painter'
|
19
|
+
|
20
|
+
module GitTrip
|
21
|
+
VERSION = '0.0.3'
|
22
|
+
include GitTrip::Errors
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module GitTrip
|
2
|
+
|
3
|
+
# Holds Errors (Exceptions) specific to GitTrip.
|
4
|
+
module Errors
|
5
|
+
%w{
|
6
|
+
DirNotFound
|
7
|
+
InvalidFormat
|
8
|
+
InvalidGitRepo
|
9
|
+
InvalidMode
|
10
|
+
InvalidPicture
|
11
|
+
InvalidSHA
|
12
|
+
InvalidStyle
|
13
|
+
InvalidURI
|
14
|
+
NoCommits
|
15
|
+
NoPicture
|
16
|
+
RTFM
|
17
|
+
}.each do |problem|
|
18
|
+
eval("class #{problem} < Exception; end")
|
19
|
+
end
|
20
|
+
end # of Errors
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GitTrip
|
2
|
+
module Gitter
|
3
|
+
|
4
|
+
# Provides common git functionality to it's children.
|
5
|
+
class Base
|
6
|
+
# Returns an array containing each commit SHA.
|
7
|
+
def commits
|
8
|
+
@data[:commits]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Iterator for the commits.
|
12
|
+
def each_commit(&block)
|
13
|
+
@data[:commits].each { |commit| yield commit }
|
14
|
+
end
|
15
|
+
end # of Base
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GitTrip
|
2
|
+
module Gitter
|
3
|
+
|
4
|
+
# Handles fetching git repository information from a directory.
|
5
|
+
class Dir < Gitter::Base
|
6
|
+
# <tt>dir</tt> should be a path to a git repository (containing a .git/ subdirectory).
|
7
|
+
def initialize(dir, options = {})
|
8
|
+
raise Errors::DirNotFound unless File.exists?(dir)
|
9
|
+
@repo = Grit::Repo.new(dir)
|
10
|
+
@data = {}
|
11
|
+
setup_data_hash
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Loads the <tt>@data</tt> hash with repository information.
|
17
|
+
def setup_data_hash
|
18
|
+
load_repo_commits
|
19
|
+
end
|
20
|
+
|
21
|
+
# Loads a hash of commits into <tt>@data[:commits]</tt>.
|
22
|
+
def load_repo_commits
|
23
|
+
commits = []
|
24
|
+
@repo.commits(@repo.head.name, @repo.commit_count).map do |c|
|
25
|
+
commits << c.to_s
|
26
|
+
end
|
27
|
+
@data[:commits] = commits
|
28
|
+
end
|
29
|
+
end # of Dir
|
30
|
+
|
31
|
+
end # of Gitter
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module GitTrip
|
2
|
+
module Gitter
|
3
|
+
|
4
|
+
# Handles fetching git repository information from a remote URI.
|
5
|
+
class URI < Gitter::Base
|
6
|
+
FORMATS = %w{ json xml yaml }
|
7
|
+
PROTOCOLS = %w{ http https }
|
8
|
+
|
9
|
+
DEFAULTS = {
|
10
|
+
:format => 'json'
|
11
|
+
}
|
12
|
+
|
13
|
+
# Takes a +uri+ that returns information about a repository;
|
14
|
+
# expects JSON data by default (see FORMATS).
|
15
|
+
# The second argument is an optional hash of +options+ (see DEFAULTS).
|
16
|
+
#
|
17
|
+
# <tt>options</tt> can contain:
|
18
|
+
# * <tt>format</tt>: Defaults to 'json'; see FORMATS.
|
19
|
+
def initialize(uri, options = {})
|
20
|
+
raise Errors::InvalidURI if invalid_uri?(uri)
|
21
|
+
@uri = uri
|
22
|
+
@options = DEFAULTS.merge(options)
|
23
|
+
raise Errors::InvalidFormat if invalid_format?(@options[:format])
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Returns true if the given +format+ is invalid.
|
29
|
+
def invalid_format?(format)
|
30
|
+
return true unless FORMATS.include?(format)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns true if the given +uri+ is invalid.
|
34
|
+
def invalid_uri?(uri)
|
35
|
+
uri.grep(/^(#{PROTOCOLS.join('|')}):\/\/\w/).empty?
|
36
|
+
end
|
37
|
+
end # of URI
|
38
|
+
|
39
|
+
end # of Gitter
|
40
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module GitTrip
|
2
|
+
|
3
|
+
class PaintMode
|
4
|
+
MODES = [
|
5
|
+
:blend,
|
6
|
+
:pixel,
|
7
|
+
:radial
|
8
|
+
]
|
9
|
+
|
10
|
+
attr_reader :picture
|
11
|
+
|
12
|
+
# This class takes an +image+ generated from GitTrip::Painter and does
|
13
|
+
# something pretty with it. +mode+ can be anything listed in MODES, as
|
14
|
+
# a string or symbol. There's a 'picture' reader that returns the
|
15
|
+
# generated Magick::Image.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
# painter = GitTrip::Painter.new(commit_sha)
|
19
|
+
# painter.paint! # Create the commit specific image.
|
20
|
+
# pretty = GitTrip::PaintMode.new(painter.picture, :pixel)
|
21
|
+
# # pretty now holds a Magick::Image.
|
22
|
+
# pretty.display
|
23
|
+
def initialize(image, mode)
|
24
|
+
raise Errors::InvalidPicture unless image.is_a?(Magick::Image)
|
25
|
+
raise Errors::InvalidMode unless MODES.include?(mode.to_sym)
|
26
|
+
@mode = mode.to_sym
|
27
|
+
@image = image
|
28
|
+
|
29
|
+
@picture = case @mode
|
30
|
+
when :blend: blend_mode
|
31
|
+
when :pixel: pixel_mode
|
32
|
+
when :radial: radial_mode
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Blend <tt>@image</tt>.
|
37
|
+
def blend_mode(distance = 35)
|
38
|
+
@image.motion_blur(0, distance, 180)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Pixelize <tt>@image</tt>.
|
42
|
+
def pixel_mode
|
43
|
+
@image.ordered_dither
|
44
|
+
end
|
45
|
+
|
46
|
+
# Radialize <tt>@image</tt>
|
47
|
+
def radial_mode
|
48
|
+
@image.radial_blur(90)
|
49
|
+
end
|
50
|
+
end # of PaintMode
|
51
|
+
|
52
|
+
end
|