Class: Nanoc::CLI::Commands::ShowPlugins Private
- Inherits:
-
Nanoc::CLI::CommandRunner
- Object
- Cri::CommandRunner
- Nanoc::CLI::CommandRunner
- Nanoc::CLI::Commands::ShowPlugins
- Defined in:
- lib/nanoc/cli/commands/show-plugins.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.
Constant Summary collapse
- PLUGIN_CLASS_ORDER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
rubocop:disable Style/MutableConstant These constants are intended to be mutated (through #add_plugin_class)
[ Nanoc::Core::Filter, Nanoc::Core::DataSource, ]
- PLUGIN_CLASSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ Nanoc::Core::Filter => 'Filters', Nanoc::Core::DataSource => 'Data Sources', }
Class Method Summary collapse
Instance Method Summary collapse
-
#run ⇒ Object
private
rubocop:enable Style/MutableConstant.
Methods inherited from Nanoc::CLI::CommandRunner
#call, #debug?, enter_site_dir, find_site_dir, #in_site_dir?, #load_site
Class Method Details
.add_plugin_class(klass, name) ⇒ 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.
84 85 86 87 |
# File 'lib/nanoc/cli/commands/show-plugins.rb', line 84 def self.add_plugin_class(klass, name) PLUGIN_CLASS_ORDER << klass PLUGIN_CLASSES[klass] = name end |
Instance Method Details
#run ⇒ 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.
rubocop:enable Style/MutableConstant
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nanoc/cli/commands/show-plugins.rb', line 29 def run # Get list of plugins (before and after) plugins_before = PLUGIN_CLASSES.keys.each_with_object({}) { |c, acc| acc[c] = c.all } site = load_site site&.code_snippets plugins_after = PLUGIN_CLASSES.keys.each_with_object({}) { |c, acc| acc[c] = c.all } # Divide list of plugins into builtin and custom plugins_builtin = plugins_before plugins_custom = plugins_after.each_with_object({}) do |(superclass, klasses), acc| acc[superclass] = klasses - plugins_before[superclass] end # Find max identifiers length all_identifiers = plugins_after.values.flatten.map(&:identifiers) max_identifiers_length = all_identifiers.map(&:to_s).map(&:size).max PLUGIN_CLASS_ORDER.each do |superclass| plugins_with_this_superclass = { builtin: plugins_builtin.fetch(superclass, []), custom: plugins_custom.fetch(superclass, []), } # Print kind kind = name_for_plugin_class(superclass) puts "#{kind}:" puts # Print plugins organised by subtype %i[builtin custom].each do |type| # Find relevant plugins relevant_plugins = plugins_with_this_superclass[type] # Print type puts " #{type}:" if relevant_plugins.empty? puts ' (none)' next end # Print plugins relevant_plugins.sort_by { |k| k.identifiers.join(', ') }.each do |plugin| # Display puts format( " %-#{max_identifiers_length}s (%s)", plugin.identifiers.join(', '), plugin.to_s.sub(/^::/, ''), ) end end puts end end |