Sha256: f77bb682af5c633163c3b78b2394e6b390c74513c8a32434e49ae915352c52b7

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

class GitPresenter::Controller
  CONFIG_FILE = ".presentation"

  def initialize(file_path)
    @presentation_dir = file_path
  end

  def initialise_presentation
    yaml = {"slides" => create_slides}.to_yaml
    File.open(presentation_file_location, "w") do |file|
      file.write(yaml)
    end
    puts "Presentation has been initalised"
    puts "run 'git-presenter start' to begin the presentation"
  end

  def start_presentation
    yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
    presenter = GitPresenter::Presentation.new(yaml)
    puts presenter.start
    presenter
  end

  def update_presentation
    yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
    slides = create_slides(yaml['slides'].last["slide"]["commit"])
    last_commit = yaml["slides"].last
    yaml["slides"] = yaml["slides"] + slides
    yaml["slides"].uniq!
    write_file(yaml.to_yaml)
    puts "Your presentation has been updated"
  end

  private

  def write_file(yaml)
    File.open(presentation_file_location, "w") do |file|
      file.write(yaml)
    end
  end

  def presentation_file_location
    File.join(@presentation_dir, CONFIG_FILE)
  end

  def create_slides(last_commit=nil)
    repo = Git.open(".")
    commits = repo.log.to_a.reverse
    commits = commits.drop_while{|commit| commit.sha != last_commit}[1..-1] unless last_commit.nil?
    commits.map do |commit|
      {"slide" =>
         {"commit"  => commit.sha,
         "message" => commit.message}
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_presenter-1.0.0 lib/git_presenter/controller.rb