Added --page-file-dir option to gollum command

This commit is contained in:
Hiroshi Saito
2010-10-07 17:55:40 +09:00
parent 33aad801bd
commit fcdffc39ff
4 changed files with 65 additions and 12 deletions
+9 -9
View File
@@ -42,7 +42,7 @@ module Precious
get '/edit/*' do
@name = params[:splat].first
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
if page = wiki.page(@name)
@page = page
@content = page.raw_data
@@ -54,7 +54,7 @@ module Precious
post '/edit/*' do
name = params[:splat].first
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
page = wiki.page(name)
format = params[:format].intern
name = params[:rename] if params[:rename]
@@ -66,7 +66,7 @@ module Precious
post '/create/*' do
name = params[:page]
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
format = params[:format].intern
@@ -82,13 +82,13 @@ module Precious
post '/preview' do
format = params['wiki_format']
data = params['text']
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
wiki.preview_page("Preview", data, format).formatted_data
end
get '/history/:name' do
@name = params[:name]
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@page = wiki.page(@name)
@page_num = [params[:page].to_i, 1].max
@versions = @page.versions :page => @page_num
@@ -110,7 +110,7 @@ module Precious
get '/compare/:name/:version_list' do
@name = params[:name]
@versions = params[:version_list].split(/\.{2,3}/)
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@page = wiki.page(@name)
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
@diff = diffs.first
@@ -119,7 +119,7 @@ module Precious
get %r{/(.+?)/([0-9a-f]{40})} do
name = params[:captures][0]
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
if page = wiki.page(name, params[:captures][1])
@page = page
@name = name
@@ -132,7 +132,7 @@ module Precious
get '/search' do
@query = params[:q]
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@results = wiki.search @query
mustache :search
end
@@ -142,7 +142,7 @@ module Precious
end
def show_page_or_file(name)
wiki = Gollum::Wiki.new(settings.gollum_path)
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
if page = wiki.page(name)
@page = page
@name = name
+13 -2
View File
@@ -46,6 +46,8 @@ module Gollum
# to "/".
attr_reader :base_path
attr_reader :page_file_dir
# Public: Initialize a new Gollum Repo.
#
# repo - The String path to the Git repository that holds the Gollum
@@ -55,6 +57,7 @@ module Gollum
# Default: "/"
# :page_class - The page Class. Default: Gollum::Page
# :file_class - The file Class. Default: Gollum::File
# :page_file_dir - String the directory in which all page files reside
#
# Returns a fresh Gollum::Repo.
def initialize(path, options = {})
@@ -63,6 +66,7 @@ module Gollum
@base_path = options[:base_path] || "/"
@page_class = options[:page_class] || self.class.page_class
@file_class = options[:file_class] || self.class.file_class
@page_file_dir = options[:page_file_dir]
clear_cache
end
@@ -339,6 +343,9 @@ module Gollum
else
::File.join(dir, page_file_name(name, format))
end
if @page_file_dir
path = ::File.join(@page_file_dir, path)
end
Dir.chdir(::File.join(@repo.path, '..')) do
if file_path_scheduled_for_deletion?(index.tree, path)
@@ -433,7 +440,7 @@ module Gollum
dir = '/' if dir.strip.empty?
fullpath = ::File.join(dir, path)
fullpath = ::File.join(*[@page_file_dir, dir, path].compact)
fullpath = fullpath[1..-1] if fullpath =~ /^\//
if index.current_tree && tree = index.current_tree / dir
@@ -507,7 +514,11 @@ module Gollum
tree.split("\0").each do |line|
items << parse_tree_line(line)
end
items
if dir = @page_file_dir
items.select{|i| i.path =~ /^#{dir}\// }
else
items
end
end
# Parses a line of output from the `ls-tree` command.