lib/nanoc/cli/commands/create-site.rb in nanoc-3.8.0 vs lib/nanoc/cli/commands/create-site.rb in nanoc-4.0.0a1

- old
+ new

@@ -5,12 +5,10 @@ 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. " -required :d, :datasource, 'specify the data source for the new site' - module Nanoc::CLI::Commands class CreateSite < ::Nanoc::CLI::CommandRunner class << self protected @@ -22,22 +20,22 @@ DEFAULT_CONFIG = <<EOS unless defined? DEFAULT_CONFIG # A list of file extensions that nanoc will consider to be textual rather than # binary. If an item with an extension not in this list is found, the file # will be considered as binary. -text_extensions: #{array_to_yaml(Nanoc::Site::DEFAULT_CONFIG[:text_extensions])} +text_extensions: #{array_to_yaml(Nanoc::Int::Site::DEFAULT_CONFIG[:text_extensions])} # The path to the directory where all generated files will be written to. This # can be an absolute path starting with a slash, but it can also be path # relative to the site directory. -output_dir: #{Nanoc::Site::DEFAULT_CONFIG[:output_dir]} +output_dir: #{Nanoc::Int::Site::DEFAULT_CONFIG[:output_dir]} # A list of index filenames, i.e. names of files that will be served by a web # server when a directory is requested. Usually, index files are named # “index.html”, but depending on the web server, this may be something else, # such as “default.htm”. This list is used by nanoc to generate pretty URLs. -index_filenames: #{array_to_yaml(Nanoc::Site::DEFAULT_CONFIG[:index_filenames])} +index_filenames: #{array_to_yaml(Nanoc::Int::Site::DEFAULT_CONFIG[:index_filenames])} # Whether or not to generate a diff of the compiled content when compiling a # site. The diff will contain the differences between the compiled content # before and after the last site compilation. enable_output_diff: false @@ -58,22 +56,22 @@ # “layout/” directories in the site directory. data_sources: - # The type is the identifier of the data source. By default, this will be # `filesystem_unified`. - type: #{Nanoc::Site::DEFAULT_DATA_SOURCE_CONFIG[:type]} + type: #{Nanoc::Int::Site::DEFAULT_DATA_SOURCE_CONFIG[:type]} # The path where items should be mounted (comparable to mount points in # Unix-like systems). This is “/” by default, meaning that items will have # “/” prefixed to their identifiers. If the items root were “/en/” # instead, an item at content/about.html would have an identifier of # “/en/about/” instead of just “/about/”. - items_root: #{Nanoc::Site::DEFAULT_DATA_SOURCE_CONFIG[:items_root]} + items_root: #{Nanoc::Int::Site::DEFAULT_DATA_SOURCE_CONFIG[:items_root]} # The path where layouts should be mounted. The layouts root behaves the # same as the items root, but applies to layouts rather than items. - layouts_root: #{Nanoc::Site::DEFAULT_DATA_SOURCE_CONFIG[:layouts_root]} + layouts_root: #{Nanoc::Int::Site::DEFAULT_DATA_SOURCE_CONFIG[:layouts_root]} # Whether to allow periods in identifiers. When turned off, everything # past the first period is considered to be the extension, and when # turned on, only the characters past the last period are considered to # be the extension. For example, a file named “content/about.html.erb” @@ -290,108 +288,73 @@ EOS def run # Check arguments if arguments.length != 1 - raise Nanoc::Errors::GenericTrivial, "usage: #{command.usage}" + 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) - raise Nanoc::Errors::GenericTrivial, "A site at '#{path}' already exists." + 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::Errors::GenericTrivial, "Unrecognised data source: #{data_source}" + raise Nanoc::Int::Errors::GenericTrivial, "Unrecognised data source: #{data_source}" end # Setup notifications - Nanoc::NotificationCenter.on(:file_created) do |file_path| + 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 - site_create_minimal(data_source) - site_setup - site_populate - end + FileUtils.mkdir_p('content') + FileUtils.mkdir_p('layouts') + FileUtils.mkdir_p('lib') + FileUtils.mkdir_p('output') - puts "Created a blank nanoc site at '#{path}'. Enjoy!" - end + # Config + File.open('nanoc.yaml', 'w') { |io| io.write(DEFAULT_CONFIG) } + Nanoc::Int::NotificationCenter.post(:file_created, 'nanoc.yaml') - protected + # Rules + File.open('Rules', 'w') do |io| + io.write DEFAULT_RULES + end + Nanoc::Int::NotificationCenter.post(:file_created, 'Rules') - # Creates a configuration file and a output directory for this site, as - # well as a rakefile that loads the standard nanoc tasks. - def site_create_minimal(_data_source) - # Create output - FileUtils.mkdir_p('output') + # 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') - # Create config - File.open('nanoc.yaml', 'w') { |io| io.write(DEFAULT_CONFIG) } - Nanoc::NotificationCenter.post(:file_created, 'nanoc.yaml') + # Style sheet + File.open('content/stylesheet.css', 'w') do |io| + io << DEFAULT_STYLESHEET + end + Nanoc::Int::NotificationCenter.post(:file_created, 'content/stylesheet.css') - # Create rules - File.open('Rules', 'w') do |io| - io.write DEFAULT_RULES + # Layout + File.open('layouts/default.html', 'w') do |io| + io << DEFAULT_LAYOUT + end + Nanoc::Int::NotificationCenter.post(:file_created, 'layouts/default.html') end - Nanoc::NotificationCenter.post(:file_created, 'Rules') - end - # Sets up the site's data source, i.e. creates the bare essentials for - # this data source to work. - def site_setup - # Get site - site = Nanoc::Site.new('.') - - # Set up data sources - site.data_sources.each do |data_source| - data_source.loading { data_source.setup } - end - end - - # Populates the site with some initial data, such as a root item, a - # default layout, and so on. - def site_populate - # Get site - site = Nanoc::Site.new('.') - data_source = site.data_sources[0] - - # Create home page - data_source.create_item( - DEFAULT_ITEM, - { title: 'Home' }, - '/' - ) - - # Create stylesheet - data_source.create_item( - DEFAULT_STYLESHEET, - {}, - '/stylesheet/', - extension: '.css' - ) - - # Create layout - data_source.create_layout( - DEFAULT_LAYOUT, - {}, - '/default/' - ) - - # Create code - FileUtils.mkdir_p('lib') - File.open('lib/default.rb', 'w') do |io| - io.write "\# All files in the 'lib' directory will be loaded\n" - io.write "\# before nanoc starts compiling.\n" - end + puts "Created a blank nanoc site at '#{path}'. Enjoy!" end end end runner Nanoc::CLI::Commands::CreateSite