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 CHANGED
@@ -2,4 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - jruby-19mode # JRuby in 1.9 mode
5
+ # - jruby-19mode # JRuby in 1.9 mode
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.4.1)
7
+ grit (2.5.0)
7
8
  diff-lcs (~> 1.1)
8
9
  mime-types (~> 1.15)
9
- jeweler (1.6.4)
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
- mime-types (1.17.2)
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
- rspec (2.7.0)
17
- rspec-core (~> 2.7.0)
18
- rspec-expectations (~> 2.7.0)
19
- rspec-mocks (~> 2.7.0)
20
- rspec-core (2.7.1)
21
- rspec-expectations (2.7.0)
22
- diff-lcs (~> 1.1.2)
23
- rspec-mocks (2.7.0)
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 or jruby in 1.9 mode (basically anything with 1.9 at the end)
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.2.2
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
- if ARGV[0] == "init"
10
- GitPresenter.initialise_presentation(Dir.pwd)
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])
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "git_presenter"
8
- s.version = "0.2.2"
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-04-17"
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/parser.rb",
32
+ "lib/git_presenter/controller.rb",
33
33
  "lib/git_presenter/presentation.rb",
34
34
  "lib/git_presenter/slide.rb",
35
- "lib/git_presenter/writer.rb",
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
- module GitPresenter
2
- class Presentation
3
- attr_reader :slides, :current_slide
1
+ class GitPresenter::Presentation
2
+ attr_reader :slides, :current_slide
4
3
 
5
- def initialize(presentation)
6
- @slides = presentation["slides"].map{|slide| Slide.new(slide["slide"])}
7
- @current_slide = slides.first
8
- end
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
- def command_for(command)
11
- return :commit if command =~ /^[0-9]+$/
12
- return :command if command[0] == "!"
13
- {"n" => :next, "next" => :next,
14
- "back" => :previous, "b" => :previous,
15
- "start" => :start, "s" => :start,
16
- "end" => :end, "e" => :end,
17
- "list" => :list, "l" => :list,
18
- "help" => :help, "h" => :help,
19
- "exit" => :exit
20
- }[command]
21
- end
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
- def execute(user_command)
24
- command = command_for(user_command)
25
- if command.nil?
26
- puts "I canny understand ye, gonna try again"
27
- return
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
- def bash_command(user_command)
36
- puts `#{user_command[1..-1]}`
37
- end
33
+ def bash_command(user_command)
34
+ puts `#{user_command[1..-1]}`
35
+ end
38
36
 
39
- def status_line
40
- "#{position+1}/#{total_slides} >"
41
- end
37
+ def status_line
38
+ "#{position+1}/#{total_slides} >"
39
+ end
42
40
 
43
- def position
44
- slides.index(@current_slide)
45
- end
41
+ def exit
42
+ `git checkout -q master`
43
+ end
46
44
 
47
- def total_slides
48
- @slides.length
49
- end
45
+ def position
46
+ slides.index(@current_slide)
47
+ end
50
48
 
51
- def start
52
- @current_slide = slides.first
53
- @current_slide.execute
54
- end
49
+ def total_slides
50
+ @slides.length
51
+ end
55
52
 
56
- def help
57
- <<-EOH
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
- end
70
-
71
- def end
72
- @current_slide = slides.last
73
- @current_slide.execute
74
- end
71
+ end
75
72
 
76
- def commit(slide_number)
77
- @current_slide = slides[slide_number - 1]
78
- @current_slide.execute
79
- end
73
+ def end
74
+ @current_slide = slides.last
75
+ @current_slide.execute
76
+ end
80
77
 
81
- def next
82
- return if position.nil?
83
- @current_slide = slides[position + 1] || @current_slide
84
- @current_slide.execute
85
- end
78
+ def commit(slide_number)
79
+ @current_slide = slides[slide_number - 1]
80
+ @current_slide.execute
81
+ end
86
82
 
87
- def previous
88
- return @current_slide if position == 0
89
- @current_slide = slides[position - 1]
90
- @current_slide.execute
91
- end
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
- def list
94
- @slides.map do |slide|
95
- if slide == @current_slide
96
- "*#{slide}"
97
- else
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
@@ -1,31 +1,29 @@
1
- module GitPresenter
2
- class Slide
3
- attr_reader :commit, :message, :run
1
+ class GitPresenter::Slide
2
+ attr_reader :commit, :message, :run
4
3
 
5
- def initialize(slide)
6
- @commit = slide["commit"]
7
- @message = slide["message"]
8
- @run = slide["run"]
9
- end
4
+ def initialize(slide)
5
+ @commit = slide["commit"]
6
+ @message = slide["message"]
7
+ @run = slide["run"]
8
+ end
10
9
 
11
- def execute
12
- output = ""
13
- output << checkout unless @commit.nil?
14
- output << `#{run}` unless @run.nil?
15
- output
16
- end
10
+ def execute
11
+ output = ""
12
+ output << checkout unless @commit.nil?
13
+ output << `#{run}` unless @run.nil?
14
+ output
15
+ end
17
16
 
18
- def to_s
19
- return "#{@commit[0..9]}, #{@message}" unless @commit.nil?
20
- "run: #{@run}"
21
- end
17
+ def to_s
18
+ return "#{@commit[0..9]}, #{@message}" unless @commit.nil?
19
+ "run: #{@run}"
20
+ end
22
21
 
23
- private
22
+ private
24
23
 
25
- def checkout
26
- `git checkout -q . `
27
- `git checkout -q #{@commit}`
28
- @message + "\n"
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
- module GitPresenter
5
+ class GitPresenter
5
6
  require "git_presenter/presentation"
6
- require "git_presenter/writer"
7
- require "git_presenter/parser"
7
+ require "git_presenter/controller"
8
8
  require "git_presenter/slide"
9
9
 
10
- def self.initialise_presentation dir
11
- builder = Writer.new(dir)
12
- builder.output_presenatation_file
10
+ def initialize(current_dir, interactive=true)
11
+ @controller = Controller.new(current_dir)
12
+ @interactive = interactive
13
13
  end
14
14
 
15
- def self.start_presentation dir
16
- parser = Parser.new(dir)
17
- parser.presentation
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 eql "hello world"
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.start_presentation(".")
15
- presenter.slides.length.should eql 4
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
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe GitPresenter::Controller do
4
+ 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
 
@@ -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
- edit_file_and_commit("initial commit", "a")
20
- commits << @git_repo.commits[0]
21
- #need to make it sleep for a second.
22
- #git is not accurate enough with the speed of the test
23
- #to sort correctly
24
- sleep 1 if delay
25
- edit_file_and_commit("second commit", "b")
26
- commits << @git_repo.commits[0]
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(delay=false)
64
- commits = initialise_test_repo(@presentation_dir, delay)
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
- git_presentation = GitPresenter.initialise_presentation(".")
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.start_presentation(".")
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.2.2
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-04-17 00:00:00.000000000 Z
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: &70104411025040 !ruby/object:Gem::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: *70104411025040
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: &70104411024120 !ruby/object:Gem::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: *70104411024120
46
+ version_requirements: *70193289097460
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: bundler
38
- requirement: &70104411023420 !ruby/object:Gem::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: *70104411023420
57
+ version_requirements: *70193289096980
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: jeweler
49
- requirement: &70104411021140 !ruby/object:Gem::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: *70104411021140
68
+ version_requirements: *70193289096500
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rcov
60
- requirement: &70104411062300 !ruby/object:Gem::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: *70104411062300
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/parser.rb
111
+ - lib/git_presenter/controller.rb
90
112
  - lib/git_presenter/presentation.rb
91
113
  - lib/git_presenter/slide.rb
92
- - lib/git_presenter/writer.rb
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: 2111319268477866572
140
+ hash: 2611368202741633093
118
141
  required_rubygems_version: !ruby/object:Gem::Requirement
119
142
  none: false
120
143
  requirements:
@@ -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
@@ -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
@@ -1,4 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe GitPresenter::Writer do
4
- end