Class: Nanoc3::CLI::Commands::CreateSite
- Inherits:
-
Cri::Command
- Object
- Cri::Command
- Nanoc3::CLI::Commands::CreateSite
- Defined in:
- lib/nanoc3/cli/commands/create_site.rb
Constant Summary
- DEFAULT_CONFIG =
<<EOS # 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(Nanoc3::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: #{Nanoc3::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.hml”, 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(Nanoc3::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 # The data sources where nanoc loads its data from. This is an array of # hashes; each array element represents a single data source. By default, # there is only a single data source that reads data from the “content/” and # “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: #{Nanoc3::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: #{Nanoc3::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: #{Nanoc3::Site::DEFAULT_DATA_SOURCE_CONFIG[:layouts_root]} EOS DEFAULT_RULES = <<EOS #!/usr/b- DEFAULT_RULES =
elpful tips about the Rules file: # # * The order of rules is important: for each item, only the first matching # rule is applied. # # * Item identifiers start and end with a slash (e.g. “/about/” for the file # “content/about.html”). To select all children, grandchildren, … of an # item, use the pattern “/about/*/”; “/about/*” will also select the parent, # because “*” matches zero or more characters. compile '/stylesheet/' do # don’t filter or layout end compile '*' do filter :erb layout 'default' end route '/stylesheet/' do '/style.css' end route '*' do item.identifier + 'index.html' end layout '*', :erb EOS DEFAULT_ITEM = <<EOS <h1>A Brand New nanoc Site</h1>- DEFAULT_ITEM =
d 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> <ul> <li><p><strong>Change this page’s content</strong> by editing the “index.html” file in the “content” directory. This is the actual page content, and therefore doesn’t include the header, sidebar or style information (those are part of the layout).</p></li> <li><p><strong>Change the layout</strong>, which is the “default.html” file in the “layouts” directory, and create something unique (and hopefully less bland).</p></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_STYLESHEET = <<EOS * { margin: 0; padding: 0; font-family: Ge- DEFAULT_STYLESHEET =
mes 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: 40px; left: 280px; width: 500px; } #main h1 { font-size: 40px; font-weight: normal; line-height: 40px; letter-spacing: -1px; } #main p { margin: 20px 0; font-size: 15px; line-height: 20px; } #main ul, #main ol { margin: 20px; } #main li { font-size: 15px; line-height: 20px; } #main ul li { list-style-type: square; } #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; } EOS DEFAULT_LAYOUT = <<EOS <!DOCTYPE HTML> <html lang="en"> <head>
- DEFAULT_LAYOUT =
tle>A Brand New nanoc Site - <%= @item[:title] %></title> <link rel="stylesheet" type="text/css" href="/style.css" media="screen"> <meta name="generator" content="nanoc #{Nanoc3::VERSION}"> </head> <body> <div id="main"> <%= yield %> </div> <div id="sidebar"> <h2>Documentation</h2> <ul> <li><a href="http://nanoc.stoneship.org/docs/">Documentation</a></li> <li><a href="http://nanoc.stoneship.org/docs/3-getting-started/">Getting Started</a></li> </ul> <h2>Community</h2> <ul> <li><a href="http://groups.google.com/group/nanoc/">Discussion Group</a></li> <li><a href="irc://chat.freenode.net/#nanoc">IRC Channel</a></li> <li><a href="http://projects.stoneship.org/trac/nanoc/">Wiki</a></li> </ul> </div> </body> </html> EOS def name 'create_site' end def aliases [ 'cs' ] end
Instance Method Summary (collapse)
- - (Object) aliases
- - (Object) long_desc
- - (Object) name
- - (Object) option_definitions
- - (Object) run( $stder, puts "usa)
- - (Object) short_desc
- - (Object) usage
Instance Method Details
- (Object) aliases
246 247 248 249 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 246
nd
def long_desc
'Creat
|
- (Object) long_desc
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 254
+
'filesystem_unified data source by default, but this can be ' +
'changed using the --datasource commandline option.'
end
def usage
"nanoc3 create_site [options] path"
end
def option_
|
- (Object) name
242 243 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 242
def short_desc
'create a site'
|
- (Object) option_definitions
264 265 266 267 268 269 270 271 272 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 264
'datasource', :short => 'd', :argument => :required,
:desc => 'specify the data source for the new site'
}
]
end
def run(options, arguments)
# Check arguments
if arguments.lengt
|
- (Object) run( $stder, puts "usa)
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 274
$stderr.puts "usage: #{usage}"
exit 1
end
# Extract arguments and options
path = arguments[0]
data_source = options[:datasource] || 'filesystem_unified'
# 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 Nanoc3::DataSource.named(data_source).nil?
$stderr.puts "Unrecognised data source: #{data_source}"
exit 1
end
# Setup notifications
Nanoc3::NotificationCenter.on(:file_created) do |file_path|
Nanoc3::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
# Creates a configuration file and a output directory for this
|
- (Object) short_desc
250 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 250 w site at the given path. The site will use |
- (Object) usage
260 261 262 263 264 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 260
tions
[
# --datasource
{
:l
|