dolt 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dolt (0.2.0)
4
+ dolt (0.2.1)
5
5
  async_sinatra (~> 1.0)
6
6
  builder (~> 3.1)
7
7
  em_pessimistic (~> 0.1)
@@ -9,6 +9,7 @@ PATH
9
9
  eventmachine (~> 1.0)
10
10
  github-markup (~> 0.7)
11
11
  htmlentities (~> 4.3)
12
+ json (~> 1.7)
12
13
  pygments.rb (~> 0.2)
13
14
  sinatra (~> 1.3)
14
15
  thin (~> 1.4)
@@ -28,13 +29,14 @@ GEM
28
29
  eventmachine
29
30
  em_pessimistic (0.1.2)
30
31
  eventmachine (~> 1.0)
31
- em_rugged (0.1.2)
32
+ em_rugged (0.1.3)
32
33
  eventmachine (~> 1.0)
33
34
  rugged (= 0.17.0.b6)
34
35
  eventmachine (1.0.0)
35
36
  ffi (1.0.11)
36
37
  github-markup (0.7.4)
37
38
  htmlentities (4.3.1)
39
+ json (1.7.5)
38
40
  metaclass (0.0.1)
39
41
  minitest (2.12.1)
40
42
  mocha (0.12.4)
data/bin/dolt CHANGED
@@ -51,6 +51,8 @@ view.helper(Dolt::View::Breadcrumb)
51
51
  view.helper(Dolt::View::Tree)
52
52
  view.helper(Dolt::View::Commit)
53
53
  view.helper(Dolt::View::Gravatar)
54
+ Dolt::View::TabWidth.tab_width = 4
55
+ view.helper(Dolt::View::TabWidth)
54
56
 
55
57
  # Configure blob rendering module
56
58
 
data/dolt.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.add_dependency "tzinfo", "~> 0.3"
34
34
  s.add_dependency "github-markup", "~> 0.7"
35
35
  s.add_dependency "htmlentities", "~> 4.3"
36
+ s.add_dependency "json", "~> 1.7"
36
37
 
37
38
  s.add_development_dependency "minitest", "~> 2.0"
38
39
  s.add_development_dependency "em-minitest-spec", "~> 1.1"
@@ -39,6 +39,20 @@ module Dolt
39
39
  repo_action(repo, ref, path, :commits, :log, ref, path, count, &block)
40
40
  end
41
41
 
42
+ def refs(repo, &block)
43
+ repository = repo_resolver.resolve(repo)
44
+ d = repository.refs
45
+ d.callback do |refs|
46
+ names = refs.map(&:name)
47
+ block.call(nil, {
48
+ :repository => repo,
49
+ :tags => stripped_ref_names(names, :tags),
50
+ :heads => stripped_ref_names(names, :heads)
51
+ })
52
+ end
53
+ d.errback { |err| block.call(err, nil) }
54
+ end
55
+
42
56
  def repositories
43
57
  repo_resolver.all
44
58
  end
@@ -62,5 +76,11 @@ module Dolt
62
76
  :ref => ref
63
77
  }.merge(locals)
64
78
  end
79
+
80
+ def stripped_ref_names(names, type)
81
+ names.select { |n| n =~ /#{type}/ }.map do |n|
82
+ n.sub(/^refs\/#{type}\//, "")
83
+ end
84
+ end
65
85
  end
66
86
  end
@@ -77,6 +77,14 @@ module Dolt
77
77
  body(renderer.render(:commits, data))
78
78
  end
79
79
  end
80
+
81
+ def refs(repo)
82
+ actions.refs(repo) do |err, data|
83
+ return error(err) if !err.nil?
84
+ response["Content-Type"] = "application/json"
85
+ body(renderer.render(:refs, data, :layout => nil))
86
+ end
87
+ end
80
88
  end
81
89
  end
82
90
  end
@@ -68,6 +68,10 @@ module Dolt
68
68
  force_ref(params[:splat], "blame", "master")
69
69
  end
70
70
 
71
+ aget "/*/refs" do
72
+ refs(params[:splat].first)
73
+ end
74
+
71
75
  private
72
76
  def force_ref(args, action, ref)
73
77
  redirect(args.shift + "/#{action}/#{ref}:" + args.join)
@@ -82,6 +82,10 @@ module Dolt
82
82
  force_ref(params[:splat], "blame", "master")
83
83
  end
84
84
 
85
+ aget "/refs" do
86
+ refs(repo)
87
+ end
88
+
85
89
  private
86
90
  def force_ref(args, action, ref)
87
91
  redirect("/#{action}/#{ref}:" + args.join)
data/lib/dolt/version.rb CHANGED
@@ -17,5 +17,5 @@
17
17
  #++
18
18
 
19
19
  module Dolt
20
- VERSION = "0.2.1"
20
+ VERSION = "0.2.2"
21
21
  end
@@ -20,9 +20,13 @@ require "htmlentities"
20
20
  module Dolt
21
21
  module View
22
22
  module Blob
23
- def format_blob(path, content)
23
+ def entityfy(content)
24
24
  @coder ||= HTMLEntities.new
25
- multiline(@coder.encode(content))
25
+ @coder.encode(content)
26
+ end
27
+
28
+ def format_blob(path, content)
29
+ multiline(entityfy(content))
26
30
  end
27
31
 
28
32
  def blob_url(repository, ref, path)
@@ -41,6 +45,10 @@ module Dolt
41
45
  repo_url(repository, "/raw/#{ref}:#{path}")
42
46
  end
43
47
 
48
+ def format_whitespace(text)
49
+ text
50
+ end
51
+
44
52
  def multiline(blob, options = {})
45
53
  class_names = options[:class_names] || []
46
54
  class_names << "prettyprint" << "linenums"
@@ -48,7 +56,10 @@ module Dolt
48
56
  num = 0
49
57
  lines = blob.split("\n").inject("") do |html, line|
50
58
  num += 1
51
- line = line.gsub(/\t/, " ")
59
+ # Empty elements causes annoying rendering artefacts
60
+ # Forcing one space on each line affects copy-paste negatively
61
+ # TODO: Don't force one space, find CSS fix
62
+ line = format_whitespace(line).sub(/^$/, " ")
52
63
  "#{html}<li class=\"L#{num}\"><span class=\"line\">#{line}</span></li>"
53
64
  end
54
65
 
@@ -24,7 +24,7 @@ module Dolt
24
24
  options = { :lexer => lexer(path, code) }.merge(opt)
25
25
  Pygments.highlight(code, highlight_options(options))
26
26
  rescue RubyPython::PythonError
27
- code
27
+ respond_to?(:entityfy) ? entityfy(code) : code
28
28
  end
29
29
 
30
30
  def highlight_multiline(path, code, options = {})
@@ -78,6 +78,7 @@ module Dolt
78
78
  end
79
79
 
80
80
  Dolt::View::SyntaxHighlight.add_lexer_alias("yml", "yaml")
81
+ Dolt::View::SyntaxHighlight.add_lexer_alias("ru", "rb")
81
82
  Dolt::View::SyntaxHighlight.add_lexer_alias("Rakefile", "rb")
82
83
  Dolt::View::SyntaxHighlight.add_lexer_alias("Gemfile", "rb")
83
84
  Dolt::View::SyntaxHighlight.add_lexer_alias("Gemfile.lock", "yaml")
@@ -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
+
19
+ module Dolt
20
+ module View
21
+ module TabWidth
22
+ def self.tab_width; @@tab_width; end
23
+ def self.tab_width=(tab_width); @@tab_width = tab_width; end
24
+
25
+ def format_whitespace(text)
26
+ text.gsub(/\t/, " " * TabWidth.tab_width)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -18,29 +18,25 @@
18
18
  require "test_helper"
19
19
  require "dolt/repo_actions"
20
20
  require "dolt/async/when"
21
+ require "ostruct"
21
22
 
22
23
  class Repository
23
24
  attr_reader :name
24
25
  def initialize(name); @name = name; end
26
+ def rev_parse(rev); stub; end
27
+ def blame(ref, path); stub; end
28
+ def log(ref, path, limit); stub; end
29
+ def refs; stub; end
25
30
 
26
- def rev_parse(rev)
27
- @deferred = When::Deferred.new
28
- @deferred.promise
29
- end
30
-
31
- def blame(ref, path)
32
- @deferred = When::Deferred.new
33
- @deferred.promise
31
+ def resolve_promise(blob)
32
+ @deferred.resolve(blob)
34
33
  end
35
34
 
36
- def log(ref, path, limit)
35
+ private
36
+ def stub
37
37
  @deferred = When::Deferred.new
38
38
  @deferred.promise
39
39
  end
40
-
41
- def resolve_promise(blob)
42
- @deferred.resolve(blob)
43
- end
44
40
  end
45
41
 
46
42
  class Resolver
@@ -161,4 +157,30 @@ describe Dolt::RepoActions do
161
157
  assert_equal expected, data
162
158
  end
163
159
  end
160
+
161
+ describe "#refs" do
162
+ before do
163
+ @refs = ["refs/stash",
164
+ "refs/tags/v0.2.1",
165
+ "refs/tags/v0.2.0",
166
+ "refs/remotes/origin/master",
167
+ "refs/heads/libgit2",
168
+ "refs/heads/master"].map { |n| OpenStruct.new(:name => n) }
169
+ end
170
+
171
+ it "yields repositories, tags and heads" do
172
+ data = nil
173
+ @actions.refs("gitorious") { |err, d| data = d }
174
+
175
+ repo = @resolver.resolved.last
176
+ repo.resolve_promise(@refs)
177
+
178
+ expected = {
179
+ :repository => "gitorious",
180
+ :heads => ["libgit2", "master"],
181
+ :tags => ["v0.2.1", "v0.2.0"]
182
+ }
183
+ assert_equal expected, data
184
+ end
185
+ end
164
186
  end
@@ -99,6 +99,10 @@ class Actions
99
99
  respond(:history, repo, ref, path, &block)
100
100
  end
101
101
 
102
+ def refs(repo, &block)
103
+ respond(:refs, repo, nil, nil, &block)
104
+ end
105
+
102
106
  def respond(type, repo, ref, path, &block)
103
107
  @repo = repo
104
108
  @ref = ref
@@ -210,7 +214,7 @@ describe Dolt::Sinatra::Actions do
210
214
  assert_equal "app/models/repository.rb", actions.path
211
215
  end
212
216
 
213
- it "renders the blame template as text" do
217
+ it "renders the blame template as html" do
214
218
  app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Text"))
215
219
  app.blame("gitorious", "master", "app/models/repository.rb")
216
220
 
@@ -230,7 +234,7 @@ describe Dolt::Sinatra::Actions do
230
234
  assert_equal "app/models/repository.rb", actions.path
231
235
  end
232
236
 
233
- it "renders the commits template as text" do
237
+ it "renders the commits template as html" do
234
238
  app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Text"))
235
239
  app.history("gitorious", "master", "app/models/repository.rb", 10)
236
240
 
@@ -238,4 +242,14 @@ describe Dolt::Sinatra::Actions do
238
242
  assert_equal "commits:Text", app.body
239
243
  end
240
244
  end
245
+
246
+ describe "#refs" do
247
+ it "renders the refs template as json" do
248
+ app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("JSON"))
249
+ app.refs("gitorious")
250
+
251
+ assert_equal "application/json", app.response["Content-Type"]
252
+ assert_equal "refs:JSON", app.body
253
+ end
254
+ end
241
255
  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
+ require "test_helper"
19
+ require "dolt/template_renderer"
20
+ require "dolt/view"
21
+ require "json"
22
+
23
+ describe "refs template" do
24
+ include Dolt::ViewTest
25
+
26
+ before do
27
+ @repo = "the-dolt"
28
+ @template_root = File.join(File.dirname(__FILE__), "..", "..", "..", "views")
29
+ @renderer = prepare_renderer(@template_root)
30
+ end
31
+
32
+ it "renders JSON" do
33
+ data = { "heads" => ["libgit2", "master"], "tags" => ["v2.1.0"] }
34
+ html = @renderer.render(:refs, data)
35
+
36
+ assert_equal data, JSON.parse(html)
37
+ end
38
+ 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
+ require "test_helper"
19
+ require "dolt/view/smart_blob_renderer"
20
+
21
+ describe Dolt::View::SmartBlobRenderer do
22
+ include Dolt::View::Blob
23
+ include Dolt::View::SmartBlobRenderer
24
+
25
+ describe "#format_blob" do
26
+ it "highlights a Ruby file" do
27
+ html = format_blob("file.rb", "class File\n attr_reader :path\nend")
28
+
29
+ assert_match "<span class=\"k\">class</span>", html
30
+ assert_match "<span class=\"nc\">File</span>", html
31
+ end
32
+
33
+ it "wraps markup in .gts-markup" do
34
+ html = render_markup("file.md", "# Hey")
35
+ assert_match "<div class=\"gts-markup\">", html
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
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/tab_width"
20
+
21
+ describe Dolt::View::TabWidth do
22
+ include Dolt::View::Blob
23
+ include Dolt::View::TabWidth
24
+
25
+ describe "#format_whitespace" do
26
+ it "limits width of whitespace" do
27
+ Dolt::View::TabWidth.tab_width = 4
28
+ html = format_whitespace("class File\n\tattr_reader :path\nend")
29
+
30
+ assert_match(/ attr_reader/, html)
31
+ end
32
+
33
+ it "uses wide tabs in formatted blobs" do
34
+ Dolt::View::TabWidth.tab_width = 12
35
+ html = format_blob("file.rb", "class File\n\tattr_reader :path\nend")
36
+
37
+ assert_match(/ attr_reader/, html)
38
+ end
39
+ end
40
+ end