lib/nanoc/cli/commands/show-rules.rb in nanoc-4.0.0b4 vs lib/nanoc/cli/commands/show-rules.rb in nanoc-4.0.0rc1
- old
+ new
@@ -8,51 +8,42 @@
module Nanoc::CLI::Commands
class ShowRules < ::Nanoc::CLI::CommandRunner
def run
require_site
- @c = Nanoc::CLI::ANSIStringColorizer
- @calc = site.compiler.rule_memory_calculator
+ @c = Nanoc::CLI::ANSIStringColorizer
+ @rules = site.compiler.rules_collection
- # TODO: explain /foo/
- # TODO: explain content/foo.html
- # TODO: explain output/foo/index.html
-
- site.items.each { |i| explain_item(i) }
- site.layouts.each { |l| explain_layout(l) }
+ site.items.sort_by(&:identifier).each { |e| explain_item(e) }
+ site.layouts.sort_by(&:identifier).each { |e| explain_layout(e) }
end
- protected
-
def explain_item(item)
puts "#{@c.c('Item ' + item.identifier, :bold, :yellow)}:"
- puts " (from #{item[:filename]})" if item[:filename]
+
item.reps.each do |rep|
- puts " Rep #{rep.name}:"
- if @calc[rep].empty? && rep.raw_path.nil?
- puts ' (nothing)'
- else
- @calc[rep].each do |mem|
- puts format(' %s %s',
- @c.c(format('%-10s', mem[0].to_s), :blue),
- mem[1..-1].map(&:inspect).join(', '))
- end
- if rep.raw_path
- puts format(' %s %s',
- @c.c(format('%-10s', 'write to'), :blue),
- rep.raw_path)
- end
- end
+ rule = @rules.compilation_rule_for(rep)
+ puts " Rep #{rep.name}: #{rule ? rule.pattern : '(none)'}"
end
+
puts
end
def explain_layout(layout)
puts "#{@c.c('Layout ' + layout.identifier, :bold, :yellow)}:"
- puts " (from #{layout[:filename]})" if layout[:filename]
- puts format(' %s %s',
- @c.c(format('%-10s', 'filter'), :blue),
- @calc[layout].map(&:inspect).join(', '))
+
+ found = false
+ @rules.layout_filter_mapping.each do |pattern, _|
+ if pattern.match?(layout.identifier)
+ puts " #{pattern}"
+ found = true
+ break
+ end
+ end
+ unless found
+ puts ' (none)'
+ end
+
puts
end
end
end