Skip to content

Commit

Permalink
Merge branch 'release-4.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 1, 2016
2 parents 42aa10f + 83c839c commit e5efa98
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
11 changes: 11 additions & 0 deletions NEWS.md
@@ -1,5 +1,16 @@
# Nanoc news

## 4.2.2 (???)

Fixes:

* Fixed confusing “invalid prefix” error message (#873, #879)
* Ensured filter arguments are frozen, to prevent outdatedness checker errors (#881, #886)

Enhancements:

* Added specific handling for `Sass::Importers::Filesystem` in the checksummer, which should reduce unnecessary recompiles in sites using Compass (#866, #884)

## 4.2.1 (2016-06-19)

Fixes:
Expand Down
6 changes: 6 additions & 0 deletions lib/nanoc/base/checksummer.rb
Expand Up @@ -194,6 +194,12 @@ def self.update(obj, _digest)

class RescueUpdateBehavior < UpdateBehavior
def self.update(obj, digest)
if obj.class.to_s == 'Sass::Importers::Filesystem'
digest.update('root=')
digest.update(obj.root)
return
end

data = begin
Marshal.dump(obj)
rescue
Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/base/entities/identifier.rb
Expand Up @@ -123,7 +123,7 @@ def +(other)
# @return [Nanoc::Identifier]
def prefix(string)
if string !~ /\A\//
raise InvalidPrefixError.new(@string)
raise InvalidPrefixError.new(string)
end
Nanoc::Identifier.new(string.sub(/\/+\z/, '') + @string, type: @type)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/nanoc/base/services/executor.rb
Expand Up @@ -21,6 +21,7 @@ def filter(rep, filter_name, filter_args = {})
# Run filter
last = rep.snapshot_contents[:last]
source = rep.binary? ? last.filename : last.string
filter_args.freeze
result = filter.setup_and_run(source, filter_args)
rep.snapshot_contents[:last] =
if filter.class.to_binary?
Expand Down Expand Up @@ -48,6 +49,7 @@ def layout(rep, layout_identifier, extra_filter_args = nil)
raise Nanoc::Int::Errors::Generic, "Cannot find rule for layout matching #{layout_identifier}"
end
filter_args = filter_args.merge(extra_filter_args || {})
filter_args.freeze

# Check whether item can be laid out
raise Nanoc::Int::Errors::CannotLayoutBinaryItem.new(rep) if rep.binary?
Expand Down
8 changes: 3 additions & 5 deletions lib/nanoc/cli/error_handler.rb
Expand Up @@ -233,11 +233,9 @@ def resolution_for(error)
end
when RuntimeError
if error.message =~ /^can't modify frozen/
'You attempted to modify immutable data. Some data, such as ' \
'item/layout attributes and raw item/layout content, can not ' \
'be modified once compilation has started. (This was ' \
'unintentionally possible in 3.1.x and before, but has been ' \
'disabled in 3.2.x in order to allow compiler optimisations.)'
'You attempted to modify immutable data. Some data cannot ' \
'be modified once compilation has started. Such data includes ' \
'content and attributes of items and layouts, and filter arguments.'
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/nanoc/base/checksummer_spec.rb
Expand Up @@ -276,6 +276,14 @@
it { is_expected.to eql('Nanoc::ItemCollectionWithoutRepsView<Nanoc::Int::IdentifiableCollection<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<foo>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<bar>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,>>') }
end

context 'Sass::Importers::Filesystem' do
let(:obj) { Sass::Importers::Filesystem.new('/foo') }

before { require 'sass' }

it { is_expected.to eql('Sass::Importers::Filesystem<root=/foo>') }
end

context 'other marshal-able classes' do
let(:obj) { klass.new('hello') }

Expand Down
10 changes: 8 additions & 2 deletions spec/nanoc/base/entities/identifier_spec.rb
Expand Up @@ -244,15 +244,21 @@
let(:prefix) { 'asdf' }

it 'raises an error' do
expect { subject }.to raise_error(Nanoc::Identifier::InvalidPrefixError)
expect { subject }.to raise_error(
Nanoc::Identifier::InvalidPrefixError,
'Invalid prefix (does not start with a slash): "asdf"',
)
end
end

context 'prefix ending with a slash' do
let(:prefix) { 'asdf/' }

it 'raises an error' do
expect { subject }.to raise_error(Nanoc::Identifier::InvalidPrefixError)
expect { subject }.to raise_error(
Nanoc::Identifier::InvalidPrefixError,
'Invalid prefix (does not start with a slash): "asdf/"',
)
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/nanoc/base/services/executor_spec.rb
Expand Up @@ -217,6 +217,22 @@ def run(content, _params = {})

expect { executor.filter(rep, :whatever) }.to raise_frozen_error
end

it 'receives frozen filter args' do
filter_class = Class.new(::Nanoc::Filter) do
def run(_content, params = {})
params[:foo] = 'bar'
'asdf'
end
end

item = Nanoc::Int::Item.new('foo bar', {}, '/foo/')
rep = Nanoc::Int::ItemRep.new(item, :default)

expect(Nanoc::Filter).to receive(:named).with(:whatever) { filter_class }

expect { executor.filter(rep, :whatever) }.to raise_frozen_error
end
end

describe '#layout' do
Expand Down Expand Up @@ -361,6 +377,19 @@ def run(content, _params = {})
expect { subject }.to raise_error(Nanoc::Int::Errors::CannotLayoutBinaryItem)
end
end

it 'receives frozen filter args' do
filter_class = Class.new(::Nanoc::Filter) do
def run(_content, params = {})
params[:foo] = 'bar'
'asdf'
end
end

expect(Nanoc::Filter).to receive(:named).with(:erb) { filter_class }

expect { subject }.to raise_frozen_error
end
end

describe '#snapshot' do
Expand Down

0 comments on commit e5efa98

Please sign in to comment.