Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove #with_ext #700

Merged
merged 1 commit into from Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 4 additions & 21 deletions lib/nanoc/base/entities/identifier.rb
Expand Up @@ -106,37 +106,20 @@ def prefix(string)
end

# @return [String]
def with_ext(ext)
def without_ext
unless full?
raise UnsupportedLegacyOperationError
end

# Strip extension, if any
extname = File.extname(@string)
string =
if extname.size > 0
@string[0..-extname.size - 1]
else
@string
end

# Add extension
if ext.size > 0
if ext.start_with?('.')
string + ext
else
string + '.' + ext
end
if extname.size > 0
@string[0..-extname.size - 1]
else
string
@string
end
end

# @return [String]
def without_ext
with_ext('')
end

# @return [String] The extension, without a leading dot.
def ext
unless full?
Expand Down
69 changes: 0 additions & 69 deletions spec/nanoc/base/entities/identifier_spec.rb
Expand Up @@ -242,75 +242,6 @@
end
end

describe '#with_ext' do
subject { identifier.with_ext(ext) }

context 'legacy type' do
let(:identifier) { described_class.new('/foo/', type: :legacy) }
let(:ext) { 'html' }

it 'raises an error' do
expect { subject }.to raise_error(Nanoc::Identifier::UnsupportedLegacyOperationError)
end
end

context 'identifier with no extension' do
let(:identifier) { described_class.new('/foo') }

context 'extension without dot given' do
let(:ext) { 'html' }

it 'adds an extension' do
expect(subject).to eql('/foo.html')
end
end

context 'extension with dot given' do
let(:ext) { '.html' }

it 'adds an extension' do
expect(subject).to eql('/foo.html')
end
end

context 'empty extension given' do
let(:ext) { '' }

it 'removes the extension' do
expect(subject).to eql('/foo')
end
end
end

context 'identifier with extension' do
let(:identifier) { described_class.new('/foo.md') }

context 'extension without dot given' do
let(:ext) { 'html' }

it 'adds an extension' do
expect(subject).to eql('/foo.html')
end
end

context 'extension with dot given' do
let(:ext) { '.html' }

it 'adds an extension' do
expect(subject).to eql('/foo.html')
end
end

context 'empty extension given' do
let(:ext) { '' }

it 'removes the extension' do
expect(subject).to eql('/foo')
end
end
end
end

describe '#without_ext' do
subject { identifier.without_ext }

Expand Down