dolt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,39 @@
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 "dolt/async/deferrable_child_process"
19
+
20
+ module Dolt
21
+ module Git
22
+ class Shell
23
+ def initialize(work_tree, git_dir = nil)
24
+ @work_tree = work_tree
25
+ @git_dir = git_dir || File.join(work_tree, ".git")
26
+ end
27
+
28
+ def show(path, ref)
29
+ git("show", "#{ref}:#{path}")
30
+ end
31
+
32
+ def git(command, *args)
33
+ base = "git --git-dir #{@git_dir} --work-tree #{@work_tree}"
34
+ cmd = "#{base} #{command} #{args.join(' ')}".strip
35
+ Dolt::DeferrableChildProcess.open(cmd)
36
+ end
37
+ end
38
+ end
39
+ 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 "eventmachine"
19
+
20
+ module Dolt
21
+ class RepoActions
22
+ def initialize(repo_resolver)
23
+ @repo_resolver = repo_resolver
24
+ end
25
+
26
+ def blob(repo, ref, path, &block)
27
+ repository = repo_resolver.resolve(repo)
28
+ d = repository.blob(path, ref)
29
+ d.callback do |blob, status|
30
+ block.call(nil, {
31
+ :blob => blob,
32
+ :repository => repository,
33
+ :ref => ref })
34
+ end
35
+ d.errback { |err| block.call(err, nil) }
36
+ end
37
+
38
+ private
39
+ def repo_resolver; @repo_resolver; end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
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
+ module Dolt
19
+ module Sinatra
20
+ module Actions
21
+ def error(status)
22
+ response["Content-Type"] = "text/plain"
23
+ body("Process failed with exit code \n#{status.exitstatus}")
24
+ end
25
+
26
+ def blob(repo, ref, path)
27
+ actions.blob(repo, ref, path) do |status, data|
28
+ if status.nil?
29
+ response["Content-Type"] = "text/html"
30
+ body(renderer.render(:blob, data))
31
+ else
32
+ error(status)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
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 "sinatra/base"
19
+ require "sinatra/async"
20
+ require "dolt/sinatra/actions"
21
+
22
+ module Dolt
23
+ module Sinatra
24
+ class Base < ::Sinatra::Base
25
+ attr_reader :actions, :renderer
26
+ include Dolt::Sinatra::Actions
27
+ register ::Sinatra::Async
28
+
29
+ def initialize(actions, renderer)
30
+ @actions = actions
31
+ @renderer = renderer
32
+ super()
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
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 "dolt/sinatra/base"
19
+
20
+ module Dolt
21
+ module Sinatra
22
+ class MultiRepoBrowser < Dolt::Sinatra::Base
23
+ aget "/" do
24
+ response["Content-Type"] = "text/html"
25
+ body("<h1>Welcome to Dolt</h1>")
26
+ end
27
+
28
+ aget "/*/blob/*:*" do
29
+ blob(*params[:splat])
30
+ end
31
+
32
+ aget "/*/blob/*" do
33
+ redirect(params[:splat].shift + "/blob/master:" + params[:splat].join)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
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 "dolt/sinatra/base"
19
+
20
+ module Dolt
21
+ module Sinatra
22
+ class SingleRepoBrowser < Dolt::Sinatra::Base
23
+ attr_reader :repo
24
+
25
+ def initialize(repo, actions, renderer)
26
+ @repo = repo
27
+ super(actions, renderer)
28
+ end
29
+
30
+ aget "/" do
31
+ redirect("/blob/master:Readme.md")
32
+ end
33
+
34
+ aget "/blob/*:*" do
35
+ ref, path = params[:splat]
36
+ blob(repo, ref, path)
37
+ end
38
+
39
+ aget "/blob/*" do
40
+ redirect("/blob/master:" + params[:splat].join)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,60 @@
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 "tilt"
19
+
20
+ module Dolt
21
+ class TemplateRenderer
22
+ def initialize(template_root, opt = {})
23
+ @template_root = template_root
24
+ @cache = {} if !opt.key?(:cache) || opt[:cache]
25
+ @layout = opt[:layout]
26
+ @type = opt[:type] || "erb"
27
+ @context_class = Class.new
28
+ end
29
+
30
+ def helper(helper_module)
31
+ @context_class.send(:include, helper_module)
32
+ end
33
+
34
+ def render(template, locals = {})
35
+ context = context_class.new
36
+ content = load(template).render(context, locals)
37
+
38
+ if !layout.nil?
39
+ content = load(layout).render(context, locals) { content }
40
+ end
41
+
42
+ content
43
+ end
44
+
45
+ private
46
+ def load(name)
47
+ file_name = File.join(template_root, "#{name}.#{type}")
48
+ return cache[file_name] if cache && cache[file_name]
49
+ template = Tilt.new(file_name)
50
+ cache[file_name] = template if cache
51
+ template
52
+ end
53
+
54
+ def template_root; @template_root; end
55
+ def cache; @cache; end
56
+ def layout; @layout; end
57
+ def type; @type; end
58
+ def context_class; @context_class; end
59
+ end
60
+ end
@@ -0,0 +1,21 @@
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
+
19
+ module Dolt
20
+ VERSION = "0.1.0"
21
+ end
data/lib/dolt/view.rb ADDED
@@ -0,0 +1,58 @@
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 "dolt/view/breadcrumb"
19
+ require "dolt/view/highlighter"
20
+
21
+ module Dolt
22
+ module View
23
+ def breadcrumb(repository, ref, path)
24
+ Dolt::View::Breadcrumb.new.render(repository, ref, path)
25
+ end
26
+
27
+ def multiline(blob, options = {})
28
+ class_names = options[:class_names] || []
29
+ class_names << "prettyprint" << "linenums"
30
+
31
+ num = 0
32
+ lines = blob.split("\n").inject("") do |html, line|
33
+ num += 1
34
+ "#{html}<li class=\"L#{num}\"><span class=\"line\">#{line}</span></li>"
35
+ end
36
+
37
+ "<pre class=\"#{class_names.join(' ')}\">" +
38
+ "<ol class=\"linenums\">#{lines}</ol></pre>"
39
+ end
40
+
41
+ def highlight(path, code, options = {})
42
+ lexer = lexer_for_file(path)
43
+ Dolt::View::Highlighter.new(options).highlight(code, lexer)
44
+ rescue RubyPython::PythonError
45
+ code
46
+ end
47
+
48
+ def highlight_lines(path, code, options = {})
49
+ lexer = lexer_for_file(path)
50
+ multiline(highlight(path, code, options), :class_names => [lexer])
51
+ end
52
+
53
+ def lexer_for_file(path)
54
+ suffix = path.split(".").pop
55
+ Dolt::View::Highlighter.lexer(suffix)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,45 @@
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
+ module Dolt
19
+ module View
20
+ class Breadcrumb
21
+ def render(repository, ref, path)
22
+ dirs = path.split("/")
23
+ filename = dirs.pop
24
+ dir_html = accumulate_dirs(dirs, repository.name, ref)
25
+ <<-HTML
26
+ <ul class="breadcrumb">
27
+ <li><a href="/files"><i class="icon icon-file"></i></a></li>
28
+ #{dir_html}<li class="active">#{filename}</li>
29
+ </ul>
30
+ HTML
31
+ end
32
+
33
+ private
34
+ def accumulate_dirs(dirs, repo, ref)
35
+ accumulated = []
36
+ dir_html = dirs.inject("") do |html, dir|
37
+ accumulated << dir
38
+ "#{html}<li><a href=\"/#{repo}/tree/#{ref}:#{accumulated.join('/')}\">" +
39
+ "#{dir}<span class=\"divider\">/</span></a></li>"
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -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 "pygments"
19
+
20
+ module Dolt
21
+ module View
22
+ class Highlighter
23
+ def initialize(options = {})
24
+ @options = options
25
+ options[:options] ||= {}
26
+ options[:options][:nowrap] = true
27
+ options[:options][:encoding] = options[:options][:encoding]|| "utf-8"
28
+ end
29
+
30
+ def highlight(code, lexer)
31
+ Pygments.highlight(code, options.merge(:lexer => lexer))
32
+ end
33
+
34
+ def self.lexer(suffix)
35
+ @@lexer_aliases[suffix] || suffix
36
+ end
37
+
38
+ def self.add_lexer_alias(extension, lexer)
39
+ @@lexer_aliases ||= {}
40
+ @@lexer_aliases[extension] = lexer
41
+ end
42
+
43
+ private
44
+ def options; @options; end
45
+ end
46
+ end
47
+ end
48
+
49
+ Dolt::View::Highlighter.add_lexer_alias("yml", "yaml")