class Nanoc::CLI::Commands::CreateSite

Constants

DEFAULT_CONFIG
DEFAULT_ITEM
DEFAULT_LAYOUT
DEFAULT_RULES
DEFAULT_STYLESHEET

Protected Class Methods

array_to_yaml(array) click to toggle source

Converts the given array to YAML format

# File lib/nanoc/cli/commands/create-site.rb, line 16
def array_to_yaml(array)
  '[ ' + array.map { |s| "'" + s + "'" }.join(', ') + ' ]'
end

Public Instance Methods

run() click to toggle source
# File lib/nanoc/cli/commands/create-site.rb, line 223
def run
  path = arguments[:path]

  # Check whether site exists
  if File.exist?(path) && (!File.directory?(path) || !(Dir.entries(path) - %w[. ..]).empty?) && !options[:force]
    raise(
      Nanoc::Core::TrivialError,
      "The site was not created because '#{path}' already exists. " \
      'Re-run the command using --force to create the site anyway.',
    )
  end

  # Build entire site
  FileUtils.mkdir_p(path)
  FileUtils.cd(File.join(path)) do
    FileUtils.mkdir_p('content')
    FileUtils.mkdir_p('layouts')
    FileUtils.mkdir_p('lib')
    FileUtils.mkdir_p('output')

    write('nanoc.yaml', DEFAULT_CONFIG)
    write('Rules', DEFAULT_RULES)
    write('content/index.html', DEFAULT_ITEM)
    write('content/stylesheet.css', DEFAULT_STYLESHEET)
    write('layouts/default.html', DEFAULT_LAYOUT)
  end

  puts "Created a blank Nanoc site at '#{path}'. Enjoy!"
end

Private Instance Methods

write(filename, content) click to toggle source
# File lib/nanoc/cli/commands/create-site.rb, line 255
def write(filename, content)
  File.write(filename, content)
  Nanoc::CLI::Logger.instance.file(:high, :create, filename)
end