Class: Nanoc::CLI::Commands::ShowRules Private

Inherits:
Nanoc::CLI::CommandRunner show all
Defined in:
lib/nanoc/cli/commands/show-rules.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Nanoc::CLI::CommandRunner

#call, #debug?, #in_site_dir?, #load_site, #site, #site=

Instance Method Details

#explain_item(item) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
36
37
38
# File 'lib/nanoc/cli/commands/show-rules.rb', line 29

def explain_item(item)
  puts "#{@c.c('Item ' + item.identifier, :bold, :yellow)}:"

  @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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nanoc/cli/commands/show-rules.rb', line 40

def explain_layout(layout)
  puts "#{@c.c('Layout ' + layout.identifier, :bold, :yellow)}:"

  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

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nanoc/cli/commands/show-rules.rb', line 10

def run
  load_site

  @c = Nanoc::CLI::ANSIStringColorizer
  @reps = site.compiler.reps

  action_provider = site.compiler.action_provider
  unless action_provider.respond_to?(:rules_collection)
    raise(
      ::Nanoc::Int::Errors::GenericTrivial,
      'The show-rules command can only be used for sites with the Rule DSL action provider.',
    )
  end
  @rules = action_provider.rules_collection

  site.items.sort_by(&:identifier).each   { |e| explain_item(e) }
  site.layouts.sort_by(&:identifier).each { |e| explain_layout(e) }
end