usage 'create-site [options] path' aliases :create_site, :cs summary 'create a site' description 'Create a new site at the given path. The site will use the `filesystem` data source.' flag nil, :force, 'Force creation of new site. Disregards previous existence of site in destination' module Nanoc::CLI::Commands class CreateSite < ::Nanoc::CLI::CommandRunner class << self protected # Converts the given array to YAML format def array_to_yaml(array) '[ ' + array.map { |s| "'" + s + "'" }.join(', ') + ' ]' end end DEFAULT_CONFIG = <A Brand New Nanoc Site

You’ve just created a new Nanoc site. The page you are looking at right now is the home page for your site. To get started, consider replacing this default homepage with your own customized homepage. Some pointers on how to do so:

If you need any help with customizing your Nanoc web site, be sure to check out the documentation (see sidebar), and be sure to subscribe to the discussion group (also see sidebar). Enjoy!

EOS DEFAULT_STYLESHEET = < A Brand New Nanoc Site - <%= @item[:title] %>
<%= yield %>
EOS def run # Extract arguments if arguments.length != 1 raise Nanoc::Int::Errors::GenericTrivial, "usage: #{command.usage}" end path = arguments[0] # Check whether site exists if File.exist?(path) && (!File.directory?(path) || !(Dir.entries(path) - %w(. ..)).empty?) && !options[:force] raise Nanoc::Int::Errors::GenericTrivial, "The site was not created because '#{path}' already exists. " \ 'Re-run the command using --force to create the site anyway.' end # Setup notifications Nanoc::Int::NotificationCenter.on(:file_created) do |file_path| Nanoc::CLI::Logger.instance.file(:high, :create, file_path) 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 def write(filename, content) File.write(filename, content) Nanoc::Int::NotificationCenter.post(:file_created, filename) end end end runner Nanoc::CLI::Commands::CreateSite