libdolt 0.6.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 (68) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +56 -0
  3. data/Rakefile +10 -0
  4. data/Readme.md +99 -0
  5. data/lib/libdolt/async/when.rb +128 -0
  6. data/lib/libdolt/disk_repo_resolver.rb +39 -0
  7. data/lib/libdolt/git/blame.rb +112 -0
  8. data/lib/libdolt/git/commit.rb +73 -0
  9. data/lib/libdolt/git/repository.rb +139 -0
  10. data/lib/libdolt/git/submodule.rb +35 -0
  11. data/lib/libdolt/git/tree.rb +42 -0
  12. data/lib/libdolt/repo_actions.rb +95 -0
  13. data/lib/libdolt/version.rb +21 -0
  14. data/lib/libdolt/view/binary_blob_embedder.rb +41 -0
  15. data/lib/libdolt/view/blame.rb +57 -0
  16. data/lib/libdolt/view/blob.rb +97 -0
  17. data/lib/libdolt/view/breadcrumb.rb +47 -0
  18. data/lib/libdolt/view/commit.rb +27 -0
  19. data/lib/libdolt/view/gravatar.rb +29 -0
  20. data/lib/libdolt/view/markup.rb +44 -0
  21. data/lib/libdolt/view/multi_repository.rb +27 -0
  22. data/lib/libdolt/view/object.rb +44 -0
  23. data/lib/libdolt/view/single_repository.rb +27 -0
  24. data/lib/libdolt/view/smart_blob_renderer.rb +33 -0
  25. data/lib/libdolt/view/syntax_highlight.rb +40 -0
  26. data/lib/libdolt/view/tab_width.rb +30 -0
  27. data/lib/libdolt/view/tree.rb +100 -0
  28. data/lib/libdolt/view.rb +23 -0
  29. data/lib/libdolt.rb +29 -0
  30. data/libdolt.gemspec +35 -0
  31. data/test/libdolt/async/when_test.rb +112 -0
  32. data/test/libdolt/git/blame_test.rb +128 -0
  33. data/test/libdolt/git/commit_test.rb +89 -0
  34. data/test/libdolt/git/repository_test.rb +186 -0
  35. data/test/libdolt/repo_actions_test.rb +236 -0
  36. data/test/libdolt/templates/blame_test.rb +54 -0
  37. data/test/libdolt/templates/blob_test.rb +116 -0
  38. data/test/libdolt/templates/commits_test.rb +59 -0
  39. data/test/libdolt/templates/raw_test.rb +39 -0
  40. data/test/libdolt/templates/refs_test.rb +36 -0
  41. data/test/libdolt/templates/tree_history_test.rb +91 -0
  42. data/test/libdolt/templates/tree_test.rb +63 -0
  43. data/test/libdolt/view/binary_blob_embedder_test.rb +49 -0
  44. data/test/libdolt/view/blame_test.rb +122 -0
  45. data/test/libdolt/view/blob_test.rb +116 -0
  46. data/test/libdolt/view/breadcrumb_test.rb +46 -0
  47. data/test/libdolt/view/commit_test.rb +31 -0
  48. data/test/libdolt/view/gravatar_test.rb +30 -0
  49. data/test/libdolt/view/markup_test.rb +70 -0
  50. data/test/libdolt/view/multi_repository_test.rb +35 -0
  51. data/test/libdolt/view/object_test.rb +83 -0
  52. data/test/libdolt/view/single_repository_test.rb +30 -0
  53. data/test/libdolt/view/smart_blob_renderer_test.rb +38 -0
  54. data/test/libdolt/view/syntax_highlight_test.rb +80 -0
  55. data/test/libdolt/view/tab_width_test.rb +40 -0
  56. data/test/libdolt/view/tree_test.rb +196 -0
  57. data/test/test_helper.rb +50 -0
  58. data/views/500.erb +22 -0
  59. data/views/blame.erb +42 -0
  60. data/views/blob.erb +31 -0
  61. data/views/commits.erb +26 -0
  62. data/views/index.erb +25 -0
  63. data/views/layout.erb +45 -0
  64. data/views/raw.erb +19 -0
  65. data/views/refs.erb +22 -0
  66. data/views/tree.erb +50 -0
  67. data/views/tree_history.erb +19 -0
  68. metadata +326 -0
@@ -0,0 +1,42 @@
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
+ module Git
21
+ class Tree
22
+ attr_reader :oid, :entries
23
+ include Enumerable
24
+
25
+ def initialize(oid, entries)
26
+ @oid = oid
27
+ @entries = entries
28
+ end
29
+
30
+ def each(&block)
31
+ entries.each(&block)
32
+ end
33
+
34
+ # From Rugged::Tree
35
+ def inspect
36
+ data = "#<Dolt::Git::Tree:#{object_id} {oid: #{oid}}>\n"
37
+ self.each { |e| data << " <\"#{e[:name]}\" #{e[:oid]}>\n" }
38
+ data
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,95 @@
1
+
2
+ # encoding: utf-8
3
+ #--
4
+ # Copyright (C) 2012 Gitorious AS
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require "eventmachine"
20
+
21
+ # Need consistent Time formatting in JSON
22
+ require "time"
23
+ class Time; def to_json(*args); "\"#{iso8601}\""; end; end
24
+
25
+ module Dolt
26
+ class RepoActions
27
+ def initialize(repo_resolver)
28
+ @repo_resolver = repo_resolver
29
+ end
30
+
31
+ def blob(repo, ref, path, &block)
32
+ repo_action(repo, ref, path, :blob, :rev_parse, "#{ref}:#{path}", &block)
33
+ end
34
+
35
+ def tree(repo, ref, path, &block)
36
+ repo_action(repo, ref, path, :tree, :tree, ref, path, &block)
37
+ end
38
+
39
+ def blame(repo, ref, path, &block)
40
+ repo_action(repo, ref, path, :blame, :blame, ref, path, &block)
41
+ end
42
+
43
+ def history(repo, ref, path, count, &block)
44
+ repo_action(repo, ref, path, :commits, :log, ref, path, count, &block)
45
+ end
46
+
47
+ def refs(repo, &block)
48
+ repository = repo_resolver.resolve(repo)
49
+ d = repository.refs
50
+ d.callback do |refs|
51
+ names = refs.map(&:name)
52
+ block.call(nil, {
53
+ :repository => repo,
54
+ :tags => stripped_ref_names(names, :tags),
55
+ :heads => stripped_ref_names(names, :heads)
56
+ })
57
+ end
58
+ d.errback { |err| block.call(err, nil) }
59
+ end
60
+
61
+ def tree_history(repo, ref, path, count, &block)
62
+ repo_action(repo, ref, path, :tree, :tree_history, ref, path, count, &block)
63
+ end
64
+
65
+ def repositories
66
+ repo_resolver.all
67
+ end
68
+
69
+ private
70
+ def repo_resolver; @repo_resolver; end
71
+
72
+ def repo_action(repo, ref, path, data, method, *args, &block)
73
+ repository = repo_resolver.resolve(repo)
74
+ d = repository.send(method, *args)
75
+ d.callback do |result|
76
+ block.call(nil, tpl_data(repo, ref, path, { data => result }))
77
+ end
78
+ d.errback { |err| block.call(err, nil) }
79
+ end
80
+
81
+ def tpl_data(repo, ref, path, locals = {})
82
+ {
83
+ :repository => repo,
84
+ :path => path,
85
+ :ref => ref
86
+ }.merge(locals)
87
+ end
88
+
89
+ def stripped_ref_names(names, type)
90
+ names.select { |n| n =~ /#{type}/ }.map do |n|
91
+ n.sub(/^refs\/#{type}\//, "")
92
+ end
93
+ end
94
+ end
95
+ 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.6.0"
21
+ 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 "mime/types"
19
+
20
+ module Dolt
21
+ module View
22
+ module BinaryBlobEmbedder
23
+ def image?(path, content)
24
+ MIME::Types.type_for(path).any? { |mt| mt.media_type == "image" }
25
+ end
26
+
27
+ def format_binary_blob(path, content, repository, ref)
28
+ if !image?(path, content)
29
+ return link_binary_blob(path, content, repository, ref)
30
+ end
31
+
32
+ url = raw_url(repository, ref, path)
33
+ <<-HTML
34
+ <p class="prettyprint">
35
+ <a href="#{url}"><img src="#{url}" alt="#{path}"></a>
36
+ </p>
37
+ HTML
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,57 @@
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
+ module View
21
+ module Blame
22
+ def blame_annotations(blame)
23
+ blame.chunks.inject([]) do |blames, chunk|
24
+ blames << chunk
25
+ (chunk[:lines].length - 1).times { blames << nil }
26
+ blames
27
+ end
28
+ end
29
+
30
+ def blame_lines(path, blame)
31
+ lines = blame.chunks.inject([]) do |lines, chunk|
32
+ lines.concat(chunk[:lines])
33
+ end
34
+
35
+ return lines unless respond_to?(:highlight)
36
+ highlight(path, lines.join("\n")).split("\n")
37
+ end
38
+
39
+ def blame_annotation_cell(annotation)
40
+ class_name = "gts-blame-annotation" + (annotation.nil? ? "" : " gts-annotated")
41
+ return "<td class=\"#{class_name}\"></td>" if annotation.nil?
42
+
43
+ <<-HTML
44
+ <td class="#{class_name}">
45
+ <span class="gts-sha">#{annotation[:oid][0..7]}</span>
46
+ #{annotation[:committer][:time].strftime("%Y-%m-%d")}
47
+ #{annotation[:committer][:name]}
48
+ </td>
49
+ HTML
50
+ end
51
+
52
+ def blame_code_cell(line)
53
+ "<td class=\"gts-code\"><code>#{line}</code></td>"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,97 @@
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 "htmlentities"
19
+
20
+ module Dolt
21
+ module View
22
+ module Blob
23
+ def binary?(content)
24
+ !content[0...(content.length-1)].index("\000").nil?
25
+ end
26
+
27
+ def entityfy(content)
28
+ @coder ||= HTMLEntities.new
29
+ @coder.encode(content)
30
+ end
31
+
32
+ def format_blob(path, content, repo = nil, ref = nil)
33
+ return format_binary_blob(path, content, repo, ref) if binary?(content)
34
+ format_text_blob(path, content, repo, ref)
35
+ end
36
+
37
+ def format_binary_blob(path, content, repository = nil, ref = nil)
38
+ link_binary_blob(path, content, repository, ref)
39
+ end
40
+
41
+ def link_binary_blob(path, content, repository = nil, ref = nil)
42
+ <<-HTML
43
+ <p class="prettyprint">
44
+ The content you're attempting to browse appears to be binary.
45
+ <a href="#{raw_url(repository, ref, path)}">Download #{File.basename(path)}</a>.
46
+ </p>
47
+ HTML
48
+ end
49
+
50
+ def format_text_blob(path, content, repository = nil, ref = nil)
51
+ multiline(entityfy(content))
52
+ end
53
+
54
+ def blob_url(repository, ref, path)
55
+ repo_url(repository, "/blob/#{ref}:#{path}")
56
+ end
57
+
58
+ def blame_url(repository, ref, path)
59
+ repo_url(repository, "/blame/#{ref}:#{path}")
60
+ end
61
+
62
+ def history_url(repository, ref, path)
63
+ repo_url(repository, "/history/#{ref}:#{path}")
64
+ end
65
+
66
+ def raw_url(repository, ref, path)
67
+ repo_url(repository, "/raw/#{ref}:#{path}")
68
+ end
69
+
70
+ def tree_history_url(repository, ref, path)
71
+ repo_url(repository, "/tree_history/#{ref}:#{path}")
72
+ end
73
+
74
+ def format_whitespace(text)
75
+ text
76
+ end
77
+
78
+ def multiline(blob, options = {})
79
+ class_names = options[:class_names] || []
80
+ class_names << "prettyprint" << "linenums"
81
+
82
+ num = 0
83
+ lines = blob.split("\n").inject("") do |html, line|
84
+ num += 1
85
+ # Empty elements causes annoying rendering artefacts
86
+ # Forcing one space on each line affects copy-paste negatively
87
+ # TODO: Don't force one space, find CSS fix
88
+ line = format_whitespace(line).sub(/^$/, " ")
89
+ "#{html}<li class=\"L#{num}\"><span class=\"line\">#{line}</span></li>"
90
+ end
91
+
92
+ "<pre class=\"#{class_names.join(' ')}\">" +
93
+ "<ol class=\"linenums\">#{lines}</ol></pre>"
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,47 @@
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
+ module View
21
+ module Breadcrumb
22
+ def breadcrumb(repository, ref, path)
23
+ dirs = path.split("/")
24
+ filename = dirs.pop
25
+ dir_html = accumulate_dirs(dirs, repository, ref)
26
+ url = repo_url(repository, "/tree/#{ref}")
27
+ <<-HTML
28
+ <ul class="breadcrumb">
29
+ <li><a href="#{url}:"><i class="icon icon-file"></i> /</a></li>
30
+ #{dir_html}<li class="active">#{filename}</li>
31
+ </ul>
32
+ HTML
33
+ end
34
+
35
+ private
36
+ def accumulate_dirs(dirs, repository, ref)
37
+ accumulated = []
38
+ divider = "<span class=\"divider\">/</span>"
39
+ dir_html = dirs.inject("") do |html, dir|
40
+ accumulated << dir
41
+ url = repo_url(repository, "/tree/#{ref}:#{accumulated.join('/')}")
42
+ "#{html}<li><a href=\"#{url}\">#{dir}#{divider}</a></li>"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
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
+ module View
21
+ module Commit
22
+ def commit_oid(oid)
23
+ oid[0...7]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
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 'digest/md5'
19
+
20
+ module Dolt
21
+ module View
22
+ module Gravatar
23
+ def gravatar(email)
24
+ hashed = Digest::MD5.hexdigest(email.downcase)
25
+ "http://www.gravatar.com/avatar/#{hashed}"
26
+ end
27
+ end
28
+ end
29
+ 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 "makeup/markup"
19
+ require "makeup/syntax_highlighter"
20
+
21
+ module Dolt
22
+ module View
23
+ module Markup
24
+ def render_markup(path, content)
25
+ "<div class=\"gts-markup\">#{markuper.render(path, content)}</div>"
26
+ end
27
+
28
+ def supported_markup_format?(path)
29
+ Makeup::Markup.can_render?(path)
30
+ end
31
+
32
+ def format_text_blob(path, code, repo = nil, ref = nil)
33
+ render_markup(path, code)
34
+ end
35
+
36
+ private
37
+ def markuper
38
+ return @markuper if @markuper
39
+ highlighter = Makeup::SyntaxHighlighter.new
40
+ @markuper = Makeup::Markup.new(:highlighter => highlighter)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
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
+ module View
21
+ module MultiRepository
22
+ def repo_url(repository, url)
23
+ "/#{repository}#{url}"
24
+ end
25
+ end
26
+ end
27
+ 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
+
19
+ module Dolt
20
+ module View
21
+ module Object
22
+ def object_url(repository, ref, path, object)
23
+ return object[:url] if object[:type] == :submodule
24
+ url = "/#{object[:type]}/#{ref}:#{object_path(path, object)}"
25
+ repo_url(repository, url)
26
+ end
27
+
28
+ def object_path(root, object)
29
+ File.join(root, object[:name]).sub(/^\//, "")
30
+ end
31
+
32
+ def object_icon_class(entry)
33
+ case entry[:type]
34
+ when :blob
35
+ "icon-file"
36
+ when :tree
37
+ "icon-folder-close"
38
+ when :submodule
39
+ "icon-hdd"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
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
+ module View
21
+ module SingleRepository
22
+ def repo_url(repository, url)
23
+ url
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
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 "libdolt/view/syntax_highlight"
19
+ require "libdolt/view/markup"
20
+
21
+ module Dolt
22
+ module View
23
+ module SmartBlobRenderer
24
+ include Dolt::View::Markup
25
+ include Dolt::View::SyntaxHighlight
26
+
27
+ def format_text_blob(path, content, repo = nil, ref = nil, options = {})
28
+ return render_markup(path, content) if supported_markup_format?(path)
29
+ highlight_multiline(path, content, options)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8 -- Copyright (C) 2012 Gitorious AS
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Affero General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Affero General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #++
16
+ require "makeup/syntax_highlighter"
17
+
18
+ module Dolt
19
+ module View
20
+ module SyntaxHighlight
21
+ def highlighter
22
+ @highlighter ||= Makeup::SyntaxHighlighter.new
23
+ end
24
+
25
+ def highlight(path, code, options = {})
26
+ highlighter.highlight(path, code, options).code
27
+ end
28
+
29
+ def highlight_multiline(path, code, options = {})
30
+ return highlight(path, code, options) unless respond_to?(:multiline)
31
+ res = highlighter.highlight(path, code, options)
32
+ multiline(res.code, :class_names => [res.lexer])
33
+ end
34
+
35
+ def format_text_blob(path, code, repo = nil, ref = nil, options = {})
36
+ highlight_multiline(path, code, options)
37
+ end
38
+ end
39
+ end
40
+ end