Skip to content

Commit

Permalink
Merge pull request #700 from nanoc/remove-with-ext
Browse files Browse the repository at this point in the history
Remove #with_ext
  • Loading branch information
denisdefreyne committed Sep 18, 2015
2 parents 1191fed + 6a7ea46 commit e709b4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 90 deletions.
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

0 comments on commit e709b4b

Please sign in to comment.