class Smeagol::App
Sinatra based app for serving the the site directly from the Gollum
wiki repo.
Private Instance Methods
get_mime_type(file)
click to toggle source
Retrieves the mime type for a filename based on its extension.
file - The filename. [String]
Returns the mime type for a file. [String]
# File lib/smeagol/app.rb, line 150 def get_mime_type(file) unless file.nil? extension = ::File.extname(file) return Rack::Mime::MIME_TYPES[extension] || 'text/plain' end return 'text/plain' end
mount_path()
click to toggle source
Determines the mounted path to prefix to internal links.
Returns the mount path. [String]
# File lib/smeagol/app.rb, line 182 def mount_path path = settings.mount_path path += '/' unless path.end_with?('/') path end
parse_params(params)
click to toggle source
If the path starts with a version identifier, use it.
params - The request parameters. [Hash]
Returns the version number. [String]
# File lib/smeagol/app.rb, line 121 def parse_params(params) name = params[:splat].first version = 'master' tag_name = nil if name.index(/^v\d/) repo = Grit::Repo.new(repository.path) tag_name = name.split('/').first repo_tag = repo.tags.find do |tag| tag_name == tag.name or tag_name == "v#{tag.name}" end if repo_tag version = repo_tag.name #repo_tag.commit.id name = name.split('/')[1..-1].join('/') else # TODO: page not found end end return name, version, tag_name end
repository()
click to toggle source
Determines the repository to use based on the hostname.
Returns the matching repository. [Repository]
# File lib/smeagol/app.rb, line 164 def repository # Match on hostname settings.repositories.each do |repository| next if repository.cname.nil? if repository.cname.upcase == request.host.upcase return repository end end # If no match, use the first repository as the default. settings.repositories.first end
sanitize_path(path)
click to toggle source
Removes all references to parent directories (../) in a path.
path - The path to sanitize. [String]
Returns a clean, pristine path. [String]
# File lib/smeagol/app.rb, line 195 def sanitize_path(path) path.gsub(/\.\.(?=$|\/)/, '') unless path.nil? end