Parent

Class/Module Index [+]

Quicksearch

Nanoc3::CLI::Base

Public Class Methods

new() click to toggle source
# File lib/nanoc3/cli/base.rb, line 6
def initialize
  super('nanoc3')

  # Add help command
  self.help_command = Nanoc3::CLI::Commands::Help.new
  add_command(self.help_command)

  # Add other commands
  add_command(Nanoc3::CLI::Commands::Autocompile.new)
  add_command(Nanoc3::CLI::Commands::Compile.new)
  add_command(Nanoc3::CLI::Commands::CreateLayout.new)
  add_command(Nanoc3::CLI::Commands::CreateItem.new)
  add_command(Nanoc3::CLI::Commands::CreateSite.new)
  add_command(Nanoc3::CLI::Commands::Debug.new)
  add_command(Nanoc3::CLI::Commands::Info.new)
  add_command(Nanoc3::CLI::Commands::Update.new)
  add_command(Nanoc3::CLI::Commands::View.new)
end
shared_base() click to toggle source
# File lib/nanoc3/cli/base.rb, line 25
def self.shared_base
  @shared_base ||= Nanoc3::CLI::Base.new
end

Public Instance Methods

global_option_definitions() click to toggle source

Returns the list of global option definitionss.

# File lib/nanoc3/cli/base.rb, line 173
def global_option_definitions
  [
    {
      :long => 'help', :short => 'h', :argument => :forbidden,
      :desc => 'show this help message and quit'
    },
    {
      :long => 'no-color', :short => 'C', :argument => :forbidden,
      :desc => 'disable color'
    },
    {
      :long => 'version', :short => 'v', :argument => :forbidden,
      :desc => 'show version information and quit'
    },
    {
      :long => 'verbose', :short => 'V', :argument => :forbidden,
      :desc => 'make nanoc output more detailed'
    },
    {
      :long => 'debug', :short => 'd', :argument => :forbidden,
      :desc => 'enable debugging (set $DEBUG to true)'
    },
    {
      :long => 'warn', :short => 'w', :argument => :forbidden,
      :desc => 'enable warnings'
    }
  ]
end
handle_option(option) click to toggle source
# File lib/nanoc3/cli/base.rb, line 202
def handle_option(option)
  case option
  when :version
    gem_info = defined?(Gem) ? "with RubyGems #{Gem::VERSION}" : "without RubyGems"

    puts "nanoc #{Nanoc3::VERSION} (c) 2007-2010 Denis Defreyne."
    puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM} #{gem_info}"
    exit 0
  when :verbose
    Nanoc3::CLI::Logger.instance.level = :low
  when :debug
    $DEBUG = true
  when :warn
    $-w = true
  when :'no-color'
    Nanoc3::CLI::Logger.instance.color = false
  when :help
    show_help
    exit 0
  end
end
require_site() click to toggle source

Helper function which can be called when a command is executed that requires a site, such as the compile command.

# File lib/nanoc3/cli/base.rb, line 31
def require_site
  if site.nil?
    $stderr.puts 'The current working directory does not seem to be a ' +
                 'valid/complete nanoc site directory; aborting.'
    exit 1
  end
end
resolution_for(error) click to toggle source

Returns a string containing hints for resolving the given error, or nil if no resolution can be automatically obtained.

# File lib/nanoc3/cli/base.rb, line 111
def resolution_for(error)
  # FIXME this should probably go somewhere else so that 3rd-party code can add other gem names too
  gem_names = {
    'adsf'           => 'adsf',
    'bluecloth'      => 'bluecloth',
    'builder'        => 'builder',
    'coderay'        => 'coderay',
    'cri'            => 'cri',
    'erubis'         => 'erubis',
    'haml'           => 'haml',
    'json'           => 'json',
    'less'           => 'less',
    'markaby'        => 'markaby',
    'maruku'         => 'maruku',
    'mime/types'     => 'mime-types',
    'rack'           => 'rack',
    'rack/cache'     => 'rack-cache',
    'rainpress'      => 'rainpress',
    'rdiscount'      => 'rdiscount',
    'redcloth'       => 'redcloth',
    'rubypants'      => 'rubypants',
    'sass'           => 'sass',
    'w3c_validators' => 'w3c_validators'
  }

  case error
  when LoadError
    # Get gem name
    lib_name = error.message.match(/no such file to load -- ([^\s]+)/)[1]
    gem_name = gem_names[$1]

    # Build message
    if gem_name
      "Try installing the '#{gem_name}' gem (`gem install #{gem_name}`) and then re-running the command."
    end
  end
end
run(args) click to toggle source

Inherited from ::Cri::Base

# File lib/nanoc3/cli/base.rb, line 55
def run(args)
  super(args)
rescue Interrupt => e
  exit(1)
rescue StandardError, ScriptError => e
  print_error(e)
  exit(1)
end
set_vcs(vcs_name) click to toggle source

Sets the data source’s VCS to the VCS with the given name. Does nothing when the site’s data source does not support VCSes (i.e. does not implement vcs=).

# File lib/nanoc3/cli/base.rb, line 152
def set_vcs(vcs_name)
  # Skip if not possible
  return if vcs_name.nil? || site.nil?

  # Find VCS
  vcs_class = Nanoc3::Extra::VCS.named(vcs_name.to_sym)
  if vcs_class.nil?
    $stderr.puts "A VCS named #{vcs_name} was not found; aborting."
    exit 1
  end

  site.data_sources.each do |data_source|
    # Skip if not possible
    next if !data_source.respond_to?(:vcs=)

    # Set VCS
    data_source.vcs = vcs_class.new
  end
end
site() click to toggle source

Gets the site (Nanoc3::Site) in the current directory and loads its data.

# File lib/nanoc3/cli/base.rb, line 40
def site
  # Load site if possible
  if File.file?('config.yaml') && (!self.instance_variable_defined?(:@site) || @site.nil?)
    begin
      @site = Nanoc3::Site.new('.')
    rescue Nanoc3::Errors::UnknownDataSource => e
      $stderr.puts "Unknown data source: #{e}"
      exit 1
    end
  end

  @site
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.