git_presenter 0.2.2 → 0.3.0
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/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +25 -11
- data/README.markdown +4 -1
- data/VERSION +1 -1
- data/bin/git-presenter +2 -18
- data/git_presenter.gemspec +12 -5
- data/lib/git_presenter/controller.rb +57 -0
- data/lib/git_presenter/presentation.rb +76 -76
- data/lib/git_presenter/slide.rb +22 -24
- data/lib/git_presenter.rb +30 -9
- data/spec/bugs/max_10_commits_being_parsed_spec.rb +13 -0
- data/spec/integration/initialize_presentation_spec.rb +2 -2
- data/spec/integration/moving_through_presentation_spec.rb +12 -1
- data/spec/integration/start_presentation_spec.rb +3 -2
- data/spec/integration/update_presentation_spec.rb +42 -0
- data/spec/lib/git_presenter/controller_spec.rb +4 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/git_helpers.rb +49 -18
- metadata +39 -16
- data/lib/git_presenter/parser.rb +0 -16
- data/lib/git_presenter/writer.rb +0 -32
- data/spec/lib/git_presenter/writer_spec.rb +0 -4
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -8,8 +8,10 @@ gem "grit", "~> 2.4"
|
|
8
8
|
# Add dependencies to develop your gem here.
|
9
9
|
# Include everything needed to run rake, tests, features, etc.
|
10
10
|
group :development do
|
11
|
+
gem "pry"
|
11
12
|
gem "rspec", "~> 2.7"
|
12
13
|
gem "bundler"
|
13
14
|
gem "jeweler", "~> 1.6"
|
14
15
|
gem "rcov", "~> 0.9"
|
16
|
+
gem 'pry'
|
15
17
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,39 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
coderay (1.0.6)
|
4
5
|
diff-lcs (1.1.3)
|
5
6
|
git (1.2.5)
|
6
|
-
grit (2.
|
7
|
+
grit (2.5.0)
|
7
8
|
diff-lcs (~> 1.1)
|
8
9
|
mime-types (~> 1.15)
|
9
|
-
|
10
|
+
posix-spawn (~> 0.3.6)
|
11
|
+
jeweler (1.8.3)
|
10
12
|
bundler (~> 1.0)
|
11
13
|
git (>= 1.2.5)
|
12
14
|
rake
|
13
|
-
|
15
|
+
rdoc
|
16
|
+
json (1.7.3)
|
17
|
+
method_source (0.7.1)
|
18
|
+
mime-types (1.18)
|
19
|
+
posix-spawn (0.3.6)
|
20
|
+
pry (0.9.9.6)
|
21
|
+
coderay (~> 1.0.5)
|
22
|
+
method_source (~> 0.7.1)
|
23
|
+
slop (>= 2.4.4, < 3)
|
14
24
|
rake (0.9.2.2)
|
15
25
|
rcov (0.9.11)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rspec-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
rspec-
|
26
|
+
rdoc (3.12)
|
27
|
+
json (~> 1.4)
|
28
|
+
rspec (2.10.0)
|
29
|
+
rspec-core (~> 2.10.0)
|
30
|
+
rspec-expectations (~> 2.10.0)
|
31
|
+
rspec-mocks (~> 2.10.0)
|
32
|
+
rspec-core (2.10.1)
|
33
|
+
rspec-expectations (2.10.0)
|
34
|
+
diff-lcs (~> 1.1.3)
|
35
|
+
rspec-mocks (2.10.1)
|
36
|
+
slop (2.4.4)
|
24
37
|
|
25
38
|
PLATFORMS
|
26
39
|
ruby
|
@@ -29,5 +42,6 @@ DEPENDENCIES
|
|
29
42
|
bundler
|
30
43
|
grit (~> 2.4)
|
31
44
|
jeweler (~> 1.6)
|
45
|
+
pry
|
32
46
|
rcov (~> 0.9)
|
33
47
|
rspec (~> 2.7)
|
data/README.markdown
CHANGED
@@ -17,7 +17,9 @@ Any and all feedback is welcome
|
|
17
17
|
## Pre-requisites
|
18
18
|
|
19
19
|
* Git
|
20
|
-
* Ruby version 1.9.2 or 1.9.3
|
20
|
+
* Ruby version 1.9.2 or 1.9.3
|
21
|
+
|
22
|
+
Note jruby is currently unsupported as there is a problem with posix-spawn and jruby
|
21
23
|
|
22
24
|
## Installation
|
23
25
|
|
@@ -28,6 +30,7 @@ gem install git_presenter
|
|
28
30
|
* Commit to git as you develop your code.
|
29
31
|
* When the code is ready use the "git-presenter init" command to initialise
|
30
32
|
* Once it is initialised you can start the presentation with "git-presenter start"
|
33
|
+
* Make more commits if need be and use "git-presenter update"
|
31
34
|
* Then use the following command to navigate the presentation
|
32
35
|
* next/n: move to next slide
|
33
36
|
* back/b: move back a slide
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/git-presenter
CHANGED
@@ -1,24 +1,8 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
|
3
2
|
require "rubygems"
|
4
|
-
require "readline"
|
5
3
|
require_relative "../lib/git_presenter"
|
6
4
|
|
7
5
|
YAML::ENGINE.yamler = 'psych'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
puts "Presentation has been initalised"
|
12
|
-
puts "run 'git-presenter start' to begin the presentation"
|
13
|
-
elsif ARGV[0] == "start"
|
14
|
-
presenter = GitPresenter.start_presentation(Dir.pwd)
|
15
|
-
puts presenter.current_slide
|
16
|
-
|
17
|
-
while command = Readline.readline(presenter.status_line, true)
|
18
|
-
result = presenter.execute(command)
|
19
|
-
exit if result == :exit
|
20
|
-
puts result
|
21
|
-
end
|
22
|
-
else
|
23
|
-
puts "what you talkin bout willis"
|
24
|
-
end
|
7
|
+
presenter = GitPresenter.new(Dir.pwd)
|
8
|
+
presenter.execute(ARGV[0])
|
data/git_presenter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "git_presenter"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Colin Gemmell"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-06-29"
|
13
13
|
s.description = "Code presentation tool using git"
|
14
14
|
s.email = "pythonandchips@gmail.com"
|
15
15
|
s.executables = ["git-presenter"]
|
@@ -29,16 +29,17 @@ Gem::Specification.new do |s|
|
|
29
29
|
"bin/git-presenter",
|
30
30
|
"git_presenter.gemspec",
|
31
31
|
"lib/git_presenter.rb",
|
32
|
-
"lib/git_presenter/
|
32
|
+
"lib/git_presenter/controller.rb",
|
33
33
|
"lib/git_presenter/presentation.rb",
|
34
34
|
"lib/git_presenter/slide.rb",
|
35
|
-
"
|
35
|
+
"spec/bugs/max_10_commits_being_parsed_spec.rb",
|
36
36
|
"spec/integration/initialize_presentation_spec.rb",
|
37
37
|
"spec/integration/moving_through_presentation_spec.rb",
|
38
38
|
"spec/integration/start_presentation_spec.rb",
|
39
|
+
"spec/integration/update_presentation_spec.rb",
|
40
|
+
"spec/lib/git_presenter/controller_spec.rb",
|
39
41
|
"spec/lib/git_presenter/presentation_spec.rb",
|
40
42
|
"spec/lib/git_presenter/slide_spec.rb",
|
41
|
-
"spec/lib/git_presenter/writer_spec.rb",
|
42
43
|
"spec/spec_helper.rb",
|
43
44
|
"spec/support/command_line_helper.rb",
|
44
45
|
"spec/support/git_helpers.rb"
|
@@ -54,23 +55,29 @@ Gem::Specification.new do |s|
|
|
54
55
|
|
55
56
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
57
|
s.add_runtime_dependency(%q<grit>, ["~> 2.4"])
|
58
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
57
59
|
s.add_development_dependency(%q<rspec>, ["~> 2.7"])
|
58
60
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
59
61
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
|
60
62
|
s.add_development_dependency(%q<rcov>, ["~> 0.9"])
|
63
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
61
64
|
else
|
62
65
|
s.add_dependency(%q<grit>, ["~> 2.4"])
|
66
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
63
67
|
s.add_dependency(%q<rspec>, ["~> 2.7"])
|
64
68
|
s.add_dependency(%q<bundler>, [">= 0"])
|
65
69
|
s.add_dependency(%q<jeweler>, ["~> 1.6"])
|
66
70
|
s.add_dependency(%q<rcov>, ["~> 0.9"])
|
71
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
67
72
|
end
|
68
73
|
else
|
69
74
|
s.add_dependency(%q<grit>, ["~> 2.4"])
|
75
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
70
76
|
s.add_dependency(%q<rspec>, ["~> 2.7"])
|
71
77
|
s.add_dependency(%q<bundler>, [">= 0"])
|
72
78
|
s.add_dependency(%q<jeweler>, ["~> 1.6"])
|
73
79
|
s.add_dependency(%q<rcov>, ["~> 0.9"])
|
80
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class GitPresenter::Controller
|
2
|
+
CONFIG_FILE = ".presentation"
|
3
|
+
|
4
|
+
def initialize(file_path)
|
5
|
+
@presentation_dir = file_path
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialise_presentation
|
9
|
+
yaml = {"slides" => create_slides}.to_yaml
|
10
|
+
File.open(presentation_file_location, "w") do |file|
|
11
|
+
file.write(yaml)
|
12
|
+
end
|
13
|
+
puts "Presentation has been initalised"
|
14
|
+
puts "run 'git-presenter start' to begin the presentation"
|
15
|
+
end
|
16
|
+
|
17
|
+
def start_presentation
|
18
|
+
yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
|
19
|
+
presenter = GitPresenter::Presentation.new(yaml)
|
20
|
+
puts presenter.start
|
21
|
+
presenter
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_presentation
|
25
|
+
yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
|
26
|
+
slides = create_slides(yaml['slides'].last["slide"]["commit"])
|
27
|
+
last_commit = yaml["slides"].last
|
28
|
+
yaml["slides"] = yaml["slides"] + slides
|
29
|
+
yaml["slides"].uniq!
|
30
|
+
write_file(yaml.to_yaml)
|
31
|
+
puts "Your presentation has been updated"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def write_file(yaml)
|
37
|
+
File.open(presentation_file_location, "w") do |file|
|
38
|
+
file.write(yaml)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def presentation_file_location
|
43
|
+
File.join(@presentation_dir, CONFIG_FILE)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_slides(last_commit=nil)
|
47
|
+
repo = Grit::Repo.new(".", "master")
|
48
|
+
commits = repo.commits("master", false).reverse
|
49
|
+
commits = commits.drop_while{|commit| commit.id != last_commit}[1..-1] unless last_commit.nil?
|
50
|
+
commits.map do |commit|
|
51
|
+
{"slide" =>
|
52
|
+
{"commit" => commit.id,
|
53
|
+
"message" => commit.message}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,60 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_reader :slides, :current_slide
|
1
|
+
class GitPresenter::Presentation
|
2
|
+
attr_reader :slides, :current_slide
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def initialize(presentation)
|
5
|
+
@slides = presentation["slides"].map{|slide| GitPresenter::Slide.new(slide["slide"])}
|
6
|
+
@current_slide = slides.first
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
def command_for(command)
|
10
|
+
return :commit if command =~ /^[0-9]+$/
|
11
|
+
return :command if command[0] == "!"
|
12
|
+
{"n" => :next, "next" => :next,
|
13
|
+
"back" => :previous, "b" => :previous,
|
14
|
+
"start" => :start, "s" => :start,
|
15
|
+
"end" => :end, "e" => :end,
|
16
|
+
"list" => :list, "l" => :list,
|
17
|
+
"help" => :help, "h" => :help,
|
18
|
+
"exit" => :exit
|
19
|
+
}[command]
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
return commit(user_command.to_i) if command == :commit
|
30
|
-
return bash_command(user_command) if command == :command
|
31
|
-
return :exit if command == :exit
|
32
|
-
self.send(command)
|
22
|
+
def execute(user_command)
|
23
|
+
command = command_for(user_command)
|
24
|
+
if command.nil?
|
25
|
+
puts "I canny understand ye, gonna try again"
|
26
|
+
return
|
33
27
|
end
|
28
|
+
return commit(user_command.to_i) if command == :commit
|
29
|
+
return bash_command(user_command) if command == :command
|
30
|
+
self.send(command)
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def bash_command(user_command)
|
34
|
+
puts `#{user_command[1..-1]}`
|
35
|
+
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
def status_line
|
38
|
+
"#{position+1}/#{total_slides} >"
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
def exit
|
42
|
+
`git checkout -q master`
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
def position
|
46
|
+
slides.index(@current_slide)
|
47
|
+
end
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
49
|
+
def total_slides
|
50
|
+
@slides.length
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
|
53
|
+
def start
|
54
|
+
@current_slide = slides.first
|
55
|
+
@current_slide.execute
|
56
|
+
end
|
57
|
+
|
58
|
+
def help
|
59
|
+
<<-EOH
|
58
60
|
Git Presenter Reference
|
59
61
|
|
60
62
|
next/n: move to next slide
|
@@ -66,39 +68,37 @@ help/h: display this message
|
|
66
68
|
!(exclimation mark): execute following in terminal
|
67
69
|
exit: exit from the presentation
|
68
70
|
EOH
|
69
|
-
|
70
|
-
|
71
|
-
def end
|
72
|
-
@current_slide = slides.last
|
73
|
-
@current_slide.execute
|
74
|
-
end
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
def end
|
74
|
+
@current_slide = slides.last
|
75
|
+
@current_slide.execute
|
76
|
+
end
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
78
|
+
def commit(slide_number)
|
79
|
+
@current_slide = slides[slide_number - 1]
|
80
|
+
@current_slide.execute
|
81
|
+
end
|
86
82
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
def next
|
84
|
+
return if position.nil?
|
85
|
+
@current_slide = slides[position + 1] || @current_slide
|
86
|
+
@current_slide.execute
|
87
|
+
end
|
92
88
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
slide
|
99
|
-
end
|
100
|
-
end.join("\n")
|
101
|
-
end
|
89
|
+
def previous
|
90
|
+
return @current_slide if position == 0
|
91
|
+
@current_slide = slides[position - 1]
|
92
|
+
@current_slide.execute
|
93
|
+
end
|
102
94
|
|
95
|
+
def list
|
96
|
+
@slides.map do |slide|
|
97
|
+
if slide == @current_slide
|
98
|
+
"*#{slide}"
|
99
|
+
else
|
100
|
+
slide
|
101
|
+
end
|
102
|
+
end.join("\n")
|
103
103
|
end
|
104
104
|
end
|
data/lib/git_presenter/slide.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_reader :commit, :message, :run
|
1
|
+
class GitPresenter::Slide
|
2
|
+
attr_reader :commit, :message, :run
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
def initialize(slide)
|
5
|
+
@commit = slide["commit"]
|
6
|
+
@message = slide["message"]
|
7
|
+
@run = slide["run"]
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def execute
|
11
|
+
output = ""
|
12
|
+
output << checkout unless @commit.nil?
|
13
|
+
output << `#{run}` unless @run.nil?
|
14
|
+
output
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def to_s
|
18
|
+
return "#{@commit[0..9]}, #{@message}" unless @commit.nil?
|
19
|
+
"run: #{@run}"
|
20
|
+
end
|
22
21
|
|
23
|
-
|
22
|
+
private
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
24
|
+
def checkout
|
25
|
+
`git checkout -q . `
|
26
|
+
`git checkout -q #{@commit}`
|
27
|
+
@message + "\n"
|
30
28
|
end
|
31
29
|
end
|
data/lib/git_presenter.rb
CHANGED
@@ -1,19 +1,40 @@
|
|
1
1
|
require "grit"
|
2
2
|
require "yaml"
|
3
|
+
require "readline"
|
3
4
|
|
4
|
-
|
5
|
+
class GitPresenter
|
5
6
|
require "git_presenter/presentation"
|
6
|
-
require "git_presenter/
|
7
|
-
require "git_presenter/parser"
|
7
|
+
require "git_presenter/controller"
|
8
8
|
require "git_presenter/slide"
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
10
|
+
def initialize(current_dir, interactive=true)
|
11
|
+
@controller = Controller.new(current_dir)
|
12
|
+
@interactive = interactive
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
15
|
+
def execute(command)
|
16
|
+
if command == "init"
|
17
|
+
@controller.initialise_presentation
|
18
|
+
elsif command == "start"
|
19
|
+
@presentation = @controller.start_presentation
|
20
|
+
if @interactive
|
21
|
+
enter_run_loop
|
22
|
+
end
|
23
|
+
elsif command == "update"
|
24
|
+
@controller.update_presentation
|
25
|
+
else
|
26
|
+
puts @presentation.execute(command)
|
27
|
+
end
|
28
|
+
@presentation
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def enter_run_loop
|
34
|
+
while command = Readline.readline(@presentation.status_line, true)
|
35
|
+
result = @presentation.execute(command)
|
36
|
+
exit if result == :exit
|
37
|
+
puts result
|
38
|
+
end
|
18
39
|
end
|
19
40
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "presentation should parse all commits for a repo" do
|
4
|
+
before do
|
5
|
+
@helper = GitHelper.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should parse more than 10 commits" do
|
9
|
+
@helper.initialise_presentation({:no_of_commits => 13}) do |commits, yaml|
|
10
|
+
yaml["slides"].length.should eql 13
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -27,13 +27,13 @@ describe "initializing a presentation" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "first line should contain the first commit number" do
|
30
|
-
@helper.initialise_presentation(true) do |commits, yaml|
|
30
|
+
@helper.initialise_presentation({:delay => true}) do |commits, yaml|
|
31
31
|
yaml["slides"][0]["slide"]["commit"].should eql commits.first.id
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
it "second line should contain the second commit number" do
|
36
|
-
@helper.initialise_presentation(true) do |commits, yaml|
|
36
|
+
@helper.initialise_presentation({:delay => true}) do |commits, yaml|
|
37
37
|
yaml["slides"][1]["slide"]["commit"].should eql commits[1].id
|
38
38
|
end
|
39
39
|
end
|
@@ -158,7 +158,18 @@ EOH
|
|
158
158
|
command_line_helper = CommandLineHelper.capture_output
|
159
159
|
@helper.start_presentation do |commits, presenter|
|
160
160
|
presenter.execute("!echo hello world")
|
161
|
-
command_line_helper.command_output.strip.should
|
161
|
+
command_line_helper.command_output.strip.should end_with "hello world"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when exiting a presentation" do
|
167
|
+
it "should set the repo back to the master branch" do
|
168
|
+
@helper.start_presentation do |commits, presenter|
|
169
|
+
presenter.execute("next")
|
170
|
+
presenter.execute("exit")
|
171
|
+
@helper.current_branch.should_not be_nil
|
172
|
+
@helper.current_branch.name.should eql "master"
|
162
173
|
end
|
163
174
|
end
|
164
175
|
end
|
@@ -11,8 +11,9 @@ describe "starting a presentation" do
|
|
11
11
|
@helper.initialise_presentation
|
12
12
|
@helper.add_command("echo hello world")
|
13
13
|
Dir.chdir(presentation_dir) do
|
14
|
-
presenter = GitPresenter.
|
15
|
-
presenter.
|
14
|
+
presenter = GitPresenter.new(".", false)
|
15
|
+
presentation = presenter.execute('start')
|
16
|
+
presentation.slides.length.should eql 4
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "update presentation with any new commits" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@helper = GitHelper.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add the new commits to the presentation" do
|
10
|
+
commits = @helper.initialise_presentation({:delay => true})
|
11
|
+
new_commit = @helper.edit_file_and_commit("forth commit", "d")
|
12
|
+
@helper.update_presentation do |yaml|
|
13
|
+
yaml["slides"].length.should eql (commits.length + 1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should add the new commits to the end of the presentation" do
|
18
|
+
commits = @helper.initialise_presentation({:delay => true})
|
19
|
+
new_commit = @helper.edit_file_and_commit("forth commit", "d")
|
20
|
+
@helper.update_presentation do |yaml|
|
21
|
+
yaml["slides"].last["slide"]["commit"].should eql new_commit.id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not contain any commits that have been removed in the middle of the presentation" do
|
26
|
+
commits = @helper.initialise_presentation({:delay => true})
|
27
|
+
removed_commit = @helper.remove_from_presentation_at(1)
|
28
|
+
new_commit = @helper.edit_file_and_commit("forth commit", "d")
|
29
|
+
@helper.update_presentation do |yaml|
|
30
|
+
yaml["slides"].length.should eql (commits.length)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should tell inform the user the presentation has been updated" do
|
35
|
+
commits = @helper.initialise_presentation({:delay => true})
|
36
|
+
removed_commit = @helper.remove_from_presentation_at(1)
|
37
|
+
new_commit = @helper.edit_file_and_commit("forth commit", "d")
|
38
|
+
@helper.update_presentation
|
39
|
+
@command_line.command_output.should include "Your presentation has been updated"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'pry'
|
2
3
|
require "support/git_helpers"
|
3
4
|
require "support/command_line_helper"
|
4
5
|
require_relative "../lib/git_presenter"
|
6
|
+
require 'pry'
|
5
7
|
|
6
8
|
RSpec.configure do |config|
|
9
|
+
config.before(:each) do
|
10
|
+
@command_line = CommandLineHelper.capture_output
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
data/spec/support/git_helpers.rb
CHANGED
@@ -5,28 +5,26 @@ class GitHelper
|
|
5
5
|
PRESENTATION_DIR
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(presentation_dir)
|
8
|
+
def initialize(presentation_dir=GitHelper::PRESENTATION_DIR)
|
9
9
|
@presentation_dir = presentation_dir
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialise_test_repo(presentation_dir, delay)
|
12
|
+
def initialise_test_repo(presentation_dir, delay, no_of_commits)
|
13
13
|
clean_up_repo(presentation_dir)
|
14
14
|
@code_file = "a_file.rb"
|
15
15
|
commits = []
|
16
|
+
content = ('a'..'z').to_a
|
16
17
|
Dir.mkdir(presentation_dir)
|
17
18
|
Dir.chdir(presentation_dir) do
|
18
19
|
@git_repo = Grit::Repo.init(".")
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
sleep 1 if delay
|
28
|
-
edit_file_and_commit("third commit", "c")
|
29
|
-
commits << @git_repo.commits[0]
|
20
|
+
(1..no_of_commits).each do |n|
|
21
|
+
edit_file_and_commit("commit number #{n}", content[n])
|
22
|
+
commits << @git_repo.commits[0]
|
23
|
+
#need to make it sleep for a second.
|
24
|
+
#git is not accurate enough with the speed of the test
|
25
|
+
#to sort correctly only when required
|
26
|
+
sleep 1 if delay
|
27
|
+
end
|
30
28
|
end
|
31
29
|
commits
|
32
30
|
end
|
@@ -42,6 +40,7 @@ class GitHelper
|
|
42
40
|
edit_file(content)
|
43
41
|
@git_repo.add(".")
|
44
42
|
@git_repo.commit_all(commit_message)
|
43
|
+
@git_repo.commits[0]
|
45
44
|
end
|
46
45
|
|
47
46
|
def setup_presentation_file(commits)
|
@@ -60,10 +59,12 @@ class GitHelper
|
|
60
59
|
File.open(@presentation_dir + '/.git/HEAD').lines.first.strip
|
61
60
|
end
|
62
61
|
|
63
|
-
def initialise_presentation(
|
64
|
-
|
62
|
+
def initialise_presentation(params={})
|
63
|
+
settings = {:no_of_commits => 3, :delay => false}.merge(params)
|
64
|
+
commits = initialise_test_repo(@presentation_dir, settings[:delay], settings[:no_of_commits])
|
65
65
|
Dir.chdir(@presentation_dir) do
|
66
|
-
|
66
|
+
presentation = GitPresenter.new(@presentation_dir, false)
|
67
|
+
git_presentation = presentation.execute("init")
|
67
68
|
yaml = YAML::parse(File.open(File.join(@presentation_dir, ".presentation"))).to_ruby
|
68
69
|
yield(commits, yaml) if block_given?
|
69
70
|
end
|
@@ -71,14 +72,36 @@ class GitHelper
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def start_presentation(command="", add_command_to_commit=nil)
|
74
|
-
commits = initialise_presentation(true)
|
75
|
+
commits = initialise_presentation({:delay => true})
|
75
76
|
Dir.chdir(@presentation_dir) do
|
76
77
|
add_command(command, add_command_to_commit) unless command.empty?
|
77
|
-
presenter = GitPresenter.
|
78
|
+
presenter = GitPresenter.new('.', false)
|
79
|
+
presenter = presenter.execute('start')
|
78
80
|
yield(commits, presenter) if block_given?
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
84
|
+
def update_presentation
|
85
|
+
Dir.chdir(@presentation_dir) do
|
86
|
+
presentation = GitPresenter.new(@presentation_dir, false)
|
87
|
+
presentation.execute("update")
|
88
|
+
yaml = YAML::parse(File.open(File.join(@presentation_dir, ".presentation"))).to_ruby
|
89
|
+
yield(yaml) if block_given?
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def remove_from_presentation_at(index)
|
94
|
+
removed_commit = nil
|
95
|
+
Dir.chdir(@presentation_dir) do
|
96
|
+
yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
|
97
|
+
removed_commit = yaml['slides'].delete_at(index)
|
98
|
+
File.open(File.open(File.join(@presentation_dir, ".presentation")), "w") do |file|
|
99
|
+
file.write(yaml.to_yaml)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
removed_commit
|
103
|
+
end
|
104
|
+
|
82
105
|
def add_command(command, add_command_to_commit=nil)
|
83
106
|
Dir.chdir(PRESENTATION_DIR) do
|
84
107
|
presentation = YAML.parse(File.open(".presentation")).to_ruby
|
@@ -92,4 +115,12 @@ class GitHelper
|
|
92
115
|
end
|
93
116
|
end
|
94
117
|
end
|
118
|
+
|
119
|
+
def current_branch
|
120
|
+
Dir.chdir(PRESENTATION_DIR) do
|
121
|
+
repo = Grit::Repo.init('.')
|
122
|
+
repo.head
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
95
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|
16
|
-
requirement: &
|
16
|
+
requirement: &70193289098420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: '2.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70193289098420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: pry
|
27
|
+
requirement: &70193289097940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70193289097940
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &70193289097460 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ~>
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '2.7'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70193289097460
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: bundler
|
38
|
-
requirement: &
|
49
|
+
requirement: &70193289096980 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70193289096980
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: jeweler
|
49
|
-
requirement: &
|
60
|
+
requirement: &70193289096500 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '1.6'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70193289096500
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rcov
|
60
|
-
requirement: &
|
71
|
+
requirement: &70193289096020 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,7 +76,18 @@ dependencies:
|
|
65
76
|
version: '0.9'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70193289096020
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: pry
|
82
|
+
requirement: &70193289095540 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70193289095540
|
69
91
|
description: Code presentation tool using git
|
70
92
|
email: pythonandchips@gmail.com
|
71
93
|
executables:
|
@@ -86,16 +108,17 @@ files:
|
|
86
108
|
- bin/git-presenter
|
87
109
|
- git_presenter.gemspec
|
88
110
|
- lib/git_presenter.rb
|
89
|
-
- lib/git_presenter/
|
111
|
+
- lib/git_presenter/controller.rb
|
90
112
|
- lib/git_presenter/presentation.rb
|
91
113
|
- lib/git_presenter/slide.rb
|
92
|
-
-
|
114
|
+
- spec/bugs/max_10_commits_being_parsed_spec.rb
|
93
115
|
- spec/integration/initialize_presentation_spec.rb
|
94
116
|
- spec/integration/moving_through_presentation_spec.rb
|
95
117
|
- spec/integration/start_presentation_spec.rb
|
118
|
+
- spec/integration/update_presentation_spec.rb
|
119
|
+
- spec/lib/git_presenter/controller_spec.rb
|
96
120
|
- spec/lib/git_presenter/presentation_spec.rb
|
97
121
|
- spec/lib/git_presenter/slide_spec.rb
|
98
|
-
- spec/lib/git_presenter/writer_spec.rb
|
99
122
|
- spec/spec_helper.rb
|
100
123
|
- spec/support/command_line_helper.rb
|
101
124
|
- spec/support/git_helpers.rb
|
@@ -114,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
137
|
version: '0'
|
115
138
|
segments:
|
116
139
|
- 0
|
117
|
-
hash:
|
140
|
+
hash: 2611368202741633093
|
118
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
142
|
none: false
|
120
143
|
requirements:
|
data/lib/git_presenter/parser.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module GitPresenter
|
2
|
-
class Parser
|
3
|
-
def initialize(presentation_dir)
|
4
|
-
@presentation_dir = presentation_dir
|
5
|
-
end
|
6
|
-
|
7
|
-
def presentation
|
8
|
-
presenter = nil
|
9
|
-
yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
|
10
|
-
presenter = GitPresenter::Presentation.new(yaml)
|
11
|
-
presenter.start
|
12
|
-
presenter
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
data/lib/git_presenter/writer.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module GitPresenter
|
2
|
-
class Writer
|
3
|
-
CONFIG_FILE = ".presentation"
|
4
|
-
|
5
|
-
def initialize(file_path)
|
6
|
-
@presentation_dir = file_path
|
7
|
-
end
|
8
|
-
|
9
|
-
def output_presenatation_file
|
10
|
-
yaml = {"slides" => create_slides}.to_yaml
|
11
|
-
File.open(presentation_file_location, "w") do |file|
|
12
|
-
file.write(yaml)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def presentation_file_location
|
19
|
-
File.join(@presentation_dir, CONFIG_FILE)
|
20
|
-
end
|
21
|
-
|
22
|
-
def create_slides
|
23
|
-
repo = Grit::Repo.new(".", "master")
|
24
|
-
repo.commits.reverse.map do |commit|
|
25
|
-
{"slide" =>
|
26
|
-
{"commit" => commit.id,
|
27
|
-
"message" => commit.message}
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|