Class: Nanoc2::CLI::CreateSiteCommand

Inherits:
Cri::Command
  • Object
show all
Defined in:
lib/nanoc2/cli/commands/create_site.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_PAGE =
<<EOS
<h1>A Brand New nanoc Site</h1>
<p>You&#8217;ve just created a new nanoc site. The page you are looking at right now is the home page for your site (and it&#8217;s probably the only page).</p>
<p>To get started, consider replacing this default homepage with your own customized homepage. Some pointers on how to do so:</p>
<ul>
  <li><strong>Change this page&#8217;s content</strong> by editing &#8220;content.txt&#8221; file in the &#8220;content&#8221; directory. This is the actual page content, and therefore doesn&#8217;t include the header, sidebar or style information (those are part of the layout).</li>
  <li><strong>Change the layout</strong>, which is the &#8220;default.txt&#8221; file in the &#8220;layouts/default&#8221; directory, and create something unique (and hopefully less bland).</li>
</ul>
<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 sidebar). Enjoy!</p>
EOS
DEFAULT_LAYOUT =
<<EOS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>A Brand New nanoc Site - <%= @page.title %></title>
    <style type="text/css" media="screen">
      * {
        margin: 0;
        padding: 0;
      
        font-family: Georgia, Palatino, Times, 'Times New Roman', sans-serif;
      }
      
      body {
        background: #fff;
      }
      
      a {
        text-decoration: none;
      }
      
      a:link,
      a:visited {
        color: #f30;
      }
      
      a:hover {
        color: #f90;
      }
      
      #main {
        position: absolute;
      
        top: 20px;
        left: 280px;
      
        width: 500px;
      }
      
      #main h1 {
        font-size: 40px;
        font-weight: normal;
      
        line-height: 40px;
      
        padding: 20px 0 20px 0;
      
        letter-spacing: -1px;
      }
      
      #main p {
        margin: 0 0 20px 0;
        
        font-size: 15px;
        
        line-height: 20px;
      }
      
      #main ul {
        padding: 0 0 0 20px;
      }
      
      #main li {
        margin: 0 0 20px 0;
      
        list-style-type: square;
      
        font-size: 15px;
        
        line-height: 20px;
      }
      
      #sidebar {
        position: absolute;
      
        top: 40px;
        left: 20px;
        width: 200px;
      
        padding: 20px 20px 0 0;
      
        border-right: 1px solid #ccc;
      
        text-align: right;
      }
      
      #sidebar h2 {
        text-transform: uppercase;
      
        font-size: 13px;
      
        color: #333;
      
        letter-spacing: 1px;
      
        line-height: 20px;
      }
      
      #sidebar ul {
        list-style-type: none;
      
        margin: 20px 0;
      }
      
      #sidebar li {
        font-size: 14px;
      
        line-height: 20px;
      }
    </style>
  </head>
  <body>
    <div id="main">
<%= @page_rep.content %>
    </div>
    <div id="sidebar">
      <h2>Documentation</h2>
      <ul>
        <li><a href="http://nanoc.stoneship.org/help/tutorial/">Tutorial</a></li>
        <li><a href="http://nanoc.stoneship.org/help/manual/">Manual</a></li>
      </ul>
      <h2>Community</h2>
      <ul>
        <li><a href="http://groups.google.com/group/nanoc/">Discussion Group</a></li>
        <li><a href="http://groups.google.com/group/nanoc-es/">Spanish Discussion Group</a></li>
        <li><a href="http://nanoc.stoneship.org/trac/">Wiki</a></li>
      </ul>
    </div>
  </body>
</html>
EOS

Instance Method Summary collapse

Instance Method Details

#aliasesObject



152
153
154
# File 'lib/nanoc2/cli/commands/create_site.rb', line 152

def aliases
  [ 'cs' ]
end

#long_descObject



160
161
162
163
164
# File 'lib/nanoc2/cli/commands/create_site.rb', line 160

def long_desc
  'Create a new site at the given path. The site will use the ' +
  'filesystem data source (but this can be changed later on). It will ' +
  'also include a few stub rakefiles to make adding new tasks easier.'
end

#nameObject



148
149
150
# File 'lib/nanoc2/cli/commands/create_site.rb', line 148

def name
  'create_site'
end

#option_definitionsObject



170
171
172
173
174
175
176
177
178
# File 'lib/nanoc2/cli/commands/create_site.rb', line 170

def option_definitions
  [
    # --datasource
    {
      :long => 'datasource', :short => 'd', :argument => :required,
      :desc => 'specify the data source for the new site'
    }
  ]
end

#run(options, arguments) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/nanoc2/cli/commands/create_site.rb', line 180

def run(options, arguments)
  # Check arguments
  if arguments.length != 1
    $stderr.puts "usage: #{usage}"
    exit 1
  end

  # Extract arguments and options
  path        = arguments[0]
  data_source = options[:datasource] || 'filesystem'

  # Check whether site exists
  if File.exist?(path)
    $stderr.puts "A site at '#{path}' already exists."
    exit 1
  end

  # Check whether data source exists
  if Nanoc2::DataSource.named(data_source).nil?
    $stderr.puts "Unrecognised data source: #{data_source}"
    exit 1
  end

  # Setup notifications
  Nanoc2::NotificationCenter.on(:file_created) do |file_path|
    Nanoc2::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

#short_descObject



156
157
158
# File 'lib/nanoc2/cli/commands/create_site.rb', line 156

def short_desc
  'create a site'
end

#usageObject



166
167
168
# File 'lib/nanoc2/cli/commands/create_site.rb', line 166

def usage
  "nanoc2 create_site [path]"
end