dolt 0.1.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 (48) hide show
  1. data/.gitmodules +3 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +53 -0
  4. data/Rakefile +10 -0
  5. data/Readme.md +25 -0
  6. data/bin/dolt +46 -0
  7. data/dolt.gemspec +39 -0
  8. data/lib/dolt/async/deferrable_child_process.rb +49 -0
  9. data/lib/dolt/async/when.rb +87 -0
  10. data/lib/dolt/disk_repo_resolver.rb +41 -0
  11. data/lib/dolt/git/blob.rb +31 -0
  12. data/lib/dolt/git/repository.rb +47 -0
  13. data/lib/dolt/git/shell.rb +39 -0
  14. data/lib/dolt/repo_actions.rb +41 -0
  15. data/lib/dolt/sinatra/actions.rb +38 -0
  16. data/lib/dolt/sinatra/base.rb +36 -0
  17. data/lib/dolt/sinatra/multi_repo_browser.rb +37 -0
  18. data/lib/dolt/sinatra/single_repo_browser.rb +44 -0
  19. data/lib/dolt/template_renderer.rb +60 -0
  20. data/lib/dolt/version.rb +21 -0
  21. data/lib/dolt/view.rb +58 -0
  22. data/lib/dolt/view/breadcrumb.rb +45 -0
  23. data/lib/dolt/view/highlighter.rb +49 -0
  24. data/test/dolt/git/blob_test.rb +49 -0
  25. data/test/dolt/git/repository_test.rb +70 -0
  26. data/test/dolt/git/shell_test.rb +78 -0
  27. data/test/dolt/repo_actions_test.rb +73 -0
  28. data/test/dolt/sinatra/actions_test.rb +81 -0
  29. data/test/dolt/template_renderer_test.rb +80 -0
  30. data/test/dolt/view_test.rb +88 -0
  31. data/test/dolt/views/blob_test.rb +96 -0
  32. data/test/test_helper.rb +43 -0
  33. data/vendor/ui/bootstrap/css/bootstrap-responsive.min.css +9 -0
  34. data/vendor/ui/bootstrap/css/bootstrap.min.css +9 -0
  35. data/vendor/ui/bootstrap/img/glyphicons-halflings-white.png +0 -0
  36. data/vendor/ui/bootstrap/img/glyphicons-halflings.png +0 -0
  37. data/vendor/ui/bootstrap/js/bootstrap.min.js +6 -0
  38. data/vendor/ui/css/gitorious.css +535 -0
  39. data/vendor/ui/css/pygments.css +133 -0
  40. data/vendor/ui/iconic/lock_stroke.svg +17 -0
  41. data/vendor/ui/images/f5f5f5-980x1.png +0 -0
  42. data/vendor/ui/images/gitorious.png +0 -0
  43. data/vendor/ui/images/powered-by.png +0 -0
  44. data/vendor/ui/images/white-980x1.png +0 -0
  45. data/vendor/ui/js/gitorious.js +87 -0
  46. data/views/blob.erb +43 -0
  47. data/views/layout.erb +42 -0
  48. metadata +263 -0
@@ -0,0 +1,49 @@
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/git/blob"
20
+
21
+ describe Dolt::Blob do
22
+ describe "#raw" do
23
+ it "returns full raw blob" do
24
+ blob = Dolt::Blob.new("file.txt", "Something something")
25
+
26
+ assert_equal "Something something", blob.raw
27
+ end
28
+ end
29
+
30
+ describe "#lines" do
31
+ it "returns empty array for empty blob" do
32
+ blob = Dolt::Blob.new("file.txt", "")
33
+
34
+ assert_equal [], blob.lines
35
+ end
36
+
37
+ it "returns array of one line" do
38
+ blob = Dolt::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::Blob.new("file.txt", "Something\nsomething\nYup")
45
+
46
+ assert_equal ["Something", "something", "Yup"], blob.lines
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,70 @@
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/git/repository"
20
+ require "dolt/async/when"
21
+
22
+ class FakeGit
23
+ attr_reader :cmds, :deferreds
24
+
25
+ def initialize
26
+ @cmds = []
27
+ @deferreds = []
28
+ end
29
+
30
+ def show(path, ref)
31
+ cmds << ["show", path, ref]
32
+ deferred = When::Deferred.new
33
+ deferreds << deferred.resolver
34
+ deferred.promise
35
+ end
36
+
37
+ def last_command; cmds.last; end
38
+ def last_resolver; deferreds.last; end
39
+ end
40
+
41
+ describe Dolt::Git::Repository do
42
+ before { @git = FakeGit.new }
43
+
44
+ describe "#blob" do
45
+ it "uses git-show to cat file at ref" do
46
+ repo = Dolt::Git::Repository.new("gitorious", @git)
47
+ repo.blob("models/repository.rb", "master")
48
+
49
+ assert_equal ["show", "models/repository.rb", "master"], @git.last_command
50
+ end
51
+
52
+ it "defaults to showing the file at HEAD" do
53
+ repo = Dolt::Git::Repository.new("gitorious", @git)
54
+ repo.blob("models/repository.rb")
55
+
56
+ assert_equal ["show", "models/repository.rb", "HEAD"], @git.last_command
57
+ end
58
+
59
+ it "invokes callback with blob object" do
60
+ repo = Dolt::Git::Repository.new("gitorious", @git)
61
+ d = repo.blob("models/repository.rb")
62
+
63
+ d.callback do |blob|
64
+ assert_equal "class Repository;end", blob.raw
65
+ end
66
+
67
+ @git.last_resolver.resolve("class Repository;end")
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,78 @@
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 "eventmachine"
21
+ require "dolt/git/shell"
22
+
23
+ describe Dolt::Git::Shell do
24
+ include EM::MiniTest::Spec
25
+ include Dolt::StdioStub
26
+
27
+ it "assumes git dir in work tree" do
28
+ expected_cmd = ["git --git-dir /somewhere/.git ",
29
+ "--work-tree /somewhere log"].join
30
+ Dolt::DeferrableChildProcess.expects(:open).with(expected_cmd)
31
+ git = Dolt::Git::Shell.new("/somewhere")
32
+ git.git("log")
33
+ end
34
+
35
+ it "uses provided git dir" do
36
+ expected_cmd = ["git --git-dir /somewhere/.git ",
37
+ "--work-tree /elsewhere log"].join
38
+ Dolt::DeferrableChildProcess.expects(:open).with(expected_cmd)
39
+ git = Dolt::Git::Shell.new("/elsewhere", "/somewhere/.git")
40
+ git.git("log")
41
+ end
42
+
43
+ it "returns deferrable" do
44
+ silence_stderr do
45
+ git = Dolt::Git::Shell.new("/somwhere")
46
+ result = git.git("log")
47
+
48
+ assert result.respond_to?(:callback)
49
+ assert result.respond_to?(:errback)
50
+ end
51
+ end
52
+
53
+ it "joins arguments with spaces" do
54
+ expected_cmd = ["git --git-dir /somewhere/.git ",
55
+ "--work-tree /somewhere push origin master"].join
56
+ Dolt::DeferrableChildProcess.expects(:open).with(expected_cmd)
57
+ git = Dolt::Git::Shell.new("/somewhere")
58
+ git.git("push", "origin", "master")
59
+ end
60
+
61
+ it "calls errback when git operation fails" do
62
+ silence_stderr do
63
+ git = Dolt::Git::Shell.new("/somewhere")
64
+ result = git.git("push", "origin", "master")
65
+ result.errback do |status|
66
+ refute status.nil?
67
+ done!
68
+ end
69
+ wait!
70
+ end
71
+ end
72
+
73
+ it "shows a file" do
74
+ git = Dolt::Git::Shell.new("/somewhere")
75
+ git.expects(:git).with("show", "master:app/models/repository.rb")
76
+ result = git.show("app/models/repository.rb", "master")
77
+ end
78
+ end
@@ -0,0 +1,73 @@
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
+
22
+ class Repository
23
+ attr_reader :name
24
+ def initialize(name); @name = name; end
25
+
26
+ def blob(path, ref)
27
+ @deferred = When::Deferred.new
28
+ @deferred.promise
29
+ end
30
+
31
+ def yield_blob(blob)
32
+ @deferred.resolve(blob)
33
+ end
34
+ end
35
+
36
+ class Resolver
37
+ attr_reader :resolved
38
+ def initialize; @resolved = []; end
39
+
40
+ def resolve(repo)
41
+ repository = Repository.new(repo)
42
+ @resolved << repository
43
+ repository
44
+ end
45
+ end
46
+
47
+ describe Dolt::RepoActions do
48
+ before do
49
+ @resolver = Resolver.new
50
+ @actions = Dolt::RepoActions.new(@resolver)
51
+ end
52
+
53
+ describe "#blob" do
54
+ it "resolves repository" do
55
+ @actions.blob("gitorious", "master", "app")
56
+
57
+ assert_equal ["gitorious"], @resolver.resolved.map(&:name)
58
+ end
59
+
60
+ it "yields blob, repo and ref to block" do
61
+ data = nil
62
+ @actions.blob("gitorious", "babd120", "app") do |status, d|
63
+ data = d
64
+ end
65
+
66
+ repo = @resolver.resolved.last
67
+ repo.yield_blob "Blob"
68
+
69
+ expected = { :blob => "Blob", :repository => repo, :ref => "babd120" }
70
+ assert_equal expected, data
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,81 @@
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/sinatra/actions"
20
+
21
+ class DummySinatraApp
22
+ include Dolt::Sinatra::Actions
23
+ attr_reader :actions, :renderer
24
+
25
+ def initialize(actions, renderer)
26
+ @actions = actions
27
+ @renderer = renderer
28
+ end
29
+
30
+ def body(str = nil)
31
+ @body = str if !str.nil?
32
+ @body
33
+ end
34
+
35
+ def response
36
+ @response ||= {}
37
+ end
38
+ end
39
+
40
+ class Renderer
41
+ def initialize(body = ""); @body = body; end
42
+
43
+ def render(action, data)
44
+ @action = action
45
+ @data = data
46
+ @body
47
+ end
48
+ end
49
+
50
+ class Actions
51
+ attr_reader :repo, :ref, :path
52
+
53
+ def blob(repo, ref, path)
54
+ @repo = repo
55
+ @ref = ref
56
+ @path = path
57
+ yield nil, { :ref => ref, :repository => repo, :blob => "Blob" }
58
+ end
59
+ end
60
+
61
+ describe Dolt::Sinatra::Actions do
62
+ describe "#blob" do
63
+ it "delegates to actions" do
64
+ actions = Actions.new
65
+ app = DummySinatraApp.new(actions, Renderer.new)
66
+ app.blob("gitorious", "master", "app/models/repository.rb")
67
+
68
+ assert_equal "gitorious", actions.repo
69
+ assert_equal "master", actions.ref
70
+ assert_equal "app/models/repository.rb", actions.path
71
+ end
72
+
73
+ it "renders the blob template as html" do
74
+ app = DummySinatraApp.new(Actions.new, Renderer.new("Blob"))
75
+ app.blob("gitorious", "master", "app/models/repository.rb")
76
+
77
+ assert_equal "text/html", app.response["Content-Type"]
78
+ assert_equal "Blob", app.body
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,80 @@
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
+ it "reads template from file" do
28
+ File.expects(:read).with("/dolt/views/file.erb").returns("")
29
+ renderer = Dolt::TemplateRenderer.new("/dolt/views")
30
+ renderer.render(:file)
31
+ end
32
+
33
+ it "renders template with locals" do
34
+ File.stubs(:read).returns("<%= name %>!")
35
+ renderer = Dolt::TemplateRenderer.new("/dolt/views")
36
+
37
+ assert_equal "Chris!", renderer.render(:file, { :name => "Chris"})
38
+ end
39
+
40
+ it "caches template in memory" do
41
+ renderer = Dolt::TemplateRenderer.new("/dolt/views")
42
+ File.stubs(:read).returns("Original")
43
+ renderer.render(:file)
44
+ File.stubs(:read).returns("Updated")
45
+
46
+ assert_equal "Original", renderer.render(:file)
47
+ end
48
+
49
+ it "does not cache template in memory when configured not to" do
50
+ renderer = Dolt::TemplateRenderer.new("/dolt/views", :cache => false)
51
+ File.stubs(:read).returns("Original")
52
+ renderer.render(:file)
53
+ File.stubs(:read).returns("Updated")
54
+
55
+ assert_equal "Updated", renderer.render(:file)
56
+ end
57
+
58
+ it "renders template with layout" do
59
+ renderer = Dolt::TemplateRenderer.new("/", :layout => "layout")
60
+ File.stubs(:read).with("/file.erb").returns("Template")
61
+ File.stubs(:read).with("/layout.erb").returns("I give you: <%= yield %>")
62
+
63
+ assert_equal "I give you: Template", renderer.render(:file)
64
+ end
65
+
66
+ it "renders str templates" do
67
+ renderer = Dolt::TemplateRenderer.new("/", :type => :str)
68
+ File.stubs(:read).with("/file.str").returns("Hey!")
69
+
70
+ assert_equal "Hey!", renderer.render(:file)
71
+ end
72
+
73
+ it "renders with helper module" do
74
+ renderer = Dolt::TemplateRenderer.new("/")
75
+ renderer.helper(ViewHelper)
76
+ File.stubs(:read).with("/file.erb").returns("Say it: <%= say_it %>")
77
+
78
+ assert_equal "Say it: YES", renderer.render(:file)
79
+ end
80
+ end
@@ -0,0 +1,88 @@
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"
20
+
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
43
+
44
+ describe "#highlight" do
45
+ it "highlights a Ruby file" do
46
+ html = highlight("file.rb", "class File\n attr_reader :path\nend")
47
+
48
+ assert_match "<span class=\"k\">class</span>", html
49
+ assert_match "<span class=\"nc\">File</span>", html
50
+ end
51
+
52
+ it "highlights a YAML file" do
53
+ html = highlight("file.yml", "something:\n is: true")
54
+
55
+ assert_match "<span class=\"l-Scalar-Plain\">something</span>", html
56
+ assert_match "<span class=\"p-Indicator\">:", html
57
+ end
58
+
59
+ it "highlights file with custom suffix" do
60
+ Dolt::View::Highlighter.add_lexer_alias("derp", "rb")
61
+ html = highlight("file.derp", "class File")
62
+
63
+ assert_match "<span class=\"k\">class</span>", html
64
+ assert_match "<span class=\"nc\">File</span>", html
65
+ end
66
+
67
+ it "skips highlighting if lexer is missing" do
68
+ html = highlight("file.txt", "Yeah yeah yeah")
69
+
70
+ assert_equal "Yeah yeah yeah", html
71
+ end
72
+ end
73
+
74
+ describe "#highlight_lines" do
75
+ it "highlights a Ruby file with line nums" do
76
+ html = highlight_lines("file.rb", "class File\n attr_reader :path\nend")
77
+
78
+ assert_match "<li class=\"L1\">", html
79
+ assert_match "<span class=\"k\">class</span>", html
80
+ end
81
+
82
+ it "includes lexer as class name" do
83
+ html = highlight_lines("file.rb", "class File\n attr_reader :path\nend")
84
+
85
+ assert_match "rb", html
86
+ end
87
+ end
88
+ end