Class: Precious::App

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/gollum/frontend/app.rb

Defined Under Namespace

Classes: Browser

Constant Summary collapse

@@min_ua =
[
    Browser.new('Internet Explorer', '10.0'),
    Browser.new('Chrome', '7.0'),
    Browser.new('Firefox', '4.0'),
]

Instance Method Summary collapse

Methods included from Helpers

#extract_name, #extract_path, #sanitize_empty_params

Instance Method Details

#commit_messageObject



370
371
372
# File 'lib/gollum/frontend/app.rb', line 370

def commit_message
  { :message => params[:message] }
end

#show_page_or_file(fullpath) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/gollum/frontend/app.rb', line 339

def show_page_or_file(fullpath)
  name         = extract_name(fullpath)
  path         = extract_path(fullpath)
  wiki         = wiki_new

  if page = wiki.paged(name, path)
    @page = page
    @name = name
    @editable = true
    @content = page.formatted_data
    @toc_content = wiki.universal_toc ? @page.toc_data : nil
    @mathjax = wiki.mathjax
    mustache :page
  elsif file = wiki.file(fullpath)
    content_type file.mime_type
    file.raw_data
  else
    page_path = [path, name].compact.join('/')
    redirect to("/create/#{CGI.escape(page_path).gsub('%2F','/')}")
  end
end

#supported_useragent?(user_agent) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/gollum/frontend/app.rb', line 53

def supported_useragent?(user_agent)
  ua = UserAgent.parse(user_agent)
  @@min_ua.detect {|min| ua >= min }
end

#update_wiki_page(wiki, page, content, commit, name = nil, format = nil) ⇒ Object



361
362
363
364
365
366
367
368
# File 'lib/gollum/frontend/app.rb', line 361

def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
  return if !page ||
    ((!content || page.raw_data == content) && page.format == format)
  name    ||= page.name
  format    = (format || page.format).to_sym
  content ||= page.raw_data
  wiki.update_page(page, name, format, content.to_s, commit)
end

#wiki_newObject



109
110
111
# File 'lib/gollum/frontend/app.rb', line 109

def wiki_new
  Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
end

#wiki_page(name, path = nil, version = nil) ⇒ Object

path is set to name if path is nil.

if path is 'a/b' and a and b are dirs, then
path must have a trailing slash 'a/b/' or
extract_path will trim path to 'a'

name, path, version



98
99
100
101
102
103
104
105
106
107
# File 'lib/gollum/frontend/app.rb', line 98

def wiki_page( name, path = nil, version = nil)
  path = name if path.nil?
  name = extract_name(name)
  path = extract_path(path)

  wiki = wiki_new

  OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, version),
                 :name => name, :path => path)
end