2
2
require 'camping'
3
3
require 'git'
4
4
5
+ begin
6
+ require 'syntax/convertors/html'
7
+ rescue LoadError
8
+ end
9
+
5
10
# this is meant to be a git-less web head to your git repo
6
11
#
7
12
# install dependencies
@@ -36,6 +41,21 @@ def get
36
41
end
37
42
end
38
43
44
+ class Stylesheet < R '/css/highlight.css'
45
+ def get
46
+ @headers [ 'Content-Type' ] = 'text/css'
47
+ ending = File . read ( __FILE__ ) . gsub ( /.*__END__/m , '' )
48
+ ending . gsub ( /__END__.*/m , '' )
49
+ end
50
+ end
51
+
52
+ class JsHighlight < R '/js/highlight.js'
53
+ def get
54
+ @headers [ 'Content-Type' ] = 'text/css'
55
+ File . read ( __FILE__ ) . gsub ( /.*__JS__/m , '' )
56
+ end
57
+ end
58
+
39
59
class View < R '/view/(\d+)'
40
60
def get repo_id
41
61
@repo = Repository . find repo_id
@@ -139,6 +159,11 @@ def get repo_id, tree1, tree2
139
159
module GitWeb ::Views
140
160
def layout
141
161
html do
162
+ head do
163
+ title 'gitweb'
164
+ #link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css'
165
+ #script :type => "text/javascript", :language => "JavaScript", :src => R(JsHighlight)
166
+ end
142
167
style <<-END , :type => 'text/css'
143
168
body { color: #333; }
144
169
h1 { background: #cce; padding: 10px; margin: 3px; }
@@ -147,6 +172,8 @@ def layout
147
172
p { padding: 5px; }
148
173
.odd { background: #eee; }
149
174
.tag { margin: 5px; padding: 1px 3px; border: 1px solid #8a8; background: #afa;}
175
+ .indent { padding: 0px 15px;}
176
+ .tip { border-top: 1px solid #aaa; color: #666; padding: 10px; }
150
177
END
151
178
body do
152
179
self << yield
@@ -277,17 +304,28 @@ def blob
277
304
end
278
305
279
306
def diff
280
- a . options 'repo' , :href => R ( View , @repo )
281
-
282
- p { a 'patch' , :href => R ( Patch , @repo , @tree1 , @tree2 ) }
283
-
307
+ a . options 'repo' , :href => R ( View , @repo )
284
308
h1 "diff"
285
- p { strong @tree1 + ' : ' + @tree2 }
286
-
309
+
310
+ p { a 'download patch file' , :href => R ( Patch , @repo , @tree1 , @tree2 ) }
311
+
312
+ p do
313
+ a @tree1 , :href => R ( Tree , @repo , @tree1 )
314
+ span . space ' : '
315
+ a @tree2 , :href => R ( Tree , @repo , @tree2 )
316
+ end
317
+
287
318
@diff . each do |file |
288
319
h3 file . path
289
- pre file . patch
320
+ begin
321
+ convertor = Syntax ::Convertors ::HTML . for_syntax "diff"
322
+ self << convertor . convert ( file . patch )
323
+ rescue
324
+ div . indent { pre file . patch }
325
+ div . tip 'tip: if you run "gem install syntax", this will be highlighted'
326
+ end
290
327
end
328
+
291
329
end
292
330
293
331
@@ -329,4 +367,4 @@ def index
329
367
330
368
def GitWeb . create
331
369
GitWeb ::Models . create_schema
332
- end
370
+ end
0 commit comments