# encoding: utf-8 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_unified` data source by default, but this can be changed using the `--datasource` command-line option. " 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 # Check arguments if arguments.length != 1 raise Nanoc::Int::Errors::GenericTrivial, "usage: #{command.usage}" end # Extract arguments and options path = arguments[0] data_source = options[:datasource] || 'filesystem_unified' # Check whether site exists if File.exist?(path) && (!File.directory?(path) || !(Dir.entries(path) - %w{ . .. }).empty?) raise Nanoc::Int::Errors::GenericTrivial, "A site at '#{path}' already exists." end # Check whether data source exists if Nanoc::DataSource.named(data_source).nil? raise Nanoc::Int::Errors::GenericTrivial, "Unrecognised data source: #{data_source}" 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') # Config File.open('nanoc.yaml', 'w') { |io| io.write(DEFAULT_CONFIG) } Nanoc::Int::NotificationCenter.post(:file_created, 'nanoc.yaml') # Rules File.open('Rules', 'w') do |io| io.write DEFAULT_RULES end Nanoc::Int::NotificationCenter.post(:file_created, 'Rules') # Home page File.open('content/index.html', 'w') do |io| io << '---' << "\n" io << 'title: Home' << "\n" io << '---' << "\n" io << "\n" io << DEFAULT_ITEM end Nanoc::Int::NotificationCenter.post(:file_created, 'content/index.html') # Style sheet File.open('content/stylesheet.css', 'w') do |io| io << DEFAULT_STYLESHEET end Nanoc::Int::NotificationCenter.post(:file_created, 'content/stylesheet.css') # Layout File.open('layouts/default.html', 'w') do |io| io << DEFAULT_LAYOUT end Nanoc::Int::NotificationCenter.post(:file_created, 'layouts/default.html') end puts "Created a blank nanoc site at '#{path}'. Enjoy!" end end end runner Nanoc::CLI::Commands::CreateSite