Skip to content

Commit

Permalink
Paths like 'someFile.png' now get the title 'SomeFile' instead of 'So…
Browse files Browse the repository at this point in the history
…mefile'
  • Loading branch information
gettalong committed Mar 10, 2015
1 parent 8e3653b commit 5671005
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/webgen/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ def analyse
else
analyse_file
end
@meta_info['title'] ||= @basename.tr('_-', ' ').capitalize
@meta_info['title'] ||= begin
name = @basename.tr('_-', ' ')
name[0] = name[0].upcase
name
end
@ext ||= ''
raise "The basename of a path may not be empty: #{@path}" if @basename.empty? || @basename == '#'
raise "The parent path must start with a slash: #{@path}" if @path[0] != ?/
Expand Down
4 changes: 4 additions & 0 deletions test/webgen/test_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def test_initialize_and_accessors
check_proc.call(Webgen::Path.new('/dir/file.en.png', 'cn' => '<basename>(-<version>)<ext>', 'version' => 'hallo'),
'/dir/', 'file', 'en', 'png', 'file-hallo.png', 'file-hallo.en.png', '/dir/file-hallo.png', '/dir/file-hallo.en.png', nil, 'File')

# Check title generation
check_proc.call(Webgen::Path.new('/someFile.png'),
'/', 'someFile', nil, 'png', 'someFile.png', 'someFile.png', '/someFile.png', '/someFile.png', nil, 'SomeFile')

# Check general exceptions
assert_raises(RuntimeError) { Webgen::Path.new('/no_basename#').basename }
assert_raises(RuntimeError) { Webgen::Path.new('relative.page').basename }
Expand Down

0 comments on commit 5671005

Please sign in to comment.