royw-git_shoes 0.0.0 → 0.0.1

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/Rakefile CHANGED
@@ -20,6 +20,7 @@ require 'spec/rake/spectask'
20
20
  Spec::Rake::SpecTask.new(:spec) do |spec|
21
21
  spec.libs << 'lib' << 'spec'
22
22
  spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ spec.spec_opts = ["--color", "--format nested"]
23
24
  end
24
25
 
25
26
  Spec::Rake::SpecTask.new(:rcov) do |spec|
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
3
- :major: 0
4
2
  :minor: 0
3
+ :patch: 1
4
+ :major: 0
@@ -18,6 +18,10 @@ class Controller
18
18
  REVERSE_DATE = 'Oldest First'
19
19
  SORT_NAMES = [NAME, REVERSE_NAME, DATE, REVERSE_DATE]
20
20
 
21
+ class << self
22
+ attr_accessor :selected_item
23
+ end
24
+
21
25
  # current working directory
22
26
  def self.cwd
23
27
  Directory.cwd
@@ -74,7 +78,7 @@ class Controller
74
78
  def self.files(&blk)
75
79
  items = Directory.contents.collect do |item|
76
80
  item.options[:click] = lambda {Controller.chdir(item.path); blk.call(nil)} if item.directory?
77
- item.options[:click] = lambda {blk.call(item.path)} if item.file?
81
+ item.options[:click] = lambda {blk.call(item)} if item.file?
78
82
  item
79
83
  end
80
84
  # puts "files items => #{items.inspect}"
data/lib/loader.rb CHANGED
@@ -5,15 +5,18 @@ require 'logger'
5
5
  require 'singleton'
6
6
  # require 'ruby-debug'
7
7
 
8
- require 'logger_facade'
9
-
10
- require 'models/git_helper'
11
- require 'models/directory'
12
- require 'models/dir_item'
13
-
8
+ # a few classes have to be loaded before the rest
9
+ require 'views/nav'
14
10
  require 'views/bullet_list'
11
+ require 'views/widget'
15
12
  require 'views/action'
16
- require 'views/dir_action'
17
13
 
18
- require 'controllers/controller'
14
+ # require all *.rb files under lib
15
+ Dir.glob("lib/**/*.rb").select{|f| f =~ /^lib\//}.each do |filespec|
16
+ file = filespec.gsub(/\.rb$/, '').gsub(/^lib\//, '')
17
+ unless file == 'loader'
18
+ # puts "require #{file}"
19
+ require file
20
+ end
21
+ end
19
22
 
data/lib/views/action.rb CHANGED
@@ -3,8 +3,27 @@ class Action
3
3
 
4
4
  attr_accessor :app
5
5
 
6
+ def initialize
7
+ @command_widget = CommandWidget.new
8
+ @title_widget = TitleWidget.new
9
+ @page_widget = PageWidget.new
10
+ end
11
+
6
12
  def execute(obj=nil)
7
13
 
8
14
  end
9
15
 
16
+ def page_layout(&blk)
17
+ @page_widget.app = app
18
+ @page_widget.show
19
+
20
+ app.flow(:width => '100%') do
21
+ @title_widget.app = app
22
+ @title_widget.show
23
+ @command_widget.app = app
24
+ @command_widget.show(:width => 100)
25
+ blk.call unless blk.nil?
26
+ end
27
+ end
28
+
10
29
  end
@@ -0,0 +1,49 @@
1
+ class CommandWidget < Widget
2
+ include Nav
3
+
4
+ def show(opt={})
5
+ dir_item = Controller.selected_item
6
+ app.stack(opt) do
7
+ app.background app.gradient(app.rgb(0, 255, 0), app.rgb(255, 255, 0), :angle => -35)
8
+ app.para app.link("Files", :click => lambda{app.visit(DIR_PAGE)})
9
+ app.rect(5, 30, 90, 1)
10
+ if Controller.in_repository?
11
+ app.para app.link("Status", :click => lambda{app.visit(STATUS_PAGE)})
12
+ if !dir_item.nil? && (dir_item.modified? || dir_item.candidate?)
13
+ app.para app.link("Add", :click => lambda{add_action})
14
+ else
15
+ app.para "Add"
16
+ end
17
+ if !dir_item.nil? && dir_item.modified?
18
+ app.para app.link("Diff", :click => lambda{diff_action})
19
+ else
20
+ app.para "Diff"
21
+ end
22
+ app.para app.link("Commit", :click => lambda{commit_action})
23
+ app.para "Config"
24
+ else
25
+ # app.para 'Status'
26
+ # app.para "Diff"
27
+ # app.para "Commit"
28
+ # app.para "Branch"
29
+ # app.para "Config"
30
+ end
31
+ end
32
+ end
33
+
34
+ def add_action
35
+ # TODO implement
36
+ puts "need to implement add_action"
37
+ end
38
+
39
+ def diff_action
40
+ # TODO implement
41
+ puts "need to implement diff_action"
42
+ end
43
+
44
+ def commit_action
45
+ # TODO implement
46
+ puts "need to implement commit_action"
47
+ end
48
+
49
+ end
@@ -1,217 +1,19 @@
1
1
  class DirAction < Action
2
- include BulletList
3
-
4
- DIR_PAGE = '/'
5
- FILE_PAGE = '/file'
6
- VIEW_AREA_OPTS = {:width => -100, :margin_left => 10, :margin_right => @gutter}
2
+ include Nav
7
3
 
8
4
  def initialize
9
5
  super
10
- @filter_selection = Controller::FILTER_NAMES.first
11
- @sort_selection = Controller::SORT_NAMES.first
6
+ @directory_widget = DirectoryWidget.new
12
7
  end
13
8
 
9
+ def execute()
10
+ info "dir_action.execute"
14
11
 
15
- def execute(filename=nil)
16
- info "dir_action.execute(#{filename})"
17
- dir_item = @values.select{|item| item.path == filename}.first rescue nil
18
- @gutter = app.gutter
19
- app.background app.palegreen
20
- app.style(Shoes::Link, :underline => false, :stroke => app.blue)
21
- app.style(Shoes::LinkHover, :underline => true, :stroke => app.red)
22
-
23
- app.flow(:width => '100%') do
24
- title_stack = app.stack(:width => '100%') do
25
- app.background app.gradient(app.rgb(0, 255, 0), app.rgb(225, 255, 0), :angle => 135)
26
- app.title("Git Shoes", :align => 'center')
27
- end
28
- command_widget(dir_item, :width => 100)
29
- if dir_item.nil?
30
- @view_area = directory_widget(VIEW_AREA_OPTS)
31
- else
32
- @view_area = file_widget(dir_item, VIEW_AREA_OPTS)
33
- end
34
- end
35
- end
36
-
37
- def command_widget(dir_item, opt={})
38
- app.stack(opt) do
39
- app.background app.gradient(app.rgb(0, 255, 0), app.rgb(255, 255, 0), :angle => -35)
40
- app.para app.link("Files", :click => lambda{app.visit(DIR_PAGE)})
41
- app.rect(5, 30, 90, 1)
42
- if Controller.in_repository?
43
- app.para app.link("Status", :click => lambda{status_action})
44
- if !dir_item.nil? && (dir_item.modified? || dir_item.candidate?)
45
- app.para app.link("Add", :click => lambda{add_action})
46
- else
47
- app.para "Add"
48
- end
49
- if !dir_item.nil? && dir_item.modified?
50
- app.para app.link("Diff", :click => lambda{diff_action})
51
- else
52
- app.para "Diff"
53
- end
54
- app.para app.link("Commit", :click => lambda{commit_action})
55
- app.para "Config"
56
- else
57
- # app.para 'Status'
58
- # app.para "Diff"
59
- # app.para "Commit"
60
- # app.para "Branch"
61
- # app.para "Config"
62
- end
12
+ page_layout do
13
+ Controller.selected_item = nil
14
+ @directory_widget.app = app
15
+ @view_area = @directory_widget.show(VIEW_AREA_OPTS)
63
16
  end
64
17
  end
65
18
 
66
- def add_action
67
- # TODO implement
68
- puts "need to implement add_action"
69
- end
70
-
71
- def diff_action
72
- # TODO implement
73
- puts "need to implement diff_action"
74
- end
75
-
76
- def commit_action
77
- # TODO implement
78
- puts "need to implement commit_action"
79
- end
80
-
81
- def status_action
82
- if Controller.in_repository?
83
- @view_area.clear {status_widget(VIEW_AREA_OPTS)}
84
- end
85
- end
86
-
87
- def status_widget(opt={})
88
- app.stack(opt) do
89
- app.para `git status`
90
- app.info app.para.text
91
- end
92
- end
93
-
94
- def file_widget(dir_item, opt={})
95
- app.stack(opt) do
96
- app.para "filename: #{dir_item.path}"
97
- # TODO: everything there is to know about the file ;)
98
- app.para(app.strong('Log'))
99
- app.flow(:height => 200, :margin_right => @gutter, :scroll => true) do
100
- app.background app.turquoise
101
- app.para(dir_item.log)
102
- end
103
- if dir_item.modified?
104
- app.para
105
- app.para(app.strong('Diff'))
106
- app.flow(:height => 200, :margin_right => @gutter, :scroll => true) do
107
- app.background app.turquoise
108
- app.para dir_item.diff
109
- end
110
- end
111
- end
112
- end
113
-
114
- def directory_widget(opt={})
115
- app.stack(opt) do
116
- cwd = Controller.cwd
117
- git_project_dir = Controller.git_project_dir
118
- if git_project_dir.nil?
119
- app.caption("Directory", :align => 'center')
120
- app.para(cwd)
121
- else
122
- repository_widget(cwd, git_project_dir)
123
- end
124
-
125
- file_selection(git_project_dir)
126
- end
127
- end
128
-
129
- def repository_widget(cwd, git_project_dir)
130
- app.caption("Git Repository", :align => 'center')
131
- app.flow do
132
- app.para "Branch: "
133
- @branch_listbox = app.list_box(:items => Controller.branches) do |list|
134
- Controller.branch = list.text
135
- file_selection_changed
136
- end
137
- @branch_listbox.choose(Controller.branch(false))
138
- app.button("New", :margin_left => 10) # TODO Hook it up
139
- app.button("Delete", :margin_left => 10) # TODO Hook it up
140
- app.button("Stash", :margin_left => 10) { Controller.stash }
141
- app.button("Stash Pop", :margin_left => 10) { Controller.stash_pop }
142
- end
143
- app.para("Branch: ", app.strong(Controller.branch(true)))
144
- app.para(app.strong(git_project_dir, app.em(cwd.gsub(git_project_dir, ''))))
145
- buf = []
146
- repository_info = Controller.repository_info
147
- repository_info.each do |key, value|
148
- buf << "#{value} #{key} files"
149
- end
150
- app.para buf.join(", ")
151
- end
152
-
153
- def file_selection(git_project_dir)
154
- app.flow do
155
- app.para 'Filter by: '
156
- if git_project_dir.nil?
157
- filter_items = Controller::FILTER_NAMES
158
- unless filter_items.include?(@filter_selection)
159
- @filter_selection = filter_items.first
160
- end
161
- else
162
- filter_items = Controller::GIT_FILTER_NAMES
163
- end
164
- @filter_by = app.list_box(:items => filter_items) do |list|
165
- file_selection_changed
166
- end
167
- app.para ' Sort by: '
168
- @sort_by = app.list_box(:items => Controller::SORT_NAMES) do |list|
169
- file_selection_changed
170
- end
171
- @listing = app.stack
172
- @filter_by.choose(@filter_selection)
173
- @sort_by.choose(@sort_selection)
174
-
175
- # need to fire a selection changed to get the intial loading of @listing
176
- file_selection_changed
177
- end
178
- end
179
-
180
- def file_selection_changed
181
- @filter_selection = @filter_by.text
182
- @sort_selection = @sort_by.text
183
- @values = Controller.files do |filename|
184
- if filename.nil?
185
- app.visit(DIR_PAGE)
186
- else
187
- app.visit(FILE_PAGE + '/' + filename)
188
- end
189
- end
190
- @values = Controller.filter_by(@filter_by.text, @values)
191
- @values = Controller.sort_by(@sort_by.text, @values)
192
- @listing.clear {bullet_list(@values, :bullet => fs_bullets)}
193
- end
194
-
195
- def fs_bullets
196
- lambda do |item|
197
- if item.path == '..'
198
- bullet = BulletList::SPACE_BULLET
199
- else
200
- if item.directory?
201
- app.fill app.black
202
- bullet = BulletList::PLUS_BULLET
203
- else
204
- if item.modified?
205
- app.fill app.red
206
- elsif item.managed?
207
- app.fill app.lime
208
- else
209
- app.fill app.black
210
- end
211
- bullet = BulletList::CIRCLE_BULLET
212
- end
213
- end
214
- bullet
215
- end
216
- end
217
19
  end
@@ -0,0 +1,94 @@
1
+ class DirectoryWidget < Widget
2
+ include BulletList
3
+ include Nav
4
+
5
+ def initialize
6
+ @filter_selection = Controller::FILTER_NAMES.first
7
+ @sort_selection = Controller::SORT_NAMES.first
8
+ @repository_widget = RepositoryWidget.new
9
+ end
10
+
11
+ def show(opt={})
12
+ app.stack(opt) do
13
+ cwd = Controller.cwd
14
+ git_project_dir = Controller.git_project_dir
15
+ if git_project_dir.nil?
16
+ app.caption("Directory", :align => 'center')
17
+ app.para(cwd)
18
+ else
19
+ @repository_widget.app = app
20
+ @repository_widget.show(cwd, git_project_dir)
21
+ end
22
+
23
+ file_selection(git_project_dir)
24
+ end
25
+ end
26
+
27
+ def file_selection(git_project_dir)
28
+ app.flow do
29
+ app.para 'Filter by: '
30
+ if git_project_dir.nil?
31
+ filter_items = Controller::FILTER_NAMES
32
+ unless filter_items.include?(@filter_selection)
33
+ @filter_selection = filter_items.first
34
+ end
35
+ else
36
+ filter_items = Controller::GIT_FILTER_NAMES
37
+ end
38
+ @filter_by = app.list_box(:items => filter_items) do |list|
39
+ file_selection_changed
40
+ end
41
+ app.para ' Sort by: '
42
+ @sort_by = app.list_box(:items => Controller::SORT_NAMES) do |list|
43
+ file_selection_changed
44
+ end
45
+ @listing = app.stack
46
+ @filter_by.choose(@filter_selection)
47
+ @sort_by.choose(@sort_selection)
48
+
49
+ # need to fire a selection changed to get the intial loading of @listing
50
+ file_selection_changed
51
+ end
52
+ end
53
+
54
+ def file_selection_changed
55
+ @filter_selection = @filter_by.text
56
+ @sort_selection = @sort_by.text
57
+ @values = Controller.files do |item|
58
+ if item.nil? || item.directory?
59
+ Controller.selected_item = nil
60
+ app.visit(DIR_PAGE)
61
+ else
62
+ Controller.selected_item = item
63
+ app.visit(FILE_PAGE)
64
+ end
65
+ end
66
+ @values = Controller.filter_by(@filter_by.text, @values)
67
+ @values = Controller.sort_by(@sort_by.text, @values)
68
+ @listing.clear {bullet_list(@values, :bullet => fs_bullets)}
69
+ end
70
+
71
+ def fs_bullets
72
+ lambda do |item|
73
+ if item.path == '..'
74
+ bullet = BulletList::SPACE_BULLET
75
+ else
76
+ if item.directory?
77
+ app.fill app.black
78
+ bullet = BulletList::PLUS_BULLET
79
+ else
80
+ if item.modified?
81
+ app.fill app.red
82
+ elsif item.managed?
83
+ app.fill app.lime
84
+ else
85
+ app.fill app.black
86
+ end
87
+ bullet = BulletList::CIRCLE_BULLET
88
+ end
89
+ end
90
+ bullet
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,19 @@
1
+ class FileAction < Action
2
+ include BulletList
3
+ include Nav
4
+
5
+ def initialize
6
+ super
7
+ @file_widget = FileWidget.new
8
+ end
9
+
10
+ def execute()
11
+ info "file_action.execute"
12
+
13
+ page_layout do
14
+ @file_widget.app = app
15
+ @view_area = @file_widget.show(VIEW_AREA_OPTS)
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,26 @@
1
+ class FileWidget < Widget
2
+
3
+ def show(opt={})
4
+ dir_item = Controller.selected_item
5
+ app.stack(opt) do
6
+ unless dir_item.nil?
7
+ app.para "filename: #{dir_item.path}"
8
+ # TODO: everything there is to know about the file ;)
9
+ if dir_item.modified?
10
+ app.para(app.strong('Diff'))
11
+ app.flow(:height => 200, :margin_right => @gutter, :scroll => true) do
12
+ app.background app.turquoise
13
+ app.para dir_item.diff
14
+ end
15
+ app.para
16
+ end
17
+ app.para(app.strong('Log'))
18
+ app.flow(:height => 200, :margin_right => @gutter, :scroll => true) do
19
+ app.background app.turquoise
20
+ app.para(dir_item.log)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ end
data/lib/views/nav.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Nav
2
+ INDEX_PAGE = '/'
3
+ DIR_PAGE = '/'
4
+ FILE_PAGE = '/file'
5
+ STATUS_PAGE = '/status'
6
+
7
+ VIEW_AREA_OPTS = {:width => -100, :margin_left => 10, :margin_right => @gutter}
8
+ end
@@ -0,0 +1,10 @@
1
+ class PageWidget < Widget
2
+
3
+ def show(opt={})
4
+ @gutter = app.gutter
5
+ app.background app.palegreen
6
+ app.style(Shoes::Link, :underline => false, :stroke => app.blue)
7
+ app.style(Shoes::LinkHover, :underline => true, :stroke => app.red)
8
+ end
9
+
10
+ end
@@ -0,0 +1,28 @@
1
+ class RepositoryWidget < Widget
2
+
3
+ def show(cwd, git_project_dir)
4
+ app.caption("Git Repository", :align => 'center')
5
+ app.flow do
6
+ app.para "Branch: "
7
+ @branch_listbox = app.list_box(:items => Controller.branches) do |list|
8
+ Controller.branch = list.text
9
+ app.visit(DIR_PAGE)
10
+ # file_selection_changed
11
+ end
12
+ @branch_listbox.choose(Controller.branch(false))
13
+ app.button("New", :margin_left => 10) # TODO Hook it up
14
+ app.button("Delete", :margin_left => 10) # TODO Hook it up
15
+ app.button("Stash", :margin_left => 10) { Controller.stash }
16
+ app.button("Stash Pop", :margin_left => 10) { Controller.stash_pop }
17
+ end
18
+ app.para("Branch: ", app.strong(Controller.branch(true)))
19
+ app.para(app.strong(git_project_dir, app.em(cwd.gsub(git_project_dir, ''))))
20
+ buf = []
21
+ repository_info = Controller.repository_info
22
+ repository_info.each do |key, value|
23
+ buf << "#{value} #{key} files"
24
+ end
25
+ app.para buf.join(", ")
26
+ end
27
+
28
+ end
@@ -0,0 +1,22 @@
1
+ class StatusAction < Action
2
+ include BulletList
3
+ include Nav
4
+
5
+ def initialize
6
+ super
7
+ @status_widget = StatusWidget.new
8
+ end
9
+
10
+ def execute()
11
+ info "status_action.execute"
12
+
13
+ page_layout do
14
+ if Controller.in_repository?
15
+ info "in repository"
16
+ @status_widget.app = app
17
+ @view_area = @status_widget.show(VIEW_AREA_OPTS)
18
+ end
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,11 @@
1
+ class StatusWidget < Widget
2
+
3
+ def show(opt={})
4
+ info "StatusWidget.show"
5
+ app.stack(opt) do
6
+ app.para `git status`
7
+ app.info app.para.text
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,10 @@
1
+ class TitleWidget < Widget
2
+
3
+ def show
4
+ title_stack = app.stack(:width => '100%') do
5
+ app.background app.gradient(app.rgb(0, 255, 0), app.rgb(225, 255, 0), :angle => 135)
6
+ app.title("Git Shoes", :align => 'center')
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ class Widget
2
+
3
+ attr_accessor :app
4
+
5
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec'
2
2
 
3
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- require 'git_shoes'
5
+ require 'loader'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: royw-git_shoes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Wright
@@ -35,7 +35,18 @@ files:
35
35
  - lib/models/git_helper.rb
36
36
  - lib/views/action.rb
37
37
  - lib/views/bullet_list.rb
38
+ - lib/views/command_widget.rb
38
39
  - lib/views/dir_action.rb
40
+ - lib/views/directory_widget.rb
41
+ - lib/views/file_action.rb
42
+ - lib/views/file_widget.rb
43
+ - lib/views/nav.rb
44
+ - lib/views/page_widget.rb
45
+ - lib/views/repository_widget.rb
46
+ - lib/views/status_action.rb
47
+ - lib/views/status_widget.rb
48
+ - lib/views/title_widget.rb
49
+ - lib/views/widget.rb
39
50
  - spec/git_helper_spec.rb
40
51
  - spec/spec_helper.rb
41
52
  has_rdoc: true