Skip to content

Commit

Permalink
Let RulesModified check dependent objects as well
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Oct 21, 2018
1 parent 4ac8df1 commit deccf81
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
30 changes: 28 additions & 2 deletions nanoc/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb
Expand Up @@ -5,10 +5,36 @@ class RulesModified < Nanoc::Int::OutdatednessRule
affects_props :compiled_content, :path

def apply(obj, outdatedness_checker)
# Check rules of obj itself
if rules_modified?(obj, outdatedness_checker)
return Nanoc::Int::OutdatednessReasons::RulesModified
end

# Check rules of layouts used by obj
layouts = layouts_touched_by(obj, outdatedness_checker)
if layouts.any? { |layout| rules_modified?(layout, outdatedness_checker) }
return Nanoc::Int::OutdatednessReasons::RulesModified
end

nil
end

private

def rules_modified?(obj, outdatedness_checker)
seq_old = outdatedness_checker.action_sequence_store[obj]
seq_new = outdatedness_checker.action_sequence_for(obj).serialize
unless seq_old.eql?(seq_new)
Nanoc::Int::OutdatednessReasons::RulesModified

!seq_old.eql?(seq_new)
end

def layouts_touched_by(obj, outdatedness_checker)
actions = outdatedness_checker.action_sequence_store[obj]
layout_actions = actions.select { |a| a.first == :layout }

layout_actions.map do |layout_action|
layout_pattern = layout_action[1]
outdatedness_checker.site.layouts[layout_pattern]
end
end
end
Expand Down
36 changes: 36 additions & 0 deletions nanoc/spec/nanoc/regressions/gh_1372_spec.rb
@@ -0,0 +1,36 @@
# frozen_string_literal: true

describe 'GH-1372', site: true, stdio: true do
before do
FileUtils.mkdir_p('content')
File.write('content/home.erb', 'hello')

FileUtils.mkdir_p('layouts')
File.write('layouts/default.haml', '#main= yield')

File.write('Rules', <<~EOS)
compile '/*' do
layout '/default.*'
write ext: 'html'
end
layout '/**/*', :haml, remove_whitespace: false
EOS
end

example do
Nanoc::CLI.run(['--verbose'])

File.write('Rules', <<~EOS)
compile '/*' do
layout '/default.*'
write ext: 'html'
end
layout '/**/*', :haml, remove_whitespace: true
EOS

expect { Nanoc::CLI.run(['--verbose']) }
.to output(%r{update.*output/home\.html$}).to_stdout
end
end

0 comments on commit deccf81

Please sign in to comment.