gollum-lib 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gollum-lib might be problematic. Click here for more details.

@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.required_ruby_version = ">= 1.8.7"
6
6
 
7
7
  s.name = 'gollum-lib'
8
- s.version = '1.0.2'
9
- s.date = '2013-06-15'
8
+ s.version = '1.0.3'
9
+ s.date = '2013-06-18'
10
10
  s.rubyforge_project = 'gollum-lib'
11
11
  s.license = 'MIT'
12
12
 
@@ -30,7 +30,7 @@ $KCODE = 'U' if RUBY_VERSION[0,3] == '1.8'
30
30
 
31
31
  module Gollum
32
32
  module Lib
33
- VERSION = '1.0.2'
33
+ VERSION = '1.0.3'
34
34
  end
35
35
 
36
36
  def self.assets_path
@@ -12,6 +12,8 @@ module Gollum
12
12
  @wiki = wiki
13
13
  @blob = nil
14
14
  @path = nil
15
+ @on_disk = false
16
+ @on_disk_path = nil
15
17
  end
16
18
 
17
19
  # Public: The url path required to reach this page within the repo.
@@ -34,6 +36,7 @@ module Gollum
34
36
  #
35
37
  # Returns the String name.
36
38
  def name
39
+ return @path if on_disk?
37
40
  @blob && @blob.name
38
41
  end
39
42
  alias filename name
@@ -42,6 +45,7 @@ module Gollum
42
45
  #
43
46
  # Returns the String data.
44
47
  def raw_data
48
+ return IO.read(@on_disk_path) if on_disk?
45
49
  return nil unless @blob
46
50
 
47
51
  if !@wiki.repo.bare && @blob.is_symlink
@@ -52,6 +56,20 @@ module Gollum
52
56
  @blob.data
53
57
  end
54
58
 
59
+ # Public: Is this an on-disk file reference?
60
+ #
61
+ # Returns true if this is a pointer to an on-disk file
62
+ def on_disk?
63
+ return @on_disk
64
+ end
65
+
66
+ # Public: The path to this file on disk
67
+ #
68
+ # Returns nil if on_disk? is false.
69
+ def on_disk_path
70
+ return @on_disk_path
71
+ end
72
+
55
73
  # Public: The Grit::Commit version of the file.
56
74
  attr_accessor :version
57
75
 
@@ -60,7 +78,7 @@ module Gollum
60
78
 
61
79
  # Public: The String mime type of the file.
62
80
  def mime_type
63
- @blob.mime_type
81
+ @blob && @blob.mime_type
64
82
  end
65
83
 
66
84
  # Populate the File with information from the Blob.
@@ -72,6 +90,8 @@ module Gollum
72
90
  def populate(blob, path=nil)
73
91
  @blob = blob
74
92
  @path = "#{path}/#{blob.name}"[1..-1]
93
+ @on_disk = false
94
+ @on_disk_path = nil
75
95
  self
76
96
  end
77
97
 
@@ -81,19 +101,49 @@ module Gollum
81
101
  #
82
102
  #########################################################################
83
103
 
104
+ # Return the file path to this file on disk, if available.
105
+ #
106
+ # Returns nil if the file isn't available on disk. This can occur if the
107
+ # repo is bare, if the commit isn't the HEAD, or if there are problems
108
+ # resolving symbolic links.
109
+ def get_disk_reference(name, commit)
110
+ return false if @wiki.repo.bare
111
+ return false if commit.sha != @wiki.repo.head.commit.sha
112
+
113
+ # This will try to resolve symbolic links, as well
114
+ pathname = Pathname.new(::File.join(@wiki.repo.path, '..', name))
115
+ realpath = pathname.realpath
116
+ return false unless realpath.exist?
117
+
118
+ @on_disk_path = realpath.to_s
119
+ return true
120
+ end
121
+
84
122
  # Find a file in the given Gollum repo.
85
123
  #
86
124
  # name - The full String path.
87
125
  # version - The String version ID to find.
126
+ # try_on_disk - If true, try to return just a reference to a file
127
+ # that exists on the disk.
88
128
  #
89
- # Returns a Gollum::File or nil if the file could not be found.
90
- def find(name, version)
129
+ # Returns a Gollum::File or nil if the file could not be found. Note
130
+ # that if you specify try_on_disk=true, you may or may not get a file
131
+ # for which on_disk? is actually true.
132
+ def find(name, version, try_on_disk=false)
91
133
  checked = name.downcase
92
134
  map = @wiki.tree_map_for(version)
135
+ commit = version.is_a?(Grit::Commit) ? version : @wiki.commit_for(version)
136
+
93
137
  if entry = map.detect { |entry| entry.path.downcase == checked }
94
138
  @path = name
95
- @blob = entry.blob(@wiki.repo)
96
- @version = version.is_a?(Grit::Commit) ? version : @wiki.commit_for(version)
139
+ @version = commit
140
+
141
+ if try_on_disk && get_disk_reference(name, commit)
142
+ @on_disk = true
143
+ else
144
+ @blob = entry.blob(@wiki.repo)
145
+ end
146
+
97
147
  self
98
148
  end
99
149
  end
@@ -257,10 +257,14 @@ module Gollum
257
257
  #
258
258
  # name - The full String pathname to the file.
259
259
  # version - The String version ID to find (default: @ref).
260
- #
261
- # Returns a Gollum::File or nil if no matching file was found.
262
- def file(name, version = @ref)
263
- @file_class.new(self).find(name, version)
260
+ # try_on_disk - If true, try to return just a reference to a file
261
+ # that exists on the disk.
262
+ #
263
+ # Returns a Gollum::File or nil if no matching file was found. Note
264
+ # that if you specify try_on_disk=true, you may or may not get a file
265
+ # for which on_disk? is actually true.
266
+ def file(name, version = @ref, try_on_disk = false)
267
+ @file_class.new(self).find(name, version, try_on_disk)
264
268
  end
265
269
 
266
270
  # Public: Create an in-memory Page with the given data and format. This
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-15 00:00:00.000000000 Z
13
+ date: 2013-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grit
@@ -442,3 +442,4 @@ signing_key:
442
442
  specification_version: 2
443
443
  summary: A simple, Git-powered wiki.
444
444
  test_files: []
445
+ has_rdoc: