Class/Module Index [+]

Quicksearch

Nanoc::CLI::Commands::CreateSite

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 20
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 301
def run
  # Check arguments
  if arguments.length != 1
    raise Nanoc::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."
  end

  # Check whether data source exists
  if Nanoc::DataSource.named(data_source).nil?
    raise Nanoc::Errors::GenericTrivial, "Unrecognised data source: #{data_source}"
  end

  # Setup notifications
  Nanoc::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

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

Protected Instance Methods

site_create_minimal(data_source) click to toggle source

Creates a configuration file and a output directory for this site, as well as a rakefile that loads the standard nanoc tasks.

# File lib/nanoc/cli/commands/create-site.rb, line 341
def site_create_minimal(data_source)
  # Create output
  FileUtils.mkdir_p('output')

  # Create config
  File.open('nanoc.yaml', 'w') { |io| io.write(DEFAULT_CONFIG) }
  Nanoc::NotificationCenter.post(:file_created, 'nanoc.yaml')

  # Create rules
  File.open('Rules', 'w') do |io|
    io.write DEFAULT_RULES
  end
  Nanoc::NotificationCenter.post(:file_created, 'Rules')
end
site_populate() click to toggle source

Populates the site with some initial data, such as a root item, a default layout, and so on.

# File lib/nanoc/cli/commands/create-site.rb, line 370
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
end
site_setup() click to toggle source

Sets up the site's data source, i.e. creates the bare essentials for this data source to work.

# File lib/nanoc/cli/commands/create-site.rb, line 358
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.