class Nanoc::OrigCLI::Commands::ShowRules

Public Instance Methods

explain_item(item, rules:, reps:) click to toggle source
# File lib/nanoc/orig_cli/commands/show-rules.rb, line 29
def explain_item(item, rules:, reps:)
  puts(fmt_heading("Item #{item.identifier}") + ':')

  reps[item].each do |rep|
    rule = rules.compilation_rule_for(rep)
    puts "  Rep #{rep.name}: #{rule ? rule.pattern : '(none)'}"
  end

  puts
end
explain_layout(layout, rules:) click to toggle source
# File lib/nanoc/orig_cli/commands/show-rules.rb, line 40
def explain_layout(layout, rules:)
  puts(fmt_heading("Layout #{layout.identifier}") + ':')

  found = false
  rules.layout_filter_mapping.each_key do |pattern|
    if pattern.match?(layout.identifier)
      puts "  #{pattern}"
      found = true
      break
    end
  end
  unless found
    puts '  (none)'
  end

  puts
end
fmt_heading(str) click to toggle source
# File lib/nanoc/orig_cli/commands/show-rules.rb, line 58
def fmt_heading(str)
  Nanoc::CLI::ANSIStringColorizer.c(str, :bold, :yellow)
end
run() click to toggle source
# File lib/nanoc/orig_cli/commands/show-rules.rb, line 13
def run
  site = load_site

  res = Nanoc::Core::Compiler.new_for(site).run_until_reps_built
  reps = res.fetch(:reps)

  action_provider = Nanoc::Core::ActionProvider.named(site.config.action_provider).for(site)
  rules = action_provider.rules_collection

  items = site.items.sort_by(&:identifier)
  layouts = site.layouts.sort_by(&:identifier)

  items.each   { |e| explain_item(e, rules:, reps:) }
  layouts.each { |e| explain_layout(e, rules:) }
end