Fix migration script when using page-file-dir (#1542)
This commit is contained in:
@@ -81,6 +81,7 @@ begin
|
||||
const = setting.to_s.upcase
|
||||
Object.const_set(const, value) unless Object.const_defined?(const)
|
||||
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
|
||||
puts "gollum-migrate-tags: #{$!.message}"
|
||||
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}")
|
||||
new_data = page.formatted_data
|
||||
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.write(new_data)
|
||||
f.close
|
||||
|
||||
+33
-18
@@ -23,7 +23,26 @@ waa
|
||||
[[Subsub/Zaa.md]]
|
||||
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']
|
||||
|
||||
@@ -35,33 +54,29 @@ unless ENV['TRAVIS']
|
||||
end
|
||||
|
||||
test 'repair broken links' do
|
||||
PREFER_RELATIVE = true
|
||||
RUN_SILENT = true
|
||||
NO_DRY_RUN = true
|
||||
HYPHENATE = false
|
||||
|
||||
Dir.chdir(@path) do
|
||||
load script_path
|
||||
end
|
||||
load_script
|
||||
|
||||
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
|
||||
assert_equal result, f.read
|
||||
end
|
||||
|
||||
test 'change spaced filenames to hyphenated filenames' do
|
||||
RUN_SILENT = true
|
||||
NO_DRY_RUN = true
|
||||
PREFER_RELATIVE = true
|
||||
HYPHENATE = true
|
||||
|
||||
Dir.chdir(@path) do
|
||||
load script_path
|
||||
end
|
||||
test 'change spaced filenames to hyphenated filenames' do
|
||||
load_script(hyphenate: true)
|
||||
|
||||
f = ::File.new(::File.join(@path, 'Home.textile'), 'r')
|
||||
output = f.read
|
||||
assert_equal true, output.include?('[[Bilbo-Baggins.md]]')
|
||||
assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]')
|
||||
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
|
||||
FileUtils.rm_rf(@path)
|
||||
|
||||
Reference in New Issue
Block a user