dolt 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile.lock +21 -18
  2. data/Readme.md +3 -5
  3. data/bin/dolt +3 -6
  4. data/dolt.gemspec +5 -16
  5. data/lib/dolt/sinatra/multi_repo_browser.rb +3 -3
  6. data/lib/dolt/sinatra/single_repo_browser.rb +3 -3
  7. data/test/test_helper.rb +5 -3
  8. data/vendor/ui/css/gitorious.css +5 -0
  9. metadata +23 -239
  10. data/lib/dolt/async/when.rb +0 -128
  11. data/lib/dolt/disk_repo_resolver.rb +0 -39
  12. data/lib/dolt/git/blame.rb +0 -112
  13. data/lib/dolt/git/commit.rb +0 -73
  14. data/lib/dolt/git/repository.rb +0 -139
  15. data/lib/dolt/git/submodule.rb +0 -35
  16. data/lib/dolt/git/tree.rb +0 -42
  17. data/lib/dolt/repo_actions.rb +0 -91
  18. data/lib/dolt/template_renderer.rb +0 -67
  19. data/lib/dolt/version.rb +0 -21
  20. data/lib/dolt/view.rb +0 -23
  21. data/lib/dolt/view/binary_blob_embedder.rb +0 -41
  22. data/lib/dolt/view/blame.rb +0 -57
  23. data/lib/dolt/view/blob.rb +0 -97
  24. data/lib/dolt/view/breadcrumb.rb +0 -47
  25. data/lib/dolt/view/commit.rb +0 -27
  26. data/lib/dolt/view/gravatar.rb +0 -29
  27. data/lib/dolt/view/markup.rb +0 -107
  28. data/lib/dolt/view/multi_repository.rb +0 -27
  29. data/lib/dolt/view/object.rb +0 -44
  30. data/lib/dolt/view/single_repository.rb +0 -27
  31. data/lib/dolt/view/smart_blob_renderer.rb +0 -33
  32. data/lib/dolt/view/syntax_highlight.rb +0 -90
  33. data/lib/dolt/view/tab_width.rb +0 -30
  34. data/lib/dolt/view/tree.rb +0 -100
  35. data/test/dolt/async/when_test.rb +0 -112
  36. data/test/dolt/git/blame_test.rb +0 -128
  37. data/test/dolt/git/commit_test.rb +0 -89
  38. data/test/dolt/git/repository_test.rb +0 -186
  39. data/test/dolt/repo_actions_test.rb +0 -236
  40. data/test/dolt/template_renderer_test.rb +0 -122
  41. data/test/dolt/templates/blame_test.rb +0 -56
  42. data/test/dolt/templates/blob_test.rb +0 -118
  43. data/test/dolt/templates/commits_test.rb +0 -61
  44. data/test/dolt/templates/raw_test.rb +0 -41
  45. data/test/dolt/templates/refs_test.rb +0 -38
  46. data/test/dolt/templates/tree_history_test.rb +0 -93
  47. data/test/dolt/templates/tree_test.rb +0 -65
  48. data/test/dolt/view/binary_blob_embedder_test.rb +0 -49
  49. data/test/dolt/view/blame_test.rb +0 -122
  50. data/test/dolt/view/blob_test.rb +0 -116
  51. data/test/dolt/view/breadcrumb_test.rb +0 -46
  52. data/test/dolt/view/commit_test.rb +0 -31
  53. data/test/dolt/view/gravatar_test.rb +0 -30
  54. data/test/dolt/view/markup_test.rb +0 -94
  55. data/test/dolt/view/multi_repository_test.rb +0 -35
  56. data/test/dolt/view/object_test.rb +0 -83
  57. data/test/dolt/view/single_repository_test.rb +0 -30
  58. data/test/dolt/view/smart_blob_renderer_test.rb +0 -38
  59. data/test/dolt/view/syntax_highlight_test.rb +0 -108
  60. data/test/dolt/view/tab_width_test.rb +0 -40
  61. data/test/dolt/view/tree_test.rb +0 -199
  62. data/views/500.erb +0 -22
  63. data/views/blame.erb +0 -42
  64. data/views/blob.erb +0 -31
  65. data/views/commits.erb +0 -26
  66. data/views/index.erb +0 -25
  67. data/views/layout.erb +0 -45
  68. data/views/raw.erb +0 -19
  69. data/views/refs.erb +0 -22
  70. data/views/tree.erb +0 -50
  71. data/views/tree_history.erb +0 -19
@@ -1,236 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "test_helper"
19
- require "dolt/repo_actions"
20
- require "dolt/async/when"
21
- require "ostruct"
22
-
23
- class Repository
24
- attr_reader :name
25
- def initialize(name); @name = name; end
26
- def tree(ref, path); stub; end
27
- def rev_parse(rev); stub; end
28
- def blame(ref, path); stub; end
29
- def log(ref, path, limit); stub; end
30
- def refs; stub; end
31
- def tree_history(ref, path, count); stub; end
32
-
33
- def resolve_promise(blob)
34
- @deferred.resolve(blob)
35
- end
36
-
37
- private
38
- def stub
39
- @deferred = When::Deferred.new
40
- @deferred.promise
41
- end
42
- end
43
-
44
- class Resolver
45
- attr_reader :resolved
46
- def initialize; @resolved = []; end
47
-
48
- def resolve(repo)
49
- repository = Repository.new(repo)
50
- @resolved << repository
51
- repository
52
- end
53
- end
54
-
55
- describe Dolt::RepoActions do
56
- before do
57
- @resolver = Resolver.new
58
- @actions = Dolt::RepoActions.new(@resolver)
59
- end
60
-
61
- describe "#blob" do
62
- it "resolves repository" do
63
- @actions.blob("gitorious", "master", "app")
64
-
65
- assert_equal ["gitorious"], @resolver.resolved.map(&:name)
66
- end
67
-
68
- it "yields path, blob, repo, ref and base_tree_url to block" do
69
- data = nil
70
- @actions.blob("gitorious", "babd120", "app") do |err, d|
71
- data = d
72
- end
73
-
74
- @resolver.resolved.last.resolve_promise("Blob")
75
-
76
- assert_equal({
77
- :blob => "Blob",
78
- :repository => "gitorious",
79
- :ref => "babd120",
80
- :path => "app"
81
- }, data)
82
- end
83
- end
84
-
85
- describe "#tree" do
86
- it "resolves repository" do
87
- @actions.tree("gitorious", "master", "app")
88
-
89
- assert_equal ["gitorious"], @resolver.resolved.map(&:name)
90
- end
91
-
92
- it "yields tree, repo and ref to block" do
93
- data = nil
94
- @actions.tree("gitorious", "babd120", "app") do |err, d|
95
- data = d
96
- end
97
-
98
- repo = @resolver.resolved.last
99
- repo.resolve_promise "Tree"
100
-
101
- expected = {
102
- :tree => "Tree",
103
- :repository => "gitorious",
104
- :ref => "babd120",
105
- :path => "app"
106
- }
107
- assert_equal expected, data
108
- end
109
- end
110
-
111
- describe "#blame" do
112
- it "resolves repository" do
113
- @actions.blame("gitorious", "master", "app")
114
-
115
- assert_equal ["gitorious"], @resolver.resolved.map(&:name)
116
- end
117
-
118
- it "yields blame, repo and ref to block" do
119
- data = nil
120
- @actions.blame("gitorious", "babd120", "app") do |err, d|
121
- data = d
122
- end
123
-
124
- repo = @resolver.resolved.last
125
- repo.resolve_promise "Blame"
126
-
127
- expected = {
128
- :blame => "Blame",
129
- :repository => "gitorious",
130
- :ref => "babd120",
131
- :path => "app"
132
- }
133
- assert_equal expected, data
134
- end
135
- end
136
-
137
- describe "#history" do
138
- it "resolves repository" do
139
- @actions.history("gitorious", "master", "app", 1)
140
-
141
- assert_equal ["gitorious"], @resolver.resolved.map(&:name)
142
- end
143
-
144
- it "yields commits, repo and ref to block" do
145
- data = nil
146
- @actions.history("gitorious", "babd120", "app", 2) do |err, d|
147
- data = d
148
- end
149
-
150
- repo = @resolver.resolved.last
151
- repo.resolve_promise "History"
152
-
153
- expected = {
154
- :commits => "History",
155
- :repository => "gitorious",
156
- :ref => "babd120",
157
- :path => "app"
158
- }
159
- assert_equal expected, data
160
- end
161
- end
162
-
163
- describe "#refs" do
164
- before do
165
- @refs = ["refs/stash",
166
- "refs/tags/v0.2.1",
167
- "refs/tags/v0.2.0",
168
- "refs/remotes/origin/master",
169
- "refs/heads/libgit2",
170
- "refs/heads/master"].map { |n| OpenStruct.new(:name => n) }
171
- end
172
-
173
- it "yields repositories, tags and heads" do
174
- data = nil
175
- @actions.refs("gitorious") { |err, d| data = d }
176
-
177
- repo = @resolver.resolved.last
178
- repo.resolve_promise(@refs)
179
-
180
- expected = {
181
- :repository => "gitorious",
182
- :heads => ["libgit2", "master"],
183
- :tags => ["v0.2.1", "v0.2.0"]
184
- }
185
- assert_equal expected, data
186
- end
187
- end
188
-
189
- describe "#tree_history" do
190
- before do
191
- @tree = [{
192
- :type => :blob,
193
- :oid => "e90021f89616ddf86855d05337c188408d3b417e",
194
- :filemode => 33188,
195
- :name => ".gitmodules",
196
- :history => [{
197
- :oid => "906d67b4f3e5de7364ba9b57d174d8998d53ced6",
198
- :author => { :name => "Christian Johansen",
199
- :email => "christian@cjohansen.no" },
200
- :summary => "Working Moron server for viewing blobs",
201
- :date => Time.parse("Mon Sep 10 15:07:39 +0200 2012"),
202
- :message => ""
203
- }]
204
- }, {
205
- :type => :blob,
206
- :oid => "c80ee3697054566d1a4247d80be78ec3ddfde295",
207
- :filemode => 33188,
208
- :name => "Gemfile",
209
- :history => [{
210
- :oid => "26139a3aba4aac8cbf658c0d0ea58b8983e4090b",
211
- :author => { :name => "Christian Johansen",
212
- :email => "christian@cjohansen.no" },
213
- :summary => "Initial commit",
214
- :date => Time.parse("Thu Aug 23 11:40:39 +0200 2012"),
215
- :message => ""
216
- }]
217
- }]
218
- end
219
-
220
- it "yields repository, path, ref and history" do
221
- data = nil
222
- @actions.tree_history("gitorious", "master", "", 1) { |err, d| data = d }
223
-
224
- repo = @resolver.resolved.last
225
- repo.resolve_promise(@tree)
226
-
227
- expected = {
228
- :repository => "gitorious",
229
- :ref => "master",
230
- :path => "",
231
- :tree => @tree
232
- }
233
- assert_equal expected, data
234
- end
235
- end
236
- end
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "test_helper"
19
- require "mocha"
20
- require "dolt/template_renderer"
21
-
22
- module ViewHelper
23
- def say_it; "YES"; end
24
- end
25
-
26
- describe Dolt::TemplateRenderer do
27
- before { @root = "/dolt/views" }
28
-
29
- it "reads template from file" do
30
- File.expects(:read).with("/dolt/views/file.erb").returns("")
31
- renderer = Dolt::TemplateRenderer.new("/dolt/views")
32
- renderer.render(:file)
33
- end
34
-
35
- it "renders template with locals" do
36
- File.stubs(:read).returns("<%= name %>!")
37
- renderer = Dolt::TemplateRenderer.new(@root)
38
-
39
- assert_equal "Chris!", renderer.render(:file, { :name => "Chris"})
40
- end
41
-
42
- it "caches template in memory" do
43
- renderer = Dolt::TemplateRenderer.new(@root)
44
- File.stubs(:read).returns("Original")
45
- renderer.render(:file)
46
- File.stubs(:read).returns("Updated")
47
-
48
- assert_equal "Original", renderer.render(:file)
49
- end
50
-
51
- it "does not cache template in memory when configured not to" do
52
- renderer = Dolt::TemplateRenderer.new(@root, :cache => false)
53
- File.stubs(:read).returns("Original")
54
- renderer.render(:file)
55
- File.stubs(:read).returns("Updated")
56
-
57
- assert_equal "Updated", renderer.render(:file)
58
- end
59
-
60
- it "renders template with layout" do
61
- renderer = Dolt::TemplateRenderer.new("/", :layout => "layout")
62
- File.stubs(:read).with("/file.erb").returns("Template")
63
- File.stubs(:read).with("/layout.erb").returns("I give you: <%= yield %>")
64
-
65
- assert_equal "I give you: Template", renderer.render(:file)
66
- end
67
-
68
- it "renders template once without layout" do
69
- renderer = Dolt::TemplateRenderer.new("/", :layout => "layout")
70
- File.stubs(:read).with("/file.erb").returns("Template")
71
- File.stubs(:read).with("/layout.erb").returns("I give you: <%= yield %>")
72
-
73
- assert_equal "Template", renderer.render(:file, {}, :layout => nil)
74
- end
75
-
76
- it "renders template once with different layout" do
77
- renderer = Dolt::TemplateRenderer.new("/", :layout => "layout")
78
- File.stubs(:read).with("/file.erb").returns("Template")
79
- File.stubs(:read).with("/layout.erb").returns("I give you: <%= yield %>")
80
- File.stubs(:read).with("/layout2.erb").returns("I present you: <%= yield %>")
81
-
82
- html = renderer.render(:file, {}, :layout => "layout2")
83
-
84
- assert_equal "I present you: Template", html
85
- end
86
-
87
- it "renders templates of specific type" do
88
- renderer = Dolt::TemplateRenderer.new("/", :type => :str)
89
- File.stubs(:read).with("/file.str").returns("Hey!")
90
-
91
- assert_equal "Hey!", renderer.render(:file)
92
- end
93
-
94
- it "renders with helper object" do
95
- renderer = Dolt::TemplateRenderer.new("/")
96
- renderer.helper(ViewHelper)
97
- File.stubs(:read).with("/file.erb").returns("Say it: <%= say_it %>")
98
-
99
- assert_equal "Say it: YES", renderer.render(:file)
100
- end
101
-
102
- it "does not leak state across render calls" do
103
- renderer = Dolt::TemplateRenderer.new("/")
104
- File.stubs(:read).with("/file.erb").returns(<<-TEMPLATE)
105
- <%= @response %><% @response = "NO" %><%= @response %>
106
- TEMPLATE
107
-
108
- assert_equal "NO", renderer.render(:file)
109
- assert_equal "NO", renderer.render(:file)
110
- end
111
-
112
- it "shares state between template and layout" do
113
- renderer = Dolt::TemplateRenderer.new("/", :layout => "layout")
114
- File.stubs(:read).with("/file.erb").returns(<<-TEMPLATE)
115
- <% @response = "NO" %><h1><%= @response %></h1>
116
- TEMPLATE
117
- tpl = "<title><%= @response %></title><%= yield %>"
118
- File.stubs(:read).with("/layout.erb").returns(tpl)
119
-
120
- assert_equal "<title>NO</title><h1>NO</h1>\n", renderer.render(:file)
121
- end
122
- end
@@ -1,56 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "test_helper"
19
- require "dolt/template_renderer"
20
- require "dolt/view"
21
-
22
- class Blame
23
- attr_reader :chunks
24
- def initialize(chunks); @chunks = chunks; end
25
- end
26
-
27
- describe "blame template" do
28
- include Dolt::ViewTest
29
-
30
- before do
31
- @repo = "the-dolt"
32
- @template_root = File.join(File.dirname(__FILE__), "..", "..", "..", "views")
33
- @committer = {
34
- :name => "Christian Johansen",
35
- :mail => "christian@cjohansen.no",
36
- :time => Time.now
37
- }
38
- end
39
-
40
- def render(path, blame, options = {})
41
- renderer = prepare_renderer(@template_root, options)
42
- renderer.render(:blame, {
43
- :blame => blame,
44
- :repository => @repo,
45
- :ref => options[:ref] || "master",
46
- :path => path
47
- })
48
- end
49
-
50
- it "renders blame" do
51
- blob = Blame.new([{ :oid => "0123456", :committer => @committer, :lines => [] }])
52
- markup = render("app/models/repository.rb", blob)
53
-
54
- assert_match /<table class="gts-code-listing">/, markup
55
- end
56
- end
@@ -1,118 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "test_helper"
19
- require "dolt/template_renderer"
20
- require "dolt/view"
21
-
22
- class Blob
23
- attr_reader :content
24
- def initialize(content); @content = content; end
25
- end
26
-
27
- describe "blob template" do
28
- include Dolt::ViewTest
29
-
30
- before do
31
- @repo = "the-dolt"
32
- @template_root = File.join(File.dirname(__FILE__), "..", "..", "..", "views")
33
- end
34
-
35
- def render(path, blob, options = {}, helpers = nil)
36
- renderer = prepare_renderer(@template_root, options, helpers)
37
- renderer.render(:blob, {
38
- :blob => blob,
39
- :repository => @repo,
40
- :ref => options[:ref] || "master",
41
- :path => path
42
- })
43
- end
44
-
45
- it "renders blob without errors" do
46
- markup = render("file.txt", Blob.new("Something something"))
47
-
48
- assert_match /Something something/, markup
49
- end
50
-
51
- it "renders blob with line numbers" do
52
- markup = render("file.txt", Blob.new("One\nTwo\nThree"))
53
-
54
- assert_match /<li.*One.*<\/li>/, markup
55
- assert_match /<li.*Two.*<\/li>/, markup
56
- assert_match /<li.*Three.*<\/li>/, markup
57
- end
58
-
59
- it "renders blob with layout" do
60
- markup = render("file.txt", Blob.new("Something something"), :layout => "layout")
61
-
62
- assert_match /Something something/, markup
63
- end
64
-
65
- it "renders repo title in page" do
66
- @repo = "my-magic-repo"
67
- markup = render("file.txt", Blob.new("Something something"), :layout => "layout")
68
-
69
- assert_match "my-magic-repo", markup
70
- end
71
-
72
- it "renders links to other views" do
73
- markup = render("file.txt", Blob.new("Something something"))
74
-
75
- assert_match "/the-dolt/blame/master:file.txt", markup
76
- assert_match "/the-dolt/history/master:file.txt", markup
77
- assert_match "/the-dolt/raw/master:file.txt", markup
78
- end
79
-
80
- it "renders links to other views for correct ref" do
81
- markup = render("file.txt", Blob.new("Something something"), :ref => "123bc21")
82
-
83
- assert_match "/the-dolt/blame/123bc21:file.txt", markup
84
- assert_match "/the-dolt/history/123bc21:file.txt", markup
85
- assert_match "/the-dolt/raw/123bc21:file.txt", markup
86
- end
87
-
88
- it "renders the path clickable" do
89
- markup = render("some/deeply/nested/file.txt", Blob.new("Something something"))
90
-
91
- assert_match 'href="/the-dolt/tree/master:some"', markup
92
- assert_match 'href="/the-dolt/tree/master:some/deeply"', markup
93
- assert_match 'href="/the-dolt/tree/master:some/deeply/nested"', markup
94
- end
95
-
96
- describe "with smart blob rendering" do
97
- include Dolt::Html
98
-
99
- before do
100
- @helpers = [Dolt::View::SingleRepository,
101
- Dolt::View::Breadcrumb,
102
- Dolt::View::Blob,
103
- Dolt::View::SmartBlobRenderer]
104
- end
105
-
106
- it "renders markdown as html" do
107
- markup = render("file.md", Blob.new("# Cool"), {}, @helpers)
108
- assert_equal 1, select(markup, "h1").length
109
- end
110
-
111
- it "syntax highlights ruby" do
112
- blob = Blob.new("class Person\n attr_reader :name\nend")
113
- markup = render("file.rb", blob, {}, @helpers)
114
-
115
- assert_equal 0, select(markup, "h1").length
116
- end
117
- end
118
- end