lib/git_presenter/presentation.rb in git_presenter-1.1.0 vs lib/git_presenter/presentation.rb in git_presenter-1.2.0
- old
+ new
@@ -1,14 +1,20 @@
class GitPresenter::Presentation
attr_reader :slides, :current_slide
- def initialize(presentation)
+ def initialize(presentation, shell=GitPresenter::Shell.new)
@branch = presentation["branch"]
@slides = presentation["slides"].map{|slide| GitPresenter::Slide.new(slide["slide"])}
- @current_slide = slides.first
+ @shell = shell
+ @current_slide = find_current_slide
end
+ def find_current_slide
+ sha = @shell.run("git rev-parse HEAD").strip
+ @slides.detect{|s| s.commit == sha}
+ end
+
def command_for(command)
return :commit if command =~ /^[0-9]+$/
return :command if command[0] == "!"
{"n" => :next, "next" => :next,
"back" => :previous, "b" => :previous,
@@ -43,10 +49,10 @@
`git checkout -q #{@branch}`
:exit
end
def position
- slides.index(@current_slide)
+ @slides.index(@current_slide)
end
def total_slides
@slides.length
end