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,30 @@
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/gravatar"
20
+
21
+ describe Dolt::View::Gravatar do
22
+ include Dolt::View::Gravatar
23
+
24
+ describe "#gravatar" do
25
+ it "returns gravatar URL" do
26
+ url = gravatar("christian@gitorious.com")
27
+ assert_equal "http://www.gravatar.com/avatar/38b06b3f65a9c84ac860bf0ce0a69e43", url
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
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/markup"
20
+
21
+ describe Dolt::View::Markup do
22
+ include Dolt::View::Markup
23
+
24
+ describe "#render_markup" do
25
+ it "wraps markup in .gts-markup" do
26
+ html = render_markup("file.md", "# Hey")
27
+ assert_match "<div class=\"gts-markup\">", html
28
+ end
29
+ end
30
+ end
@@ -16,34 +16,20 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
18
18
  require "test_helper"
19
- require "dolt/git/blob"
19
+ require "dolt/view/multi_repository"
20
20
 
21
- describe Dolt::Git::Blob do
22
- describe "#raw" do
23
- it "returns full raw blob" do
24
- blob = Dolt::Git::Blob.new("file.txt", "Something something")
21
+ describe Dolt::View::MultiRepository do
22
+ include Dolt::Html
23
+ include Dolt::View::MultiRepository
25
24
 
26
- assert_equal "Something something", blob.raw
25
+ describe "#repo_url" do
26
+ it "returns url prefixed with repository" do
27
+ assert_equal "/gitorious/some/url", repo_url("gitorious", "/some/url")
27
28
  end
28
- end
29
-
30
- describe "#lines" do
31
- it "returns empty array for empty blob" do
32
- blob = Dolt::Git::Blob.new("file.txt", "")
33
-
34
- assert_equal [], blob.lines
35
- end
36
-
37
- it "returns array of one line" do
38
- blob = Dolt::Git::Blob.new("file.txt", "Something something")
39
-
40
- assert_equal ["Something something"], blob.lines
41
- end
42
-
43
- it "returns array of lines" do
44
- blob = Dolt::Git::Blob.new("file.txt", "Something\nsomething\nYup")
45
29
 
46
- assert_equal ["Something", "something", "Yup"], blob.lines
30
+ it "returns url prefixed with repository name containing slashes" do
31
+ url = repo_url("gitorious/mainline", "/some/url")
32
+ assert_equal "/gitorious/mainline/some/url", url
47
33
  end
48
34
  end
49
35
  end
@@ -0,0 +1,71 @@
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/object"
22
+
23
+ describe Dolt::View::Object do
24
+ include Dolt::View::Object
25
+
26
+ describe "single repo mode" do
27
+ include Dolt::View::SingleRepository
28
+
29
+ it "returns blob url" do
30
+ object = { :type => "blob", :name => "Gemfile" }
31
+ url = object_url("myrepo", "master", "", object)
32
+ assert_equal "/blob/master:Gemfile", url
33
+ end
34
+
35
+ it "returns tree url" do
36
+ object = { :type => "tree", :name => "models" }
37
+ url = object_url("myrepo", "master", "app", object)
38
+ assert_equal "/tree/master:app/models", url
39
+ end
40
+
41
+ it "returns blob url in directory" do
42
+ object = { :type => "blob", :name => "Gemfile" }
43
+ url = object_url("myrepo", "master", "lib/mything", object)
44
+ assert_equal "/blob/master:lib/mything/Gemfile", url
45
+ end
46
+ end
47
+
48
+ describe "multi repo mode" do
49
+ include Dolt::View::MultiRepository
50
+
51
+ it "returns blob url" do
52
+ object = { :type => "blob", :name => "Gemfile" }
53
+ url = object_url("myrepo", "master", "", object)
54
+ assert_equal "/myrepo/blob/master:Gemfile", url
55
+ end
56
+
57
+ it "returns blob url in directory" do
58
+ object = { :type => "blob", :name => "Gemfile" }
59
+ url = object_url("myrepo", "master", "lib/mything", object)
60
+ assert_equal "/myrepo/blob/master:lib/mything/Gemfile", url
61
+ end
62
+ end
63
+
64
+ it "returns blob icon type" do
65
+ assert_equal "icon-file", object_icon_class({ :type => :blob })
66
+ end
67
+
68
+ it "returns tree icon type" do
69
+ assert_equal "icon-folder-close", object_icon_class({ :type => :tree })
70
+ end
71
+ end
@@ -0,0 +1,30 @@
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
+
21
+ describe Dolt::View::SingleRepository do
22
+ include Dolt::Html
23
+ include Dolt::View::SingleRepository
24
+
25
+ describe "#repo_url" do
26
+ it "returns url unmodified" do
27
+ assert_equal "/some/url", repo_url("gitorious", "/some/url")
28
+ end
29
+ end
30
+ end
@@ -16,30 +16,14 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
18
18
  require "test_helper"
19
- require "dolt/view"
19
+ require "dolt/view/single_repository"
20
+ require "dolt/view/multi_repository"
21
+ require "dolt/view/blob"
22
+ require "dolt/view/syntax_highlight"
20
23
 
21
- describe Dolt::View do
22
- include Dolt::View
23
-
24
- describe "#multiline" do
25
- it "adds line number markup to code" do
26
- html = multiline("A few\nLines\n Here")
27
-
28
- assert_match "<pre", html
29
- assert_match "<ol class=\"linenums", html
30
- assert_match "<li class=\"L1\"><span class=\"line\">A few</span></li>", html
31
- assert_match "<li class=\"L2\"><span class=\"line\">Lines</span></li>", html
32
- assert_match "<li class=\"L3\"><span class=\"line\"> Here</span></li>", html
33
- end
34
-
35
- it "adds custom class name" do
36
- html = multiline("A few\nLines\n Here", :class_names => ["ruby"])
37
-
38
- assert_match "prettyprint", html
39
- assert_match "linenums", html
40
- assert_match "ruby", html
41
- end
42
- end
24
+ describe Dolt::View::Blob do
25
+ include Dolt::View::Blob
26
+ include Dolt::View::SyntaxHighlight
43
27
 
44
28
  describe "#highlight" do
45
29
  it "highlights a Ruby file" do
@@ -57,7 +41,7 @@ describe Dolt::View do
57
41
  end
58
42
 
59
43
  it "highlights file with custom suffix" do
60
- Dolt::View::Highlighter.add_lexer_alias("derp", "rb")
44
+ Dolt::View::SyntaxHighlight.add_lexer_alias("derp", "rb")
61
45
  html = highlight("file.derp", "class File")
62
46
 
63
47
  assert_match "<span class=\"k\">class</span>", html
@@ -71,18 +55,47 @@ describe Dolt::View do
71
55
  end
72
56
  end
73
57
 
74
- describe "#highlight_lines" do
58
+ describe "#format_blob" do
75
59
  it "highlights a Ruby file with line nums" do
76
- html = highlight_lines("file.rb", "class File\n attr_reader :path\nend")
60
+ html = format_blob("file.rb", "class File\n attr_reader :path\nend")
77
61
 
78
62
  assert_match "<li class=\"L1\">", html
79
63
  assert_match "<span class=\"k\">class</span>", html
80
64
  end
81
65
 
82
66
  it "includes lexer as class name" do
83
- html = highlight_lines("file.rb", "class File\n attr_reader :path\nend")
67
+ html = format_blob("file.rb", "class File\n attr_reader :path\nend")
84
68
 
85
69
  assert_match "rb", html
86
70
  end
87
71
  end
72
+
73
+ describe "#lexer" do
74
+ it "uses known suffix" do
75
+ assert_equal "rb", lexer("file.rb")
76
+ end
77
+
78
+ it "uses registered suffix" do
79
+ Dolt::View::SyntaxHighlight.add_lexer_alias("blarg", "blarg")
80
+ assert_equal "blarg", lexer("file.blarg")
81
+ end
82
+
83
+ it "uses registered lexer" do
84
+ Dolt::View::SyntaxHighlight.add_lexer_alias("bg", "blarg")
85
+ assert_equal "blarg", lexer("file.bg")
86
+ end
87
+
88
+ it "uses known shebang" do
89
+ assert_equal "rb", lexer("some-binary", "#!/usr/bin/env ruby\n")
90
+ end
91
+
92
+ it "uses registered shebang" do
93
+ Dolt::View::SyntaxHighlight.add_lexer_shebang(/\bnode\b/, "js")
94
+ assert_equal "js", lexer("some-binary", "#!/usr/bin/env node\n")
95
+ end
96
+
97
+ it "uses filename for unknown lexer" do
98
+ assert_equal "some-binary", lexer("some-binary", "class Person\nend")
99
+ end
100
+ end
88
101
  end
@@ -0,0 +1,115 @@
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/object"
21
+ require "dolt/view/tree"
22
+ require "ostruct"
23
+
24
+ describe Dolt::View::Tree do
25
+ include Dolt::Html
26
+ include Dolt::View::SingleRepository
27
+ include Dolt::View::Object
28
+ include Dolt::View::Tree
29
+
30
+ describe "#tree_entries" do
31
+ before do
32
+ async = { :name => "async", :type => :tree }
33
+ disk_repo_resolver = { :type => :blob, :name => "disk_repo_resolver.rb" }
34
+ git = { :type => :tree, :name => "git" }
35
+ repo_actions = { :type => :blob, :name => "repo_actions.rb" }
36
+ sinatra = { :type => :tree, :name => "sinatra" }
37
+ template_renderer = { :type => :blob, :name => "template_renderer.rb" }
38
+ version = { :type => :blob, :name => "version.rb" }
39
+ view_rb = { :type => :blob, :name => "view.rb" }
40
+ view = { :type => :tree, :name => "view" }
41
+ @tree = OpenStruct.new({ :entries => [async, disk_repo_resolver, git,
42
+ repo_actions, sinatra, template_renderer,
43
+ version, view_rb, view] })
44
+ end
45
+
46
+ it "groups tree by type, dirs first" do
47
+ entries = tree_entries(@tree)
48
+
49
+ assert_equal :tree, entries[0][:type]
50
+ assert_equal :tree, entries[1][:type]
51
+ assert_equal :tree, entries[2][:type]
52
+ assert_equal :tree, entries[3][:type]
53
+ assert_equal :blob, entries[4][:type]
54
+ assert_equal :blob, entries[5][:type]
55
+ assert_equal :blob, entries[6][:type]
56
+ assert_equal :blob, entries[7][:type]
57
+ assert_equal :blob, entries[8][:type]
58
+ end
59
+
60
+ it "sorts by name" do
61
+ entries = tree_entries(@tree)
62
+
63
+ assert_equal "async", entries[0][:name]
64
+ assert_equal "git", entries[1][:name]
65
+ assert_equal "sinatra", entries[2][:name]
66
+ assert_equal "view", entries[3][:name]
67
+ assert_equal "disk_repo_resolver.rb", entries[4][:name]
68
+ assert_equal "repo_actions.rb", entries[5][:name]
69
+ assert_equal "template_renderer.rb", entries[6][:name]
70
+ assert_equal "version.rb", entries[7][:name]
71
+ assert_equal "view.rb", entries[8][:name]
72
+ end
73
+ end
74
+
75
+ describe "#tree_context" do
76
+ def context(path)
77
+ tree_context("gitorious", "master", path)
78
+ end
79
+
80
+ it "renders root as empty string" do
81
+ assert_equal "", context("")
82
+ assert_equal "", context("/")
83
+ assert_equal "", context("./")
84
+ end
85
+
86
+ it "renders single path item as table row" do
87
+ assert_equal 1, select(context("lib"), "tr").length
88
+ assert_equal 1, select(context("./lib"), "tr").length
89
+ end
90
+
91
+ it "renders single path item in cell" do
92
+ assert_equal 1, select(context("lib"), "td").length
93
+ end
94
+
95
+ it "renders single path item as link" do
96
+ assert_equal 1, select(context("lib"), "a").length
97
+ assert_match /lib/, select(context("lib"), "a").first
98
+ end
99
+
100
+ it "renders single path item with open folder icon" do
101
+ assert_match /icon-folder-open/, select(context("lib"), "i").first
102
+ end
103
+
104
+ it "renders two path items as two table rows" do
105
+ assert_equal 2, select(context("lib/dolt"), "tr").length
106
+ end
107
+
108
+ it "renders two path items with colspan in first row" do
109
+ assert_match /colspan="6"/, select(context("lib/dolt"), "tr").first
110
+ assert_match /colspan="5"/, select(context("lib/dolt"), "tr")[1]
111
+ tr = select(context("lib/dolt"), "tr")[1]
112
+ assert_equal 2, select(tr, "td").length
113
+ end
114
+ end
115
+ end
data/test/test_helper.rb CHANGED
@@ -19,25 +19,30 @@ require "bundler/setup"
19
19
  require "minitest/autorun"
20
20
  require "em/minitest/spec"
21
21
  require "eventmachine"
22
+ require "dolt/view"
22
23
 
23
24
  Bundler.require(:default, :test)
24
25
 
25
26
  module Dolt
26
- module StdioStub
27
- def silence_stderr
28
- new_stderr = $stderr.dup
29
- rd, wr = IO::pipe
30
- $stderr.reopen(wr)
31
- yield
32
- $stderr.reopen(new_stderr)
27
+ module Html
28
+ def select(html, tag_name)
29
+ html.scan(/<#{tag_name}[^>]*>.*?<\/#{tag_name}>/m)
33
30
  end
31
+ end
34
32
 
35
- def silence_stdout
36
- new_stdout = $stdout.dup
37
- rd, wr = IO::pipe
38
- $stdout.reopen(wr)
39
- yield
40
- $stdout.reopen(new_stdout)
33
+ module ViewTest
34
+ def prepare_renderer(root, options = {}, helpers = nil)
35
+ renderer = Dolt::TemplateRenderer.new(root, options)
36
+ renderer.helper(helpers || [Dolt::View::MultiRepository,
37
+ Dolt::View::Object,
38
+ Dolt::View::Blob,
39
+ Dolt::View::Tree,
40
+ Dolt::View::Blame,
41
+ Dolt::View::SyntaxHighlight,
42
+ Dolt::View::Commit,
43
+ Dolt::View::Gravatar,
44
+ Dolt::View::Breadcrumb])
45
+ renderer
41
46
  end
42
47
  end
43
48
  end