Class: Smeagol::App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Smeagol::App
- Defined in:
- lib/smeagol/app.rb
Overview
Sinatra based app for serving the the site directly from the Gollum wiki repo.
Instance Method Summary collapse
-
#get_mime_type(file) ⇒ String
private
Retrieves the mime type for a filename based on its extension.
-
#mount_path ⇒ String
private
Determines the mounted path to prefix to internal links.
-
#parse_params(params) ⇒ String
private
If the path starts with a version identifier, use it.
-
#repository ⇒ Repository
private
Determines the repository to use based on the hostname.
-
#sanitize_path(path) ⇒ String
private
Removes all references to parent directories (../) in a path.
Instance Method Details
#get_mime_type(file) ⇒ String (private)
Retrieves the mime type for a filename based on its extension.
150 151 152 153 154 155 156 157 |
# 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 ⇒ String (private)
Determines the mounted path to prefix to internal links.
182 183 184 185 186 |
# File 'lib/smeagol/app.rb', line 182 def mount_path path = settings.mount_path path += '/' unless path.end_with?('/') path end |
#parse_params(params) ⇒ String (private)
If the path starts with a version identifier, use it.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# 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..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 ⇒ Repository (private)
Determines the repository to use based on the hostname.
164 165 166 167 168 169 170 171 172 173 174 175 |
# 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) ⇒ String (private)
Removes all references to parent directories (../) in a path.
195 196 197 |
# File 'lib/smeagol/app.rb', line 195 def sanitize_path(path) path.gsub(/\.\.(?=$|\/)/, '') unless path.nil? end |