Extracted `sanitize_filename` from site.rb into reader.rb

- Extracted
 - Updated References
 - Ran Tests

Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
Martin Jorn Rogalla 2015-03-04 20:01:27 +01:00
parent ddfecb0f53
commit e586105b46
2 changed files with 7 additions and 7 deletions

View File

@ -73,5 +73,11 @@ module Jekyll
SafeYAML.load_file(path)
end
end
def sanitize_filename(name)
name.gsub!(/[^\w\s_-]+/, '')
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
name.gsub(/\s+/, '_')
end
end
end

View File

@ -232,7 +232,7 @@ module Jekyll
path = reader.in_source_dir(dir, entry)
next if File.symlink?(path) && safe
key = sanitize_filename(File.basename(entry, '.*'))
key = reader.sanitize_filename(File.basename(entry, '.*'))
if File.directory?(path)
read_data_to(path, data[key] = {})
else
@ -464,11 +464,5 @@ module Jekyll
def site_cleaner
@site_cleaner ||= Cleaner.new(self)
end
def sanitize_filename(name)
name.gsub!(/[^\w\s_-]+/, '')
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
name.gsub(/\s+/, '_')
end
end
end