Added --page-file-dir option to gollum command
This commit is contained in:
+7
-1
@@ -19,6 +19,7 @@ require 'gollum'
|
|||||||
|
|
||||||
exec = {}
|
exec = {}
|
||||||
options = { 'port' => 4567, 'bind' => '127.0.0.1' }
|
options = { 'port' => 4567, 'bind' => '127.0.0.1' }
|
||||||
|
wiki_options = {}
|
||||||
opts = OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = help
|
opts.banner = help
|
||||||
|
|
||||||
@@ -38,6 +39,10 @@ opts = OptionParser.new do |opts|
|
|||||||
opts.on("--irb", "Start an irb process with gollum loaded for the current wiki.") do
|
opts.on("--irb", "Start an irb process with gollum loaded for the current wiki.") do
|
||||||
options['irb'] = true
|
options['irb'] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("--page-file-dir [PATH]", "Specify the sub directory for all page files (default: repository root).") do |path|
|
||||||
|
wiki_options[:page_file_dir] = path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read command line options into `options` hash
|
# Read command line options into `options` hash
|
||||||
@@ -77,7 +82,7 @@ if options['irb']
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
wiki = Gollum::Wiki.new(gollum_path)
|
wiki = Gollum::Wiki.new(gollum_path, wiki_options)
|
||||||
if !wiki.exist? then raise Grit::InvalidGitRepositoryError end
|
if !wiki.exist? then raise Grit::InvalidGitRepositoryError end
|
||||||
puts "Loaded Gollum wiki at #{File.expand_path(gollum_path).inspect}."
|
puts "Loaded Gollum wiki at #{File.expand_path(gollum_path).inspect}."
|
||||||
puts
|
puts
|
||||||
@@ -99,5 +104,6 @@ if options['irb']
|
|||||||
else
|
else
|
||||||
require 'gollum/frontend/app'
|
require 'gollum/frontend/app'
|
||||||
Precious::App.set(:gollum_path, gollum_path)
|
Precious::App.set(:gollum_path, gollum_path)
|
||||||
|
Precious::App.set(:wiki_options, wiki_options)
|
||||||
Precious::App.run!(options)
|
Precious::App.run!(options)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ module Precious
|
|||||||
|
|
||||||
get '/edit/*' do
|
get '/edit/*' do
|
||||||
@name = params[:splat].first
|
@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)
|
if page = wiki.page(@name)
|
||||||
@page = page
|
@page = page
|
||||||
@content = page.raw_data
|
@content = page.raw_data
|
||||||
@@ -54,7 +54,7 @@ module Precious
|
|||||||
|
|
||||||
post '/edit/*' do
|
post '/edit/*' do
|
||||||
name = params[:splat].first
|
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)
|
page = wiki.page(name)
|
||||||
format = params[:format].intern
|
format = params[:format].intern
|
||||||
name = params[:rename] if params[:rename]
|
name = params[:rename] if params[:rename]
|
||||||
@@ -66,7 +66,7 @@ module Precious
|
|||||||
|
|
||||||
post '/create/*' do
|
post '/create/*' do
|
||||||
name = params[:page]
|
name = params[:page]
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path)
|
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||||
|
|
||||||
format = params[:format].intern
|
format = params[:format].intern
|
||||||
|
|
||||||
@@ -82,13 +82,13 @@ module Precious
|
|||||||
post '/preview' do
|
post '/preview' do
|
||||||
format = params['wiki_format']
|
format = params['wiki_format']
|
||||||
data = params['text']
|
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
|
wiki.preview_page("Preview", data, format).formatted_data
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/history/:name' do
|
get '/history/:name' do
|
||||||
@name = params[:name]
|
@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 = wiki.page(@name)
|
||||||
@page_num = [params[:page].to_i, 1].max
|
@page_num = [params[:page].to_i, 1].max
|
||||||
@versions = @page.versions :page => @page_num
|
@versions = @page.versions :page => @page_num
|
||||||
@@ -110,7 +110,7 @@ module Precious
|
|||||||
get '/compare/:name/:version_list' do
|
get '/compare/:name/:version_list' do
|
||||||
@name = params[:name]
|
@name = params[:name]
|
||||||
@versions = params[:version_list].split(/\.{2,3}/)
|
@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)
|
@page = wiki.page(@name)
|
||||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||||
@diff = diffs.first
|
@diff = diffs.first
|
||||||
@@ -119,7 +119,7 @@ module Precious
|
|||||||
|
|
||||||
get %r{/(.+?)/([0-9a-f]{40})} do
|
get %r{/(.+?)/([0-9a-f]{40})} do
|
||||||
name = params[:captures][0]
|
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])
|
if page = wiki.page(name, params[:captures][1])
|
||||||
@page = page
|
@page = page
|
||||||
@name = name
|
@name = name
|
||||||
@@ -132,7 +132,7 @@ module Precious
|
|||||||
|
|
||||||
get '/search' do
|
get '/search' do
|
||||||
@query = params[:q]
|
@query = params[:q]
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path)
|
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||||
@results = wiki.search @query
|
@results = wiki.search @query
|
||||||
mustache :search
|
mustache :search
|
||||||
end
|
end
|
||||||
@@ -142,7 +142,7 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show_page_or_file(name)
|
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)
|
if page = wiki.page(name)
|
||||||
@page = page
|
@page = page
|
||||||
@name = name
|
@name = name
|
||||||
|
|||||||
+13
-2
@@ -46,6 +46,8 @@ module Gollum
|
|||||||
# to "/".
|
# to "/".
|
||||||
attr_reader :base_path
|
attr_reader :base_path
|
||||||
|
|
||||||
|
attr_reader :page_file_dir
|
||||||
|
|
||||||
# Public: Initialize a new Gollum Repo.
|
# Public: Initialize a new Gollum Repo.
|
||||||
#
|
#
|
||||||
# repo - The String path to the Git repository that holds the Gollum
|
# repo - The String path to the Git repository that holds the Gollum
|
||||||
@@ -55,6 +57,7 @@ module Gollum
|
|||||||
# Default: "/"
|
# Default: "/"
|
||||||
# :page_class - The page Class. Default: Gollum::Page
|
# :page_class - The page Class. Default: Gollum::Page
|
||||||
# :file_class - The file Class. Default: Gollum::File
|
# :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.
|
# Returns a fresh Gollum::Repo.
|
||||||
def initialize(path, options = {})
|
def initialize(path, options = {})
|
||||||
@@ -63,6 +66,7 @@ module Gollum
|
|||||||
@base_path = options[:base_path] || "/"
|
@base_path = options[:base_path] || "/"
|
||||||
@page_class = options[:page_class] || self.class.page_class
|
@page_class = options[:page_class] || self.class.page_class
|
||||||
@file_class = options[:file_class] || self.class.file_class
|
@file_class = options[:file_class] || self.class.file_class
|
||||||
|
@page_file_dir = options[:page_file_dir]
|
||||||
clear_cache
|
clear_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -339,6 +343,9 @@ module Gollum
|
|||||||
else
|
else
|
||||||
::File.join(dir, page_file_name(name, format))
|
::File.join(dir, page_file_name(name, format))
|
||||||
end
|
end
|
||||||
|
if @page_file_dir
|
||||||
|
path = ::File.join(@page_file_dir, path)
|
||||||
|
end
|
||||||
|
|
||||||
Dir.chdir(::File.join(@repo.path, '..')) do
|
Dir.chdir(::File.join(@repo.path, '..')) do
|
||||||
if file_path_scheduled_for_deletion?(index.tree, path)
|
if file_path_scheduled_for_deletion?(index.tree, path)
|
||||||
@@ -433,7 +440,7 @@ module Gollum
|
|||||||
|
|
||||||
dir = '/' if dir.strip.empty?
|
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 =~ /^\//
|
fullpath = fullpath[1..-1] if fullpath =~ /^\//
|
||||||
|
|
||||||
if index.current_tree && tree = index.current_tree / dir
|
if index.current_tree && tree = index.current_tree / dir
|
||||||
@@ -507,7 +514,11 @@ module Gollum
|
|||||||
tree.split("\0").each do |line|
|
tree.split("\0").each do |line|
|
||||||
items << parse_tree_line(line)
|
items << parse_tree_line(line)
|
||||||
end
|
end
|
||||||
items
|
if dir = @page_file_dir
|
||||||
|
items.select{|i| i.path =~ /^#{dir}\// }
|
||||||
|
else
|
||||||
|
items
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parses a line of output from the `ls-tree` command.
|
# Parses a line of output from the `ls-tree` command.
|
||||||
|
|||||||
@@ -282,3 +282,39 @@ context "Wiki sync with working directory" do
|
|||||||
FileUtils.rm_r(@path)
|
FileUtils.rm_r(@path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "page_file_dir option" do
|
||||||
|
setup do
|
||||||
|
@path = testpath('examples/pfdtest')
|
||||||
|
@repo = Grit::Repo.init(@path)
|
||||||
|
@page_file_dir = 'docs'
|
||||||
|
Dir.chdir(@path) do
|
||||||
|
Dir.mkdir(@page_file_dir)
|
||||||
|
File.open("docs/foo.md", "w"){|f| f.print "Hello foo" }
|
||||||
|
@repo.add("docs/foo.md")
|
||||||
|
File.open("bar.md", "w"){|f| f.print "Hello bar" }
|
||||||
|
@repo.add("bar.md")
|
||||||
|
@repo.commit_index("Added docs/foo.md and bar.md")
|
||||||
|
end
|
||||||
|
|
||||||
|
@wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_file_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "write a page in sub directory" do
|
||||||
|
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||||
|
assert_equal "Hi", File.read(File.join(@path, @page_file_dir, "New-Page.md"))
|
||||||
|
assert !File.exist?(File.join(@path, "New-Page.md"))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a file in page file dir should be found" do
|
||||||
|
assert @wiki.page("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a file out of page file dir should not be found" do
|
||||||
|
assert !@wiki.page("bar")
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_r(@path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user