Skip to content

Commit

Permalink
Include extra_attributes in attributes checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jan 3, 2017
1 parent c162a1f commit e8ed7c8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/nanoc/data_sources/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,21 @@ def load_objects(dir_name, klass)
attributes,
identifier,
content_checksum_data: proto_doc.content_checksum_data,
attributes_checksum_data: proto_doc.attributes_checksum_data,
attributes_checksum_data: attributes_checksum_data_for(proto_doc, content_filename, meta_filename),
)
end
end

res
end

def attributes_checksum_data_for(proto_doc, content_filename, meta_filename)
YAML.dump(
attributes: proto_doc.attributes_checksum_data,
extra_attributes: extra_attributes_for(content_filename, meta_filename),
)
end

def extra_attributes_for(content_filename, meta_filename)
{
filename: content_filename,
Expand Down
14 changes: 13 additions & 1 deletion spec/nanoc/data_sources/filesystem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@
expect(subject[0].identifier).to eq(Nanoc::Identifier.new('/bar/'))
expect(subject[0].checksum_data).to be_nil
expect(subject[0].content_checksum_data).to eq('test 1')
expect(subject[0].attributes_checksum_data).to eq("num: 1\n")
end

it 'has the right attributes checksum data' do
cs = YAML.load(subject[0].attributes_checksum_data)

expect(cs[:attributes]).to eq("num: 1\n")
expect(cs[:extra_attributes]).to eq(
filename: 'foo/bar.html',
content_filename: 'foo/bar.html',
meta_filename: nil,
extension: 'html',
mtime: now,
)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/nanoc/integration/outdatedness_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
describe 'Outdatedness integration', site: true, stdio: true do
context 'only attribute dependency' do
let(:time) { Time.now }

before do
File.write('content/foo.md', "---\ntitle: hello\n---\n\nfoo")
File.write('content/bar.md', '<%= @items["/foo.*"][:title] %>')

FileUtils.touch('content/foo.md', mtime: time)
FileUtils.touch('content/bar.md', mtime: time)

File.write('Rules', <<EOS)
compile '/foo.*' do
write '/foo.html'
Expand All @@ -29,6 +34,7 @@

it 'shows file as outdated after modification' do
File.write('content/bar.md', 'JUST BAR!')
FileUtils.touch('content/bar.md', mtime: time)

expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
output(/^item \/foo\.md, rep default:\n is not outdated/).to_stdout,
Expand All @@ -40,6 +46,7 @@

it 'shows file and dependencies as not outdated after content modification' do
File.write('content/foo.md', "---\ntitle: hello\n---\n\nfoooOoooOOoooOooo")
FileUtils.touch('content/foo.md', mtime: time)

expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
output(/^item \/foo\.md, rep default:\n is outdated: /).to_stdout,
Expand All @@ -51,6 +58,7 @@

it 'shows file and dependencies as outdated after title modification' do
File.write('content/foo.md', "---\ntitle: bye\n---\n\nfoo")
FileUtils.touch('content/foo.md', mtime: time)

expect { Nanoc::CLI.run(%w(show-data --no-color)) }.to(
output(/^item \/foo\.md, rep default:\n is outdated: /).to_stdout,
Expand Down
48 changes: 48 additions & 0 deletions spec/nanoc/regressions/gh_1045_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe 'GH-1045', site: true, stdio: true do
before do
File.write('content/foo.txt', 'foo')
FileUtils.touch('content/foo.txt', mtime: Time.parse('2015-03-02 10:00:00Z'))

File.write('content/sitemap.erb', '<%= xml_sitemap(items: items.select { |i| i.path.end_with?(\'/\') }) %>')

File.write('nanoc.yaml', <<EOS)
base_url: 'http://example.com'
EOS

File.write('lib/default.rb', <<EOS)
include Nanoc::Helpers::XMLSitemap
EOS

File.write('Rules', <<EOS)
compile '/*.txt' do
write item.identifier.without_ext + '/index.html'
end
compile '/sitemap.erb' do
filter :erb
write item.identifier.without_ext + '.xml'
end
EOS
end

it 'creates the sitemap' do
Nanoc::CLI.run(%w(compile))

expect(File.file?('output/sitemap.xml')).to be
contents = File.read('output/sitemap.xml')
expect(contents).to match(%r{<loc>http://example.com/foo/</loc>})
expect(contents).to match(%r{<lastmod>2015-03-02</lastmod>})
end

it 'updates the sitemap' do
Nanoc::CLI.run(%w(compile))
File.write('content/foo.txt', 'foo 2')
FileUtils.touch('content/foo.txt', mtime: Time.parse('2016-04-03 10:00:00Z'))
Nanoc::CLI.run(%w(compile))

expect(File.file?('output/sitemap.xml')).to be
contents = File.read('output/sitemap.xml')
expect(contents).to match(%r{<loc>http://example.com/foo/</loc>})
expect(contents).to match(%r{<lastmod>2016-04-03</lastmod>})
end
end

0 comments on commit e8ed7c8

Please sign in to comment.