gitdocs 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,8 @@
1
- 0.4.9 (12/29/2011)
1
+ 0.4.10 (12/30/2011)
2
+
3
+ * View revision history on the web front-end!
4
+
5
+ 0.4.9 (12/30/2011)
2
6
 
3
7
  * Adds configuration for web port in settings
4
8
  * Adds support for 'add' and 'remove' shares in settings
@@ -42,12 +42,22 @@ GitDocs = {
42
42
  var el = $('.content').prepend('<div class="alert-message ' + result +
43
43
  '"><a class="close" href="#">×</a>' + body + '</div>');
44
44
  $('div.alert-message').alert();
45
+ },
46
+ // converts iso8601 dates tagged with .reldate to relative
47
+ convertRelativeTimes : function() {
48
+ $('.reldate').each(function(ind, el) {
49
+ if ($(el).data("iso")) return;
50
+ var iso = $(el).text();
51
+ $(el).data("iso", iso);
52
+ $(el).text(RelativeDate.time_ago_in_words(iso));
53
+ });
45
54
  }
46
55
  };
47
56
 
48
57
  $(document).ready(function() {
49
58
  GitDocs.linkBreadcrumbs();
50
59
  GitDocs.fillDirMeta();
60
+ GitDocs.convertRelativeTimes();
51
61
  StringFormatter.autoLink();
52
62
  });
53
63
 
@@ -140,11 +140,15 @@ module Gitdocs
140
140
  end
141
141
 
142
142
  IGNORED_FILES = ['.gitignore']
143
+ # Returns the list of files in a given directory
143
144
  # dir_files("some/dir") => [<Docfile>, <Docfile>]
144
145
  def dir_files(dir_path)
145
146
  Dir[File.join(dir_path, "*")].to_a.map { |path| Docfile.new(path) }
146
147
  end
147
148
 
149
+ # Returns file meta data based on relative file path
150
+ # file_meta("path/to/file")
151
+ # => { :author => "Nick", :size => 1000, :modified => ... }
148
152
  def file_meta(file)
149
153
  result = {}
150
154
  file = file.gsub(%r{^/}, '')
@@ -158,6 +162,28 @@ module Gitdocs
158
162
  result
159
163
  end
160
164
 
165
+ # Returns the revisions available for a particular file
166
+ # file_revisions("README")
167
+ def file_revisions(file)
168
+ file = file.gsub(%r{^/}, '')
169
+ output = sh_string("git log --format='%h|%s|%aN|%ai' -n100 #{ShellTools.escape(file)}")
170
+ output.to_s.split("\n").map do |log_result|
171
+ commit, subject, author, date = log_result.split("|")
172
+ date = Time.parse(date.sub(' ', 'T')).utc.iso8601
173
+ { :commit => commit, :subject => subject, :author => author, :date => date }
174
+ end
175
+ end
176
+
177
+ # Returns the temporary path of a particular revision of a file
178
+ # file_revision_at("README", "a4c56h") => "/tmp/some/path/README"
179
+ def file_revision_at(file, ref)
180
+ file = file.gsub(%r{^/}, '')
181
+ content = sh_string("git show #{ref}:#{ShellTools.escape(file)}")
182
+ tmp_path = File.expand_path(File.basename(file), Dir.tmpdir)
183
+ File.open(tmp_path, 'w') { |f| f.puts content }
184
+ tmp_path
185
+ end
186
+
161
187
  def valid?
162
188
  out, status = sh_with_code "git status"
163
189
  @root.present? && status.success?
@@ -90,6 +90,9 @@ module Gitdocs
90
90
  elsif File.directory?(expanded_path) # list directory
91
91
  contents = gd.dir_files(expanded_path)
92
92
  render! "dir", :layout => 'app', :locals => locals.merge(:contents => contents)
93
+ elsif mode == "revisions" # list revisions
94
+ revisions = gd.file_revisions(file_path)
95
+ render! "revisions", :layout => 'app', :locals => locals.merge(:revisions => revisions)
93
96
  elsif mode == 'delete' # delete file
94
97
  FileUtils.rm(expanded_path)
95
98
  redirect! "/" + idx.to_s + parent
@@ -97,6 +100,8 @@ module Gitdocs
97
100
  contents = File.read(expanded_path)
98
101
  render! "edit", :layout => 'app', :locals => locals.merge(:contents => contents)
99
102
  elsif mode != 'raw' # render file
103
+ revision = request.params['revision']
104
+ expanded_path = gd.file_revision_at(file_path, revision) if revision
100
105
  begin # attempting to render file
101
106
  contents = '<div class="tilt">' + render(expanded_path) + '</div>'
102
107
  rescue RuntimeError => e # not tilt supported
@@ -1,3 +1,3 @@
1
1
  module Gitdocs
2
- VERSION = "0.4.9"
2
+ VERSION = "0.4.10"
3
3
  end
@@ -3,4 +3,5 @@
3
3
  - if file
4
4
  %a{ :href => "?mode=raw" } (raw)
5
5
  %a{ :href => "?mode=edit" } (edit)
6
+ %a{ :href => "?mode=revisions" } (revisions)
6
7
  %a{ :href => "?mode=delete", :onclick => "javascript:return confirm('Are you sure?')" } (delete)
@@ -0,0 +1,25 @@
1
+ - @title = root
2
+
3
+ = partial("header", :locals => { :parent => parent, :file => true, :idx => idx })
4
+
5
+ - if revisions && revisions.any?
6
+ %table.condensed-table.zebra-striped
7
+ %thead
8
+ %tr
9
+ %th Commit
10
+ %th Subject
11
+ %th Author
12
+ %th Committed
13
+
14
+ %tbody
15
+ - revisions.each_with_index do |r, i|
16
+ %tr
17
+ %td.commit
18
+ %a{ :href => "?revision=#{r[:commit]}" }
19
+ = r[:commit]
20
+ %td.subject= r[:subject]
21
+ %td.author= r[:author]
22
+ %td.date.reldate= r[:date]
23
+
24
+ - if revisions.empty?
25
+ %p No revisions for this file could be found.
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gitdocs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.9
5
+ version: 0.4.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Hull
@@ -322,6 +322,7 @@ files:
322
322
  - lib/gitdocs/views/edit.haml
323
323
  - lib/gitdocs/views/file.haml
324
324
  - lib/gitdocs/views/home.haml
325
+ - lib/gitdocs/views/revisions.haml
325
326
  - lib/gitdocs/views/search.haml
326
327
  - lib/gitdocs/views/settings.haml
327
328
  - lib/img/icon.png