pig 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +1 -1
- data/README.textile +1 -1
- data/VERSION +1 -1
- data/lib/generators/pig/pig_generator.rb +9 -3
- data/lib/pig.rb +50 -19
- data/pig.gemspec +2 -2
- data/spec/pig_spec.rb +37 -16
- metadata +4 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
@@ -5,18 +5,24 @@ class PigGenerator < Rails::Generators::Base
|
|
5
5
|
class_option :revision_path,
|
6
6
|
:banner => '/path_to_revisions',
|
7
7
|
:default => '/revision',
|
8
|
-
:desc => 'A root-relative path at which to display revision information
|
8
|
+
:desc => 'A root-relative path at which to display revision information'
|
9
9
|
|
10
10
|
class_option :skip_routes,
|
11
11
|
:type => :boolean,
|
12
12
|
:default => false,
|
13
|
-
:desc => 'Do not generate routes
|
13
|
+
:desc => 'Do not generate routes'
|
14
|
+
|
15
|
+
class_option :html,
|
16
|
+
:type => :boolean,
|
17
|
+
:default => true,
|
18
|
+
:desc => 'HTML output'
|
14
19
|
|
15
20
|
def install_pig
|
16
21
|
if options[:skip_routes]
|
17
22
|
puts 'Nothing to do'
|
18
23
|
else
|
19
|
-
|
24
|
+
format = options[:html] ? ':html' : ':plain'
|
25
|
+
route("match '#{formatted_revision_path}', :to => Pig.new({:format => #{format}})")
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
data/lib/pig.rb
CHANGED
@@ -1,9 +1,47 @@
|
|
1
1
|
require 'git'
|
2
2
|
|
3
|
+
WORKING_DIR = File.join(File.dirname(File.expand_path(__FILE__)), "..")
|
4
|
+
NUMBER_OF_COMMITS = 10
|
5
|
+
|
3
6
|
class Pig
|
4
7
|
|
5
|
-
|
6
|
-
|
8
|
+
attr_accessor :format
|
9
|
+
|
10
|
+
def initialize options
|
11
|
+
@format = options[:format]
|
12
|
+
end
|
13
|
+
|
14
|
+
def history
|
15
|
+
results = ""
|
16
|
+
commits = repository.log(NUMBER_OF_COMMITS) || []
|
17
|
+
commits.each do |commit|
|
18
|
+
results << format_commit(commit)
|
19
|
+
end
|
20
|
+
wrap(results)
|
21
|
+
end
|
22
|
+
|
23
|
+
def call env
|
24
|
+
rack_response_template << [history]
|
25
|
+
end
|
26
|
+
|
27
|
+
def rack_response_template
|
28
|
+
[200, {"Content-Type" => "text/#{@format}"}]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def format_commit msg
|
34
|
+
case format
|
35
|
+
when :plain
|
36
|
+
format_plain msg
|
37
|
+
when :html
|
38
|
+
format_html msg
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def repository
|
43
|
+
Git.open root_dir
|
44
|
+
end
|
7
45
|
|
8
46
|
def root_dir
|
9
47
|
if defined? Rails
|
@@ -13,28 +51,21 @@ class Pig
|
|
13
51
|
end
|
14
52
|
end
|
15
53
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
commits = repository.log(NUMBER_OF_COMMITS) || []
|
23
|
-
commits.each do |commit|
|
24
|
-
results << format(commit)
|
54
|
+
def wrap commits
|
55
|
+
case format
|
56
|
+
when :html
|
57
|
+
"<html><head><title>Latest Commits</title></head><body><ul>#{commits}</ul></body></html>"
|
58
|
+
else
|
59
|
+
commits
|
25
60
|
end
|
26
|
-
results
|
27
61
|
end
|
28
62
|
|
29
|
-
def
|
30
|
-
"#{commit.to_s}
|
63
|
+
def format_plain commit
|
64
|
+
"#{commit.message}\n #{commit.to_s}\n #{commit.author.date.strftime("%Y-%m-%d")} #{commit.author.name}\n\n"
|
31
65
|
end
|
32
66
|
|
33
|
-
def
|
34
|
-
|
67
|
+
def format_html commit
|
68
|
+
"<li><h3>#{commit.message}</h3><br />#{commit.to_s}<br />#{commit.author.date.strftime("%Y-%m-%d")} #{commit.author.name}<br /><br /></li>"
|
35
69
|
end
|
36
70
|
|
37
|
-
def rack_response_template
|
38
|
-
[200, {"Content-Type" => "text/plain"}]
|
39
|
-
end
|
40
71
|
end
|
data/pig.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pig}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jim Remsik"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-05}
|
13
13
|
s.description = %q{A rack endpoint to dynamically view the latest N formatted commits. Pig takes its name from the classic story of the chicken and the pig. Many versions of this idea exist as jokes or anecdotes wherein the two decide to start a restaurant named Ham-n-Eggs. Ultimately, the pig chooses not to participate because he would be committed and the chicken merely involved.}
|
14
14
|
s.email = %q{bigtiger@hashrocket.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/pig_spec.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Pig do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:format) { :plain }
|
6
|
+
let(:pig) { Pig.new({:format => format}) }
|
6
7
|
|
7
8
|
describe "#call" do
|
8
9
|
|
@@ -17,13 +18,23 @@ describe Pig do
|
|
17
18
|
end
|
18
19
|
|
19
20
|
describe "#format" do
|
20
|
-
|
21
|
-
let(:commit) { stub(:author => author, :to_s => "393932") }
|
21
|
+
let(:commit_message) { stub(:to_s => "One great commit") }
|
22
22
|
let(:author) { stub(:date => date, :name => "Dev Author") }
|
23
23
|
let(:date) { stub(:strftime => "12-31-01") }
|
24
|
+
let(:commit) { stub(:author => author, :to_s => "393932", :message => commit_message) }
|
25
|
+
|
26
|
+
context "plain format" do
|
27
|
+
let(:format) { :plain }
|
28
|
+
it "returns the commit message, sha1, date, and author in plain text" do
|
29
|
+
pig.send(:format_commit, commit).should == "One great commit\n 393932\n 12-31-01 Dev Author\n\n"
|
30
|
+
end
|
31
|
+
end
|
24
32
|
|
25
|
-
|
26
|
-
|
33
|
+
context "html format" do
|
34
|
+
let(:format) { :html }
|
35
|
+
it "returns the commit message, sha1, date, and author in html format" do
|
36
|
+
pig.send(:format_commit, commit).should == "<li><h3>One great commit</h3><br />393932<br />12-31-01 Dev Author<br /><br /></li>"
|
37
|
+
end
|
27
38
|
end
|
28
39
|
|
29
40
|
end
|
@@ -31,20 +42,14 @@ describe Pig do
|
|
31
42
|
describe "#repository" do
|
32
43
|
|
33
44
|
it "calls Git.open on the specified working directory" do
|
34
|
-
Git.should_receive(:open,
|
35
|
-
pig.repository
|
45
|
+
Git.should_receive(:open, WORKING_DIR)
|
46
|
+
pig.send(:repository)
|
36
47
|
end
|
37
48
|
|
38
49
|
end
|
39
50
|
|
40
51
|
describe "#history" do
|
41
52
|
|
42
|
-
before do
|
43
|
-
repo = stub(:log)
|
44
|
-
pig.stub(:repository).and_return(repo)
|
45
|
-
repo.stub(:log, 10).and_return([])
|
46
|
-
end
|
47
|
-
|
48
53
|
it "retrieves a log of the last 10 commits by default" do
|
49
54
|
repo = stub(:log)
|
50
55
|
pig.should_receive(:repository).and_return(repo)
|
@@ -52,10 +57,26 @@ describe Pig do
|
|
52
57
|
pig.history
|
53
58
|
end
|
54
59
|
|
55
|
-
|
56
|
-
|
60
|
+
context "when no commits" do
|
61
|
+
before do
|
62
|
+
repo = stub(:log)
|
63
|
+
pig.stub(:repository).and_return(repo)
|
64
|
+
repo.stub(:log, 10).and_return([])
|
65
|
+
end
|
66
|
+
|
67
|
+
context "plain format" do
|
68
|
+
it "returns an empty string" do
|
69
|
+
pig.history.should == ""
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "html format" do
|
74
|
+
let(:format) { :html }
|
75
|
+
it "returns empty html" do
|
76
|
+
pig.history.should == "<html><head><title>Latest Commits</title></head><body><ul></ul></body></html>"
|
77
|
+
end
|
78
|
+
end
|
57
79
|
end
|
58
|
-
|
59
80
|
end
|
60
81
|
|
61
82
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Remsik
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-05 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|