dolt 0.1.1 → 0.2.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.
Files changed (62) hide show
  1. data/Gemfile.lock +25 -5
  2. data/Readme.md +90 -16
  3. data/bin/dolt +22 -4
  4. data/dolt.gemspec +10 -2
  5. data/lib/dolt/disk_repo_resolver.rb +3 -5
  6. data/lib/dolt/git/blame.rb +112 -0
  7. data/lib/dolt/git/commit.rb +73 -0
  8. data/lib/dolt/git/repository.rb +26 -24
  9. data/lib/dolt/repo_actions.rb +32 -19
  10. data/lib/dolt/sinatra/actions.rb +51 -18
  11. data/lib/dolt/sinatra/multi_repo_browser.rb +30 -3
  12. data/lib/dolt/sinatra/single_repo_browser.rb +36 -2
  13. data/lib/dolt/template_renderer.rb +7 -8
  14. data/lib/dolt/version.rb +1 -1
  15. data/lib/dolt/view.rb +3 -61
  16. data/lib/dolt/view/blame.rb +57 -0
  17. data/lib/dolt/view/blob.rb +60 -0
  18. data/lib/dolt/view/breadcrumb.rb +10 -17
  19. data/lib/dolt/{git/blob.rb → view/commit.rb} +5 -11
  20. data/lib/dolt/view/gravatar.rb +29 -0
  21. data/lib/dolt/{git/shell.rb → view/markup.rb} +10 -16
  22. data/lib/dolt/view/multi_repository.rb +27 -0
  23. data/lib/dolt/{async/deferrable_child_process.rb → view/object.rb} +11 -24
  24. data/lib/dolt/view/single_repository.rb +27 -0
  25. data/lib/dolt/view/smart_blob_renderer.rb +33 -0
  26. data/lib/dolt/view/syntax_highlight.rb +86 -0
  27. data/lib/dolt/view/tree.rb +69 -0
  28. data/test/dolt/git/blame_test.rb +128 -0
  29. data/test/dolt/git/commit_test.rb +89 -0
  30. data/test/dolt/git/repository_test.rb +24 -73
  31. data/test/dolt/repo_actions_test.rb +77 -15
  32. data/test/dolt/sinatra/actions_test.rb +168 -8
  33. data/test/dolt/template_renderer_test.rb +44 -10
  34. data/test/dolt/templates/blame_test.rb +56 -0
  35. data/test/dolt/{views → templates}/blob_test.rb +44 -34
  36. data/test/dolt/templates/commits_test.rb +61 -0
  37. data/test/dolt/templates/raw_test.rb +41 -0
  38. data/test/dolt/templates/tree_test.rb +51 -0
  39. data/test/dolt/view/blame_test.rb +122 -0
  40. data/test/dolt/view/blob_test.rb +90 -0
  41. data/test/dolt/view/breadcrumb_test.rb +46 -0
  42. data/test/dolt/view/commit_test.rb +31 -0
  43. data/test/dolt/view/gravatar_test.rb +30 -0
  44. data/test/dolt/view/markup_test.rb +30 -0
  45. data/test/dolt/{git/blob_test.rb → view/multi_repository_test.rb} +10 -24
  46. data/test/dolt/view/object_test.rb +71 -0
  47. data/test/dolt/view/single_repository_test.rb +30 -0
  48. data/test/dolt/{view_test.rb → view/syntax_highlight_test.rb} +40 -27
  49. data/test/dolt/view/tree_test.rb +115 -0
  50. data/test/test_helper.rb +18 -13
  51. data/vendor/ui/css/gitorious.css +20 -8
  52. data/views/blame.erb +41 -0
  53. data/views/blob.erb +6 -9
  54. data/views/commits.erb +23 -0
  55. data/views/index.erb +25 -0
  56. data/views/raw.erb +19 -0
  57. data/views/tree.erb +28 -26
  58. metadata +156 -26
  59. data/lib/dolt/git/tree.rb +0 -65
  60. data/lib/dolt/view/highlighter.rb +0 -52
  61. data/test/dolt/git/shell_test.rb +0 -112
  62. data/test/dolt/git/tree_test.rb +0 -120
@@ -0,0 +1,61 @@
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
+ describe "commits template" do
23
+ include Dolt::ViewTest
24
+
25
+ def commit(num)
26
+ { :oid => num + ("0" * 39),
27
+ :summary => "Commit ##{num}",
28
+ :author => @author,
29
+ :date => Time.now }
30
+ end
31
+
32
+ before do
33
+ @repo = "the-dolt"
34
+ @author = {
35
+ :name => "Christian Johansen",
36
+ :email => "christian@gitorious.com"
37
+ }
38
+ @commit1 = commit("1")
39
+ @commit2 = commit("2")
40
+ @commit3 = commit("3")
41
+ @template_root = File.join(File.dirname(__FILE__), "..", "..", "..", "views")
42
+ end
43
+
44
+ def render(path, commits, options = {})
45
+ renderer = prepare_renderer(@template_root, options)
46
+ renderer.render(:commits, {
47
+ :commits => commits,
48
+ :repository => @repo,
49
+ :ref => options[:ref] || "master",
50
+ :path => path
51
+ })
52
+ end
53
+
54
+ it "renders history" do
55
+ markup = render("app/models/repository.rb", [@commit1, @commit2, @commit3])
56
+
57
+ assert_match /Commit #1/, markup
58
+ assert_match /Commit #2/, markup
59
+ assert_match /Commit #3/, markup
60
+ end
61
+ end
@@ -0,0 +1,41 @@
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 "raw 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
+ it "renders raw contents" do
36
+ renderer = prepare_renderer(@template_root)
37
+ html = renderer.render(:raw, { :blob => Blob.new("Something something") })
38
+
39
+ assert_equal "Something something\n", html
40
+ end
41
+ end
@@ -0,0 +1,51 @@
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 Tree
23
+ attr_reader :entries
24
+ def initialize(entries); @entries = entries; end
25
+ end
26
+
27
+ describe "tree 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, tree, options = {})
36
+ renderer = prepare_renderer(@template_root, options)
37
+ renderer.render(:tree, {
38
+ :tree => tree,
39
+ :repository => @repo,
40
+ :ref => options[:ref] || "master",
41
+ :path => path
42
+ })
43
+ end
44
+
45
+ it "renders empty tree" do
46
+ tree = Tree.new([])
47
+ markup = render("app/models", tree)
48
+
49
+ assert_match /<table class="table table-striped gts-tree-explorer">/, markup
50
+ end
51
+ end
@@ -0,0 +1,122 @@
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/view/blame"
20
+ require "ostruct"
21
+
22
+ describe Dolt::View::Blame do
23
+ include Dolt::Html
24
+ include Dolt::View::Blame
25
+
26
+ before do
27
+ chunks = [{ :oid => "0000001", :lines => ["1", "2", "3"] },
28
+ { :oid => "0000002", :lines => ["4", "5"] }]
29
+ @blame = OpenStruct.new({ :chunks => chunks })
30
+ end
31
+
32
+ describe "#blame_annotations" do
33
+ it "returns array of same length as total number of lines" do
34
+ annotations = blame_annotations(@blame)
35
+
36
+ assert_equal 5, annotations.length
37
+ end
38
+
39
+ it "stores annotation for first occurrence" do
40
+ annotations = blame_annotations(@blame)
41
+
42
+ assert_equal "0000001", annotations.first[:oid]
43
+ end
44
+
45
+ it "stores nil for consecutive entries in same chunk" do
46
+ annotations = blame_annotations(@blame)
47
+
48
+ assert_nil annotations[1]
49
+ assert_nil annotations[2]
50
+ refute_nil annotations[3]
51
+ assert_nil annotations[4]
52
+ end
53
+ end
54
+
55
+ describe "#blame_lines" do
56
+ it "returns array of lines" do
57
+ assert_equal 5, blame_lines("file.rb", @blame).length
58
+ end
59
+
60
+ it "does not modify lines" do
61
+ assert_equal "1", blame_lines("file.rb", @blame).first
62
+ end
63
+ end
64
+
65
+ describe "#blame_lines with #highlight" do
66
+ def highlight(path, code)
67
+ "{" + code.split("\n").map { |l| "#{path}:#{l}" }.join("\n") + "}"
68
+ end
69
+
70
+ it "highlights code before splitting" do
71
+ lines = blame_lines("file.rb", @blame)
72
+
73
+ assert_equal "{file.rb:1", lines.first
74
+ assert_equal "file.rb:2", lines[1]
75
+ assert_equal "file.rb:5}", lines.last
76
+ end
77
+ end
78
+
79
+ describe "#blame_annotation_cell" do
80
+ before do
81
+ @oid = "1234567890" * 4
82
+
83
+ @committer = {
84
+ :name => "Christian Johansen",
85
+ :time => Time.utc(2012, 1, 1, 12)
86
+ }
87
+ end
88
+
89
+ it "returns table cell with annotated class" do
90
+ html = blame_annotation_cell({ :committer => @committer, :oid => @oid })
91
+
92
+ assert_match /gts-blame-annotation/, html
93
+ assert_match /gts-annotated/, html
94
+ assert_match /Christian Johansen/, html
95
+ end
96
+
97
+ it "includes the commit oid" do
98
+ html = blame_annotation_cell({ :committer => @committer, :oid => @oid })
99
+
100
+ assert_match /gts-sha/, html
101
+ assert_match /1234567/, html
102
+ refute_match /890/, html
103
+ end
104
+
105
+ it "includes the commit date" do
106
+ html = blame_annotation_cell({ :committer => @committer, :oid => @oid })
107
+
108
+ assert_match /2012-01-01/, html
109
+ end
110
+ end
111
+
112
+ describe "#blame_code_cell" do
113
+ it "returns table cell with code element" do
114
+ html = blame_code_cell("var a = 42;")
115
+
116
+ assert_equal 1, select(html, "td").length
117
+ assert_match /gts-code/, html
118
+ assert_equal 1, select(html, "code").length
119
+ assert_match /a = 42/, html
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,90 @@
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/view/single_repository"
20
+ require "dolt/view/multi_repository"
21
+ require "dolt/view/blob"
22
+
23
+ describe Dolt::View::Blob do
24
+ include Dolt::View::Blob
25
+
26
+ describe "single repo mode" do
27
+ include Dolt::View::SingleRepository
28
+
29
+ it "returns blame url" do
30
+ url = blame_url("myrepo", "master", "some/path")
31
+ assert_equal "/blame/master:some/path", url
32
+ end
33
+
34
+ it "returns history url" do
35
+ url = history_url("myrepo", "master", "some/path")
36
+ assert_equal "/history/master:some/path", url
37
+ end
38
+
39
+ it "returns raw url" do
40
+ url = raw_url("myrepo", "master", "some/path")
41
+ assert_equal "/raw/master:some/path", url
42
+ end
43
+ end
44
+
45
+ describe "multi repo mode" do
46
+ include Dolt::View::MultiRepository
47
+
48
+ it "returns blame url" do
49
+ url = blame_url("myrepo", "master", "some/path")
50
+ assert_equal "/myrepo/blame/master:some/path", url
51
+ end
52
+
53
+ it "returns history url" do
54
+ url = history_url("myrepo", "master", "some/path")
55
+ assert_equal "/myrepo/history/master:some/path", url
56
+ end
57
+
58
+ it "returns raw url" do
59
+ url = raw_url("myrepo", "master", "some/path")
60
+ assert_equal "/myrepo/raw/master:some/path", url
61
+ end
62
+ end
63
+
64
+ describe "#multiline" do
65
+ it "adds line number markup to code" do
66
+ html = multiline("A few\nLines\n Here")
67
+
68
+ assert_match "<pre", html
69
+ assert_match "<ol class=\"linenums", html
70
+ assert_match "<li class=\"L1\"><span class=\"line\">A few</span></li>", html
71
+ assert_match "<li class=\"L2\"><span class=\"line\">Lines</span></li>", html
72
+ assert_match "<li class=\"L3\"><span class=\"line\"> Here</span></li>", html
73
+ end
74
+
75
+ it "adds custom class name" do
76
+ html = multiline("A few\nLines\n Here", :class_names => ["ruby"])
77
+
78
+ assert_match "prettyprint", html
79
+ assert_match "linenums", html
80
+ assert_match "ruby", html
81
+ end
82
+ end
83
+
84
+ describe "#format_blob" do
85
+ it "escapes brackets" do
86
+ html = format_blob("file.txt", "<hey>")
87
+ assert_match /&lt;hey&gt;/, html
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,46 @@
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/view/breadcrumb"
20
+
21
+ describe Dolt::View::Breadcrumb do
22
+ include Dolt::Html
23
+ include Dolt::View::SingleRepository
24
+ include Dolt::View::Breadcrumb
25
+
26
+ it "renders li element for root" do
27
+ html = breadcrumb("myrepo", "master", "path.txt")
28
+
29
+ assert_equal 1, select(html, "a").length
30
+ assert_match /icon-file/, select(html, "li").first
31
+ end
32
+
33
+ it "renders li element for file" do
34
+ html = breadcrumb("myrepo", "master", "path.txt")
35
+
36
+ assert_match /path.txt/, select(html, "li").last
37
+ end
38
+
39
+ it "renders links to accumulated paths" do
40
+ html = breadcrumb("myrepo", "master", "some/nested/path.txt")
41
+
42
+ links = select(html, "a")
43
+ assert_match /\"\/tree\/master:some"/, links[1]
44
+ assert_match /\"\/tree\/master:some\/nested"/, links[2]
45
+ end
46
+ end
@@ -0,0 +1,31 @@
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/view/commit"
20
+
21
+ describe Dolt::View::Commit do
22
+ include Dolt::Html
23
+ include Dolt::View::Commit
24
+
25
+ describe "#commit_oid" do
26
+ it "returns the first seven characters" do
27
+ oid = "38b06b3f65a9c84ac860bf0ce0a69e43a23bc765"
28
+ assert_equal "38b06b3", commit_oid(oid)
29
+ end
30
+ end
31
+ end