Class: Nanoc3::CLI::Commands::CreateSite
- Inherits:
-
Nanoc3::CLI::Command
- Object
- Nanoc3::CLI::Command
- Nanoc3::CLI::Commands::CreateSite
- Defined in:
- lib/nanoc3/cli/commands/create_site.rb
Constant Summary collapse
- DEFAULT_CONFIG =
"# 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.\ntext_extensions: \#{array_to_yaml(Nanoc3::Site::DEFAULT_CONFIG[:text_extensions])}\n\n# The path to the directory where all generated files will be written to. This\n# can be an absolute path starting with a slash, but it can also be path\n# relative to the site directory.\noutput_dir: \#{Nanoc3::Site::DEFAULT_CONFIG[:output_dir]}\n\n# A list of index filenames, i.e. names of files that will be served by a web\n# server when a directory is requested. Usually, index files are named\n# \u201Cindex.html\u201D, but depending on the web server, this may be something else,\n# such as \u201Cdefault.htm\u201D. This list is used by nanoc to generate pretty URLs.\nindex_filenames: \#{array_to_yaml(Nanoc3::Site::DEFAULT_CONFIG[:index_filenames])}\n\n# Whether or not to generate a diff of the compiled content when compiling a\n# site. The diff will contain the differences between the compiled content\n# before and after the last site compilation.\nenable_output_diff: false\n\n# The data sources where nanoc loads its data from. This is an array of\n# hashes; each array element represents a single data source. By default,\n# there is only a single data source that reads data from the \u201Ccontent/\u201D and\n# \u201Clayout/\u201D directories in the site directory.\ndata_sources:\n -\n # The type is the identifier of the data source. By default, this will be\n # `filesystem_unified`.\n type: \#{Nanoc3::Site::DEFAULT_DATA_SOURCE_CONFIG[:type]}\n\n # The path where items should be mounted (comparable to mount points in\n # Unix-like systems). This is \u201C/\u201D by default, meaning that items will have\n # \u201C/\u201D prefixed to their identifiers. If the items root were \u201C/en/\u201D\n # instead, an item at content/about.html would have an identifier of\n # \u201C/en/about/\u201D instead of just \u201C/about/\u201D.\n items_root: \#{Nanoc3::Site::DEFAULT_DATA_SOURCE_CONFIG[:items_root]}\n\n # The path where layouts should be mounted. The layouts root behaves the\n # same as the items root, but applies to layouts rather than items.\n layouts_root: \#{Nanoc3::Site::DEFAULT_DATA_SOURCE_CONFIG[:layouts_root]}\n\n# Configuration for the \u201Cwatch\u201D command, which watches a site for changes and\n# recompiles if necessary.\nwatcher:\n # A list of directories to watch for changes. When editing this, make sure\n # that the \u201Coutput/\u201D and \u201Ctmp/\u201D directories are _not_ included in this list,\n # because recompiling the site will cause these directories to change, which\n # will cause the site to be recompiled, which will cause these directories\n # to change, which will cause the site to be recompiled again, and so on.\n dirs_to_watch: [ 'content', 'layouts', 'lib' ]\n\n # A list of single files to watch for changes. As mentioned above, don\u2019t put\n # any files from the \u201Coutput/\u201D or \u201Ctmp/\u201D directories in here.\n files_to_watch: [ 'config.yaml', 'Rules' ]\n\n # When to send notifications (using Growl or notify-send).\n notify_on_compilation_success: true\n notify_on_compilation_failure: true\n"- DEFAULT_RULES =
"#!/usr/bin/env ruby\n\n# A few helpful tips about the Rules file:\n#\n# * The string given to #compile and #route are matching patterns for\n# identifiers--not for paths. Therefore, you can\u2019t match on extension.\n#\n# * The order of rules is important: for each item, only the first matching\n# rule is applied.\n#\n# * Item identifiers start and end with a slash (e.g. \u201C/about/\u201D for the file\n# \u201Ccontent/about.html\u201D). To select all children, grandchildren, \u2026 of an\n# item, use the pattern \u201C/about/*/\u201D; \u201C/about/*\u201D will also select the parent,\n# because \u201C*\u201D matches zero or more characters.\n\ncompile '/stylesheet/' do\n # don\u2019t filter or layout\nend\n\ncompile '*' do\n if item.binary?\n # don\u2019t filter binary items\n else\n filter :erb\n layout 'default'\n end\nend\n\nroute '/stylesheet/' do\n '/style.css'\nend\n\nroute '*' do\n if item.binary?\n # Write item with identifier /foo/ to /foo.ext\n item.identifier.chop + '.' + item[:extension]\n else\n # Write item with identifier /foo/ to /foo/index.html\n item.identifier + 'index.html'\n end\nend\n\nlayout '*', :erb\n"- DEFAULT_ITEM =
"<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 sidebar). Enjoy!</p>\n"- DEFAULT_STYLESHEET =
"* {\n margin: 0;\n padding: 0;\n\n font-family: Georgia, Palatino, Times, 'Times New Roman', sans-serif;\n}\n\nbody {\n background: #fff;\n}\n\na {\n text-decoration: none;\n}\n\na:link,\na:visited {\n color: #f30;\n}\n\na:hover {\n color: #f90;\n}\n\n#main {\n position: absolute;\n\n top: 40px;\n left: 280px;\n\n width: 500px;\n}\n\n#main h1 {\n font-size: 40px;\n font-weight: normal;\n\n line-height: 40px;\n\n letter-spacing: -1px;\n}\n\n#main p {\n margin: 20px 0;\n \n font-size: 15px;\n \n line-height: 20px;\n}\n\n#main ul, #main ol {\n margin: 20px;\n}\n\n#main li {\n font-size: 15px;\n \n line-height: 20px;\n}\n\n#main ul li {\n list-style-type: square;\n}\n\n#sidebar {\n position: absolute;\n\n top: 40px;\n left: 20px;\n width: 200px;\n\n padding: 20px 20px 0 0;\n\n border-right: 1px solid #ccc;\n\n text-align: right;\n}\n\n#sidebar h2 {\n text-transform: uppercase;\n\n font-size: 13px;\n\n color: #333;\n\n letter-spacing: 1px;\n\n line-height: 20px;\n}\n\n#sidebar ul {\n list-style-type: none;\n\n margin: 20px 0;\n}\n\n#sidebar li {\n font-size: 14px;\n\n line-height: 20px;\n}\n"- DEFAULT_LAYOUT =
"<!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\" type=\"text/css\" href=\"/style.css\" media=\"screen\">\n <meta name=\"generator\" content=\"nanoc \#{Nanoc3::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=\"http://nanoc.stoneship.org/docs/\">Documentation</a></li>\n <li><a href=\"http://nanoc.stoneship.org/docs/3-getting-started/\">Getting Started</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=\"irc://chat.freenode.net/#nanoc\">IRC Channel</a></li>\n <li><a href=\"http://projects.stoneship.org/trac/nanoc/\">Wiki</a></li>\n </ul>\n </div>\n </body>\n</html>\n"- DEFAULT_RAKEFILE =
"begin\n require 'nanoc3/tasks'\nrescue LoadError\n require 'rubygems'\n require 'nanoc3/tasks'\nend\n"
Instance Attribute Summary
Attributes inherited from Nanoc3::CLI::Command
#arguments, #command, #options
Instance Method Summary collapse
Methods inherited from Nanoc3::CLI::Command
#call, call, #initialize, #site
Constructor Details
This class inherits a constructor from Nanoc3::CLI::Command
Instance Method Details
#run ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/nanoc3/cli/commands/create_site.rb', line 295 def run # Check arguments if arguments.length != 1 $stderr.puts "usage: #{command.usage}" exit 1 end # Extract arguments and options path = arguments[0] data_source = [: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 |