class GitPresenter::Presentation

Attributes

current_slide[R]
slides[R]

Public Class Methods

new(presentation, shell=GitPresenter::Shell.new) click to toggle source
# File lib/git_presenter/presentation.rb, line 4
def initialize(presentation, shell=GitPresenter::Shell.new)
  @branch = presentation["branch"]
  @slides = presentation["slides"].map{|slide| GitPresenter::Slide.new(slide["slide"])}
  @shell = shell
  @current_slide = find_current_slide
end

Public Instance Methods

bash_command(user_command) click to toggle source
# File lib/git_presenter/presentation.rb, line 40
def bash_command(user_command)
  puts `#{user_command[1..-1]}`
end
command_for(command) click to toggle source
# File lib/git_presenter/presentation.rb, line 16
def command_for(command)
  return :commit if command =~ /^[0-9]+$/
  return :command if command[0] == "!"
  {"n" => :next, "next" => :next,
   "back" => :previous, "b" => :previous,
   "start" => :start, "s" => :start,
   "end" => :end, "e" => :end,
   "list" => :list, "l" => :list,
   "help" => :help, "h" => :help,
   "exit" => :exit
  }[command]
end
commit(slide_number) click to toggle source
# File lib/git_presenter/presentation.rb, line 86
def commit(slide_number)
  @current_slide = slides[slide_number - 1]
  @current_slide.execute
end
end() click to toggle source
# File lib/git_presenter/presentation.rb, line 81
def end
  @current_slide = slides.last
  @current_slide.execute
end
execute(user_command) click to toggle source
# File lib/git_presenter/presentation.rb, line 29
def execute(user_command)
  command = command_for(user_command)
  if command.nil?
    puts "I canny understand ye, gonna try again"
    return
  end
  return commit(user_command.to_i) if command == :commit
  return bash_command(user_command) if command == :command
  self.send(command)
end
exit() click to toggle source
# File lib/git_presenter/presentation.rb, line 48
def exit
  `git checkout -q #{@branch}`
  :exit
end
find_current_slide() click to toggle source
# File lib/git_presenter/presentation.rb, line 11
def find_current_slide
  sha = @shell.run("git rev-parse HEAD").strip
  @slides.detect{|s| s.commit == sha}
end
help() click to toggle source
# File lib/git_presenter/presentation.rb, line 66
  def help
    <<-EOH
Git Presenter Reference

next/n: move to next slide
back/b: move back a slide
end/e:  move to end of presentation
start/s: move to start of presentation
list/l : list slides in presentation
help/h: display this message
!(exclimation mark): execute following in terminal
exit: exit from the presentation
EOH
  end
list() click to toggle source
# File lib/git_presenter/presentation.rb, line 103
def list
  @slides.map do |slide|
    if slide == @current_slide
      "*#{slide}"
    else
      slide
    end
  end.join("\n")
end
next() click to toggle source
# File lib/git_presenter/presentation.rb, line 91
def next
  return if position.nil?
  @current_slide = slides[position + 1] || @current_slide
  @current_slide.execute
end
position() click to toggle source
# File lib/git_presenter/presentation.rb, line 53
def position
  @slides.index(@current_slide)
end
previous() click to toggle source
# File lib/git_presenter/presentation.rb, line 97
def previous
  return @current_slide if position == 0
  @current_slide = slides[position - 1]
  @current_slide.execute
end
start() click to toggle source
# File lib/git_presenter/presentation.rb, line 61
def start
  @current_slide = slides.first
  @current_slide.execute
end
status_line() click to toggle source
# File lib/git_presenter/presentation.rb, line 44
def status_line
  "#{position+1}/#{total_slides} >"
end
total_slides() click to toggle source
# File lib/git_presenter/presentation.rb, line 57
def total_slides
  @slides.length
end