Class: Nanoc::CLI::Commands::CreateSite Private

Inherits:
Nanoc::CLI::CommandRunner show all
Defined in:
lib/nanoc/cli/commands/create-site.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

DEFAULT_GEMFILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"# frozen_string_literal: true\n\nsource 'https://rubygems.org'\n\ngem 'nanoc', '~> \#{Nanoc::CLI::VERSION.split(\n" unless defined? DEFAULT_GEMFILE
DEFAULT_CONFIG =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"      # A list of file extensions that Nanoc will consider to be textual rather than\n      # binary. If an item with an extension not in this list is found,  the file\n      # will be considered as binary.\n      text_extensions: \#{array_to_yaml(Nanoc::Core::Configuration::DEFAULT_CONFIG[:text_extensions])}\n\n      prune:\nauto_prune: true\n\n      data_sources:\n- type: filesystem\n" unless defined? DEFAULT_CONFIG
DEFAULT_RULES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"#!/usr/bin/env ruby\n\ncompile '/**/*.html' do\n  layout '/default.*'\n\n  if item.identifier =~ '**/index.*'\n    write item.identifier.to_s\n  else\n    write item.identifier.without_ext + '/index.html'\n  end\nend\n\n# This is an example rule that matches Markdown (.md) files, and filters them\n# using the :kramdown filter. It is commented out by default, because kramdown\n# is not bundled with Nanoc or Ruby.\n#\n#compile '/**/*.md' do\n#  filter :kramdown\n#  layout '/default.*'\n#\n#  if item.identifier =~ '**/index.*'\n#    write item.identifier.without_ext + '.html'\n#  else\n#    write item.identifier.without_ext + '/index.html'\n#  end\n#end\n\npassthrough '/**/*'\n" unless defined? DEFAULT_RULES
DEFAULT_ITEM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"---\ntitle: Home\n---\n\n<h1>A Brand New Nanoc Site</h1>\n\n<p>You\u2019ve 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:</p>\n\n<ul>\n  <li><p><strong>Change this page\u2019s content</strong> by editing the \u201Cindex.html\u201D file in the \u201Ccontent\u201D directory. This is the actual page content, and therefore doesn\u2019t include the header, sidebar or style information (those are part of the layout).</p></li>\n  <li><p><strong>Change the layout</strong>, which is the \u201Cdefault.html\u201D file in the \u201Clayouts\u201D directory, and create something unique (and hopefully less bland).</p></li>\n</ul>\n\n<p>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\n" unless defined? DEFAULT_ITEM
DEFAULT_STYLESHEET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"      * {\nmargin: 0;\npadding: 0;\n\nfont-family: Georgia, Palatino, serif;\n      }\n\n      body {\nbackground: #fff;\n      }\n\n      a {\ntext-decoration: none;\n      }\n\n      a:link,\n      a:visited {\ncolor: #f30;\n      }\n\n      a:hover {\ncolor: #f90;\n      }\n\n      #main {\nposition: absolute;\n\ntop: 40px;\nleft: 280px;\n\nwidth: 500px;\n      }\n\n      #main h1 {\nfont-size: 40px;\nfont-weight: normal;\n\nline-height: 40px;\n\nletter-spacing: -1px;\n      }\n\n      #main p {\nmargin: 20px 0;\n\nfont-size: 15px;\n\nline-height: 20px;\n      }\n\n      #main ul, #main ol {\nmargin: 20px;\n      }\n\n      #main li {\nfont-size: 15px;\n\nline-height: 20px;\n      }\n\n      #main ul li {\nlist-style-type: square;\n      }\n\n      #sidebar {\nposition: absolute;\n\ntop: 40px;\nleft: 20px;\nwidth: 200px;\n\npadding: 20px 20px 0 0;\n\nborder-right: 1px solid #ccc;\n\ntext-align: right;\n      }\n\n      #sidebar h2 {\ntext-transform: uppercase;\n\nfont-size: 13px;\n\ncolor: #333;\n\nletter-spacing: 1px;\n\nline-height: 20px;\n      }\n\n      #sidebar ul {\nlist-style-type: none;\n\nmargin: 20px 0;\n      }\n\n      #sidebar li {\nfont-size: 14px;\n" unless defined? DEFAULT_STYLESHEET
DEFAULT_LAYOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"      <!DOCTYPE HTML>\n      <html lang=\"en\">\n        <head>\n<meta charset=\"utf-8\">\n<title>A Brand New Nanoc Site - <%= @item[:title] %></title>\n<link rel=\"stylesheet\" href=\"/stylesheet.css\">\n\n<!-- you don't need to keep this, but it's cool for stats! -->\n<meta name=\"generator\" content=\"Nanoc <%= Nanoc::VERSION %>\">\n        </head>\n        <body>\n<div id=\"main\">\n  <%= yield %>\n</div>\n<div id=\"sidebar\">\n  <h2>Documentation</h2>\n  <ul>\n    <li><a href=\"https://nanoc.app/doc/\">Documentation</a></li>\n    <li><a href=\"https://nanoc.app/doc/tutorial/\">Tutorial</a></li>\n  </ul>\n  <h2>Community</h2>\n  <ul>\n    <li><a href=\"http://groups.google.com/group/nanoc/\">Discussion group</a></li>\n    <li><a href=\"https://gitter.im/nanoc/nanoc\">Gitter channel</a></li>\n    <li><a href=\"https://nanoc.app/contributing/\">Contributing</a></li>\n  </ul>\n</div>\n" unless defined? DEFAULT_LAYOUT

Instance Method Summary collapse

Methods inherited from Nanoc::CLI::CommandRunner

#call, #debug?, enter_site_dir, find_site_dir, #in_site_dir?, #load_site

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/nanoc/cli/commands/create-site.rb', line 229

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('Gemfile', DEFAULT_GEMFILE)
    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