class Precious::App

Private Instance Methods

commit_options() click to toggle source

Options parameter to Gollum::Committer#initialize

:message   - The String commit message.
:name      - The String author full name.
:email     - The String email address.

message is sourced from the incoming request parameters optional author details are sourced from the session, to be populated by rack middleware ahead of us. optional note is equally sourced from the session.

# File lib/gollum/app.rb, line 731
def commit_options
  msg               = (params[:message].nil? or params[:message].empty?) ? "[no message]" : params[:message]
  commit_options    = { message: msg, note: session['gollum.note'] }
  author_parameters = session['gollum.author']
  commit_options.merge! author_parameters unless author_parameters.nil?
  commit_options
end
find_upload_dest(path) click to toggle source
# File lib/gollum/app.rb, line 739
def find_upload_dest(path)
  settings.wiki_options[:allow_uploads] ?
      (settings.wiki_options[:per_page_uploads] ?
          path : 'uploads'
      ) : ''
end
load_template(wiki_page, path) click to toggle source
# File lib/gollum/app.rb, line 699
def load_template(wiki_page, path)
  template_page = wiki_page(::File.join(path, '_Template')).page || wiki_page('/_Template').page
  template_page ? Gollum::TemplateFilter.apply_filters(wiki_page, template_page.text_data) : nil
end
page_does_not_exist() click to toggle source
# File lib/gollum/app.rb, line 624
def page_does_not_exist()
  @message = "The requested page does not exist."
  status 404
  return mustache :error
end
redirect_to(redirect_path, fullpath, query_params) click to toggle source
# File lib/gollum/app.rb, line 620
def redirect_to(redirect_path, fullpath, query_params)
    redirect to("#{encodeURI(redirect_path)}?redirected_from=#{encodeURI(fullpath)}#{query_params}")
end
show_file(file) click to toggle source
# File lib/gollum/app.rb, line 689
def show_file(file)
  return unless file
  content_type file.mime_type
  if file.on_disk?
    send_file file.on_disk_path, :disposition => 'inline'
  else
    file.raw_data
  end
end
show_history(wikip) click to toggle source
# File lib/gollum/app.rb, line 630
def show_history(wikip)
  @name      = wikip.fullname
  @page      = wikip.page
  @page_num  = [params[:page_num].to_i, 1].max
  @max_count = settings.wiki_options.fetch(:pagination_count, 10)
  unless @page.nil?
    @wiki     = @page.wiki
    @versions = @page.versions(
      per_page: @max_count,
      page_num: @page_num,
      follow: settings.wiki_options.fetch(:follow_renames, true)
    )
    mustache :history
  else
    redirect to("/")
  end
end
show_page_or_file(fullpath) click to toggle source
# File lib/gollum/app.rb, line 648
def show_page_or_file(fullpath)
  wiki = wiki_new
  if page = wiki.page(fullpath)
    @page          = page
    @name          = page.filename_stripped
    @content       = page.formatted_data
    @upload_dest   = find_upload_dest(Pathname.new(fullpath).cleanpath.to_s)

    # Extensions and layout data
    @editable      = true
    @toc_content   = wiki.universal_toc ? @page.toc_data : nil
    @h1_title      = wiki.h1_title
    @bar_side      = wiki.bar_side
    @allow_uploads = wiki.allow_uploads
    @navbar        = true
    mustache :page
  elsif file = wiki.file(fullpath, wiki.ref, true)
    show_file(file)
  elsif @redirects_enabled && redirect_path = wiki.redirects[fullpath]
    redirect_to(redirect_path, fullpath, "")
  else
    if @allow_editing
      path = fullpath[-1] == '/' ? "#{fullpath}#{wiki.index_page}" : fullpath # Append default index page if no page name is supplied
      redirect to("/gollum/create/#{clean_url(encodeURIComponent(path))}")
    else
      return page_does_not_exist
    end
  end
end
show_raw_page(fullpath) click to toggle source
# File lib/gollum/app.rb, line 678
def show_raw_page(fullpath)
  wiki = wiki_new
  if @redirects_enabled && redirect_path = wiki.redirects[fullpath]
    redirect_to(redirect_path, fullpath, "&raw")
  elsif page = wiki.page(fullpath) and file = wiki.file(fullpath, wiki.ref, true)
    show_file(file)
  else
    return page_does_not_exist
  end
end
update_wiki_page(wiki, page, content, commit, name = nil, format = nil) click to toggle source
# File lib/gollum/app.rb, line 704
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_new() click to toggle source
# File lib/gollum/app.rb, line 720
def wiki_new
  Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
end
wiki_page(path, version = nil, wiki = nil) click to toggle source
# File lib/gollum/app.rb, line 713
def wiki_page(path, version = nil, wiki = nil)
  pathname = (Pathname.new('/') + path).cleanpath
  wiki = wiki_new if wiki.nil?
  OpenStruct.new(:wiki => wiki, :page => wiki.page(pathname.to_s, version = version),
                 :name => pathname.basename.sub_ext('').to_s, :path => pathname.dirname.to_s, :ext => pathname.extname, :fullname => pathname.basename.to_s, :fullpath => pathname.to_s)
end