merge page-file-dir_option branch
This commit is contained in:
+15
-6
@@ -19,6 +19,8 @@ require 'gollum'
|
|||||||
|
|
||||||
exec = {}
|
exec = {}
|
||||||
options = { 'port' => 4567, 'bind' => '0.0.0.0' }
|
options = { 'port' => 4567, 'bind' => '0.0.0.0' }
|
||||||
|
wiki_options = {}
|
||||||
|
|
||||||
opts = OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = help
|
opts.banner = help
|
||||||
|
|
||||||
@@ -42,6 +44,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
|
||||||
@@ -67,13 +73,13 @@ if options['irb']
|
|||||||
ARGV.replace(args)
|
ARGV.replace(args)
|
||||||
@__initialized = true
|
@__initialized = true
|
||||||
end
|
end
|
||||||
|
|
||||||
ws = WorkSpace.new(binding)
|
ws = WorkSpace.new(binding)
|
||||||
irb = Irb.new(ws)
|
irb = Irb.new(ws)
|
||||||
|
|
||||||
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
|
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
|
||||||
@CONF[:MAIN_CONTEXT] = irb.context
|
@CONF[:MAIN_CONTEXT] = irb.context
|
||||||
|
|
||||||
catch(:IRB_EXIT) do
|
catch(:IRB_EXIT) do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
@@ -81,10 +87,10 @@ 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
|
||||||
puts %( page = wiki.page('page-name'))
|
puts %( page = wiki.page('page-name'))
|
||||||
puts %( # => <Gollum::Page>)
|
puts %( # => <Gollum::Page>)
|
||||||
puts
|
puts
|
||||||
@@ -103,11 +109,14 @@ 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)
|
||||||
|
|
||||||
if cfg = options['config']
|
if cfg = options['config']
|
||||||
# If the path begins with a '/' it will be considered an absolute path,
|
# If the path begins with a '/' it will be considered an absolute path,
|
||||||
# otherwise it will be relative to the CWD
|
# otherwise it will be relative to the CWD
|
||||||
cfg = File.join(Dir.getwd, cfg) unless cfg.slice(0) == File::SEPARATOR
|
cfg = File.join(Dir.getwd, cfg) unless cfg.slice(0) == File::SEPARATOR
|
||||||
require cfg
|
require cfg
|
||||||
end
|
end
|
||||||
|
|
||||||
Precious::App.run!(options)
|
Precious::App.run!(options)
|
||||||
end
|
end
|
||||||
|
|||||||
+10
-10
@@ -44,7 +44,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
|
||||||
@@ -55,7 +55,7 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
post '/edit/*' do
|
post '/edit/*' do
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path)
|
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||||
page = wiki.page(params[:splat].first)
|
page = wiki.page(params[:splat].first)
|
||||||
name = params[:rename] || page.name
|
name = params[:rename] || page.name
|
||||||
msg = commit_message
|
msg = commit_message
|
||||||
@@ -69,7 +69,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
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
post '/revert/:page/*' do
|
post '/revert/:page/*' do
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path)
|
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||||
@name = params[:page]
|
@name = params[:page]
|
||||||
@page = wiki.page(@name)
|
@page = wiki.page(@name)
|
||||||
shas = params[:splat].first.split("/")
|
shas = params[:splat].first.split("/")
|
||||||
@@ -103,7 +103,7 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
post '/preview' do
|
post '/preview' do
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path)
|
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||||
@name = "Preview"
|
@name = "Preview"
|
||||||
@page = wiki.preview_page(@name, params[:content], params[:format])
|
@page = wiki.preview_page(@name, params[:content], params[:format])
|
||||||
@content = @page.formatted_data
|
@content = @page.formatted_data
|
||||||
@@ -112,7 +112,7 @@ module Precious
|
|||||||
|
|
||||||
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
|
||||||
@@ -134,7 +134,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
|
||||||
@@ -147,7 +147,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
|
||||||
@@ -160,7 +160,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
|
||||||
@name = @query
|
@name = @query
|
||||||
mustache :search
|
mustache :search
|
||||||
@@ -171,7 +171,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
|
||||||
|
|||||||
@@ -2,7 +2,15 @@ module Gollum
|
|||||||
# Controls all access to the Git objects from Gollum. Extend this class to
|
# Controls all access to the Git objects from Gollum. Extend this class to
|
||||||
# add custom caching for special cases.
|
# add custom caching for special cases.
|
||||||
class GitAccess
|
class GitAccess
|
||||||
def initialize(path)
|
# Initializes the GitAccess instance.
|
||||||
|
#
|
||||||
|
# path - The String path to the Git repository that holds the
|
||||||
|
# Gollum site.
|
||||||
|
# page_file_dir - String the directory in which all page files reside
|
||||||
|
#
|
||||||
|
# Returns this instance.
|
||||||
|
def initialize(path, page_file_dir = nil)
|
||||||
|
@page_file_dir = page_file_dir
|
||||||
@path = path
|
@path = path
|
||||||
@repo = Grit::Repo.new(path)
|
@repo = Grit::Repo.new(path)
|
||||||
clear
|
clear
|
||||||
@@ -15,7 +23,7 @@ module Gollum
|
|||||||
@repo.git.exist?
|
@repo.git.exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Converts a given Git reference to a SHA, using the cache if
|
# Public: Converts a given Git reference to a SHA, using the cache if
|
||||||
# available.
|
# available.
|
||||||
#
|
#
|
||||||
# ref - a String Git reference (ex: "master")
|
# ref - a String Git reference (ex: "master")
|
||||||
@@ -29,7 +37,7 @@ module Gollum
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Gets a recursive list of Git blobs for the whole tree at the
|
# Public: Gets a recursive list of Git blobs for the whole tree at the
|
||||||
# given commit.
|
# given commit.
|
||||||
#
|
#
|
||||||
# ref - A String Git reference or Git SHA to a commit.
|
# ref - A String Git reference or Git SHA to a commit.
|
||||||
@@ -144,10 +152,17 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns an Array of BlobEntry instances.
|
# Returns an Array of BlobEntry instances.
|
||||||
def tree!(sha)
|
def tree!(sha)
|
||||||
tree = @repo.git.native(:ls_tree,
|
tree = @repo.git.native(:ls_tree,
|
||||||
{:r => true, :l => true, :z => true}, sha)
|
{:r => true, :l => true, :z => true}, sha)
|
||||||
tree.split("\0").inject([]) do |items, line|
|
items = tree.split("\0").inject([]) do |memo, line|
|
||||||
items << parse_tree_line(line)
|
memo << parse_tree_line(line)
|
||||||
|
end
|
||||||
|
|
||||||
|
if dir = @page_file_dir
|
||||||
|
regex = /^#{dir}\//
|
||||||
|
items.select { |i| i.path =~ regex }
|
||||||
|
else
|
||||||
|
items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -201,7 +216,7 @@ module Gollum
|
|||||||
# Parses a line of output from the `ls-tree` command.
|
# Parses a line of output from the `ls-tree` command.
|
||||||
#
|
#
|
||||||
# line - A String line of output:
|
# line - A String line of output:
|
||||||
# "100644 blob 839c2291b30495b9a882c17d08254d3c90d8fb53 Home.md"
|
# "100644 blob 839c2291b30495b9a882c17d08254d3c90d8fb53 Home.md"
|
||||||
#
|
#
|
||||||
# Returns an Array of BlobEntry instances.
|
# Returns an Array of BlobEntry instances.
|
||||||
def parse_tree_line(line)
|
def parse_tree_line(line)
|
||||||
|
|||||||
+33
-24
@@ -94,17 +94,21 @@ module Gollum
|
|||||||
# Gets the sanitization options for older page revisions used by this Wiki.
|
# Gets the sanitization options for older page revisions used by this Wiki.
|
||||||
attr_reader :history_sanitization
|
attr_reader :history_sanitization
|
||||||
|
|
||||||
|
# Gets the String directory in which all page files reside.
|
||||||
|
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
|
# path - The String path to the Git repository that holds the Gollum
|
||||||
# site.
|
# site.
|
||||||
# options - Optional Hash:
|
# options - Optional Hash:
|
||||||
# :base_path - String base path for all Wiki links.
|
# :base_path - String base path for all Wiki links.
|
||||||
# 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
|
||||||
# :markup_class - The markup Class. Default: Gollum::Markup
|
# :markup_class - The markup Class. Default: Gollum::Markup
|
||||||
# :sanitization - An instance of Sanitization.
|
# :sanitization - An instance of Sanitization.
|
||||||
|
# :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 = {})
|
||||||
@@ -112,14 +116,15 @@ module Gollum
|
|||||||
options[:access] = path
|
options[:access] = path
|
||||||
path = path.path
|
path = path.path
|
||||||
end
|
end
|
||||||
@path = path
|
@path = path
|
||||||
@access = options[:access] || GitAccess.new(path)
|
@page_file_dir = options[:page_file_dir]
|
||||||
@base_path = options[:base_path] || "/"
|
@access = options[:access] || GitAccess.new(path, @page_file_dir)
|
||||||
@page_class = options[:page_class] || self.class.page_class
|
@base_path = options[:base_path] || "/"
|
||||||
@file_class = options[:file_class] || self.class.file_class
|
@page_class = options[:page_class] || self.class.page_class
|
||||||
@markup_class = options[:markup_class] || self.class.markup_class
|
@file_class = options[:file_class] || self.class.file_class
|
||||||
@repo = @access.repo
|
@markup_class = options[:markup_class] || self.class.markup_class
|
||||||
@sanitization = options[:sanitization] || self.class.sanitization
|
@repo = @access.repo
|
||||||
|
@sanitization = options[:sanitization] || self.class.sanitization
|
||||||
@history_sanitization = options[:history_sanitization] ||
|
@history_sanitization = options[:history_sanitization] ||
|
||||||
self.class.history_sanitization
|
self.class.history_sanitization
|
||||||
end
|
end
|
||||||
@@ -361,10 +366,10 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns an Array with Objects of page name and count of matches
|
# Returns an Array with Objects of page name and count of matches
|
||||||
def search(query)
|
def search(query)
|
||||||
# See: http://github.com/Sirupsen/gollum/commit/f0a6f52bdaf6bee8253ca33bb3fceaeb27bfb87e
|
args = [{:c => query}, 'master', '--']
|
||||||
search_output = @repo.git.grep({:c => query}, 'master')
|
args << '--' << @page_file_dir if @page_file_dir
|
||||||
|
|
||||||
search_output.split("\n").collect do |line|
|
@repo.git.grep(*args).split("\n").map! do |line|
|
||||||
result = line.split(':')
|
result = line.split(':')
|
||||||
file_name = Gollum::Page.canonicalize_filename(::File.basename(result[1]))
|
file_name = Gollum::Page.canonicalize_filename(::File.basename(result[1]))
|
||||||
|
|
||||||
@@ -470,13 +475,17 @@ module Gollum
|
|||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def update_working_dir(index, dir, name, format)
|
def update_working_dir(index, dir, name, format)
|
||||||
unless @repo.bare
|
unless @repo.bare
|
||||||
path =
|
if @page_file_dir
|
||||||
if dir == ''
|
dir = dir.size.zero? ? @page_file_dir : File.join(dir, @page_file_dir)
|
||||||
page_file_name(name, format)
|
|
||||||
else
|
|
||||||
::File.join(dir, page_file_name(name, format))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
path =
|
||||||
|
if dir == ''
|
||||||
|
page_file_name(name, format)
|
||||||
|
else
|
||||||
|
::File.join(dir, page_file_name(name, format))
|
||||||
|
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)
|
||||||
@repo.git.rm({'f' => true}, '--', path)
|
@repo.git.rm({'f' => true}, '--', path)
|
||||||
@@ -571,7 +580,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
|
||||||
|
|||||||
+3
-2
@@ -8,6 +8,7 @@ context "Frontend" do
|
|||||||
@path = cloned_testpath("examples/revert.git")
|
@path = cloned_testpath("examples/revert.git")
|
||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @path)
|
||||||
|
Precious::App.set(:wiki_options, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
@@ -16,7 +17,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "edits page" do
|
test "edits page" do
|
||||||
page_1 = @wiki.page('A')
|
page_1 = @wiki.page('A')
|
||||||
post "/edit/A", :content => 'abc',
|
post "/edit/A", :content => 'abc',
|
||||||
:format => page_1.format, :message => 'def'
|
:format => page_1.format, :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -56,7 +57,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "renames page" do
|
test "renames page" do
|
||||||
page_1 = @wiki.page('B')
|
page_1 = @wiki.page('B')
|
||||||
post "/edit/B", :content => 'abc',
|
post "/edit/B", :content => 'abc',
|
||||||
:rename => "C",
|
:rename => "C",
|
||||||
:format => page_1.format, :message => 'def'
|
:format => page_1.format, :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
|
|||||||
@@ -285,3 +285,45 @@ 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
|
||||||
|
|
||||||
|
test "search results should be restricted in page filer dir" do
|
||||||
|
results = @wiki.search("Hello")
|
||||||
|
assert_equal 1, results.size
|
||||||
|
assert_equal "foo", results[0][:name]
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_r(@path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user