Fix migration script when using page-file-dir (#1542)
This commit is contained in:
@@ -81,6 +81,7 @@ begin
|
|||||||
const = setting.to_s.upcase
|
const = setting.to_s.upcase
|
||||||
Object.const_set(const, value) unless Object.const_defined?(const)
|
Object.const_set(const, value) unless Object.const_defined?(const)
|
||||||
end
|
end
|
||||||
|
wiki_options[:page_file_dir] = setting(:page_file_dir) ? setting(:page_file_dir) : wiki_options[:page_file_dir] # Allow settings :page_file_dir through PAGE_FILE_DIR constant.
|
||||||
rescue OptionParser::InvalidOption
|
rescue OptionParser::InvalidOption
|
||||||
puts "gollum-migrate-tags: #{$!.message}"
|
puts "gollum-migrate-tags: #{$!.message}"
|
||||||
puts "gollum-migrate-tags: try 'gollum-migrate-tags --help' for more information"
|
puts "gollum-migrate-tags: try 'gollum-migrate-tags --help' for more information"
|
||||||
@@ -261,7 +262,7 @@ wiki.pages.each do |page|
|
|||||||
log(:info,"Page #{page.path}")
|
log(:info,"Page #{page.path}")
|
||||||
new_data = page.formatted_data
|
new_data = page.formatted_data
|
||||||
if setting(:no_dry_run)
|
if setting(:no_dry_run)
|
||||||
path = ::File.join([wiki.path, wiki.page_file_dir, page.path].compact)
|
path = ::File.join(wiki.path, page.path)
|
||||||
f = File.new(path, 'w')
|
f = File.new(path, 'w')
|
||||||
f.write(new_data)
|
f.write(new_data)
|
||||||
f.close
|
f.close
|
||||||
|
|||||||
+31
-16
@@ -23,7 +23,26 @@ waa
|
|||||||
[[Subsub/Zaa.md]]
|
[[Subsub/Zaa.md]]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags'))
|
def load_script(**args)
|
||||||
|
settings = {
|
||||||
|
:run_silent => true,
|
||||||
|
:no_dry_run => true,
|
||||||
|
:prefer_relative => true,
|
||||||
|
:hyphenate => false,
|
||||||
|
:page_file_dir => nil,
|
||||||
|
}.merge(args)
|
||||||
|
|
||||||
|
settings.each do |const, val|
|
||||||
|
const_name = const.to_s.upcase
|
||||||
|
Object.const_set(const_name, val) unless Object.const_defined?(const_name) && Object.const_get(const_name) == val
|
||||||
|
end
|
||||||
|
|
||||||
|
script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags'))
|
||||||
|
|
||||||
|
Dir.chdir(@path) do
|
||||||
|
load script_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
unless ENV['TRAVIS']
|
unless ENV['TRAVIS']
|
||||||
|
|
||||||
@@ -35,27 +54,14 @@ unless ENV['TRAVIS']
|
|||||||
end
|
end
|
||||||
|
|
||||||
test 'repair broken links' do
|
test 'repair broken links' do
|
||||||
PREFER_RELATIVE = true
|
load_script
|
||||||
RUN_SILENT = true
|
|
||||||
NO_DRY_RUN = true
|
|
||||||
HYPHENATE = false
|
|
||||||
|
|
||||||
Dir.chdir(@path) do
|
|
||||||
load script_path
|
|
||||||
end
|
|
||||||
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
|
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
|
||||||
assert_equal result, f.read
|
assert_equal result, f.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'change spaced filenames to hyphenated filenames' do
|
test 'change spaced filenames to hyphenated filenames' do
|
||||||
RUN_SILENT = true
|
load_script(hyphenate: true)
|
||||||
NO_DRY_RUN = true
|
|
||||||
PREFER_RELATIVE = true
|
|
||||||
HYPHENATE = true
|
|
||||||
|
|
||||||
Dir.chdir(@path) do
|
|
||||||
load script_path
|
|
||||||
end
|
|
||||||
|
|
||||||
f = ::File.new(::File.join(@path, 'Home.textile'), 'r')
|
f = ::File.new(::File.join(@path, 'Home.textile'), 'r')
|
||||||
output = f.read
|
output = f.read
|
||||||
@@ -63,6 +69,15 @@ unless ENV['TRAVIS']
|
|||||||
assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]')
|
assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'migration with page file dir' do
|
||||||
|
load_script(page_file_dir: 'Subdir')
|
||||||
|
|
||||||
|
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
|
||||||
|
output = f.read
|
||||||
|
assert_equal true, output.include?('[[Subsub/Zaa.md]]')
|
||||||
|
assert_equal true, output.include?('[[Samwi]]')
|
||||||
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_rf(@path)
|
FileUtils.rm_rf(@path)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user