class Gollum::File

Attributes

path[R]

Public: The String path of the file.

version[RW]

Public: The Grit::Commit version of the file.

Public Class Methods

new(wiki) click to toggle source

Public: Initialize a file.

wiki - The Gollum::Wiki in question.

Returns a newly initialized Gollum::File.

# File lib/gollum-lib/file.rb, line 10
def initialize(wiki)
  @wiki = wiki
  @blob = nil
  @path = nil
end

Public Instance Methods

escaped_url_path() click to toggle source

Public: The #url_path, but CGI escaped.

Returns the String #url_path

# File lib/gollum-lib/file.rb, line 28
def escaped_url_path
  CGI.escape(self.url_path).gsub('%2F','/')
end
filename()
Alias for: name
find(name, version) click to toggle source

Find a file in the given Gollum repo.

name - The full String path. version - The String version ID to find.

Returns a Gollum::File or nil if the file could not be found.

# File lib/gollum-lib/file.rb, line 89
def find(name, version)
  checked = name.downcase
  map     = @wiki.tree_map_for(version)
  if entry = map.detect { |entry| entry.path.downcase == checked }
    @path    = name
    @blob    = entry.blob(@wiki.repo)
    @version = version.is_a?(Grit::Commit) ? version : @wiki.commit_for(version)
    self
  end
end
mime_type() click to toggle source

Public: The String mime type of the file.

# File lib/gollum-lib/file.rb, line 61
def mime_type
  @blob.mime_type
end
name() click to toggle source

Public: The on-disk filename of the file.

Returns the String name.

# File lib/gollum-lib/file.rb, line 35
def name
  @blob && @blob.name
end
Also aliased as: filename
populate(blob, path=nil) click to toggle source

Populate the File with information from the Blob.

blob - The Grit::Blob that contains the info. path - The String directory path of the file.

Returns the populated Gollum::File.

# File lib/gollum-lib/file.rb, line 71
def populate(blob, path=nil)
  @blob = blob
  @path = "#{path}/#{blob.name}"[1..-1]
  self
end
raw_data() click to toggle source

Public: The raw contents of the page.

Returns the String data.

# File lib/gollum-lib/file.rb, line 43
def raw_data
  return nil unless @blob

  if !@wiki.repo.bare && @blob.is_symlink
    new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path))
    return IO.read(new_path) if new_path
  end

  @blob.data
end
url_path() click to toggle source

Public: The url path required to reach this page within the repo.

Returns the String #url_path

# File lib/gollum-lib/file.rb, line 19
def url_path
  path = self.path
  path = path.sub(/\/[^\/]+$/, '/') if path.include?('/')
  path
end