nanoc 3.2.4 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/ChangeLog +3 -0
- data/Gemfile +32 -0
- data/LICENSE +19 -0
- data/NEWS.md +470 -0
- data/README.md +114 -0
- data/Rakefile +14 -0
- data/bin/nanoc +7 -27
- data/bin/nanoc3 +3 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/nanoc.rb +41 -0
- data/lib/nanoc/base.rb +49 -0
- data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
- data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
- data/lib/nanoc/base/compilation/compiler.rb +458 -0
- data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
- data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
- data/lib/nanoc/base/compilation/filter.rb +165 -0
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
- data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
- data/lib/nanoc/base/compilation/rule.rb +73 -0
- data/lib/nanoc/base/compilation/rule_context.rb +84 -0
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
- data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
- data/lib/nanoc/base/context.rb +47 -0
- data/lib/nanoc/base/core_ext.rb +6 -0
- data/lib/nanoc/base/core_ext/array.rb +62 -0
- data/lib/nanoc/base/core_ext/hash.rb +63 -0
- data/lib/nanoc/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc/base/core_ext/string.rb +46 -0
- data/lib/nanoc/base/directed_graph.rb +275 -0
- data/lib/nanoc/base/errors.rb +211 -0
- data/lib/nanoc/base/memoization.rb +67 -0
- data/lib/nanoc/base/notification_center.rb +84 -0
- data/lib/nanoc/base/ordered_hash.rb +200 -0
- data/lib/nanoc/base/plugin_registry.rb +181 -0
- data/lib/nanoc/base/result_data/item_rep.rb +492 -0
- data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
- data/lib/nanoc/base/source_data/configuration.rb +24 -0
- data/lib/nanoc/base/source_data/data_source.rb +234 -0
- data/lib/nanoc/base/source_data/item.rb +301 -0
- data/lib/nanoc/base/source_data/layout.rb +130 -0
- data/lib/nanoc/base/source_data/site.rb +361 -0
- data/lib/nanoc/base/store.rb +135 -0
- data/lib/nanoc/cli.rb +137 -0
- data/lib/nanoc/cli/command_runner.rb +104 -0
- data/lib/nanoc/cli/commands/autocompile.rb +58 -0
- data/lib/nanoc/cli/commands/compile.rb +297 -0
- data/lib/nanoc/cli/commands/create_item.rb +60 -0
- data/lib/nanoc/cli/commands/create_layout.rb +73 -0
- data/lib/nanoc/cli/commands/create_site.rb +411 -0
- data/lib/nanoc/cli/commands/debug.rb +117 -0
- data/lib/nanoc/cli/commands/deploy.rb +79 -0
- data/lib/nanoc/cli/commands/info.rb +98 -0
- data/lib/nanoc/cli/commands/nanoc.rb +38 -0
- data/lib/nanoc/cli/commands/prune.rb +50 -0
- data/lib/nanoc/cli/commands/update.rb +70 -0
- data/lib/nanoc/cli/commands/view.rb +82 -0
- data/lib/nanoc/cli/commands/watch.rb +124 -0
- data/lib/nanoc/cli/error_handler.rb +199 -0
- data/lib/nanoc/cli/logger.rb +92 -0
- data/lib/nanoc/data_sources.rb +29 -0
- data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
- data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
- data/lib/nanoc/data_sources/filesystem.rb +299 -0
- data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
- data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
- data/lib/nanoc/extra.rb +24 -0
- data/lib/nanoc/extra/auto_compiler.rb +103 -0
- data/lib/nanoc/extra/chick.rb +125 -0
- data/lib/nanoc/extra/core_ext.rb +6 -0
- data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
- data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
- data/lib/nanoc/extra/core_ext/time.rb +19 -0
- data/lib/nanoc/extra/deployer.rb +47 -0
- data/lib/nanoc/extra/deployers.rb +15 -0
- data/lib/nanoc/extra/deployers/fog.rb +98 -0
- data/lib/nanoc/extra/deployers/rsync.rb +70 -0
- data/lib/nanoc/extra/file_proxy.rb +40 -0
- data/lib/nanoc/extra/pruner.rb +86 -0
- data/lib/nanoc/extra/validators.rb +12 -0
- data/lib/nanoc/extra/validators/links.rb +268 -0
- data/lib/nanoc/extra/validators/w3c.rb +95 -0
- data/lib/nanoc/extra/vcs.rb +66 -0
- data/lib/nanoc/extra/vcses.rb +17 -0
- data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
- data/lib/nanoc/extra/vcses/dummy.rb +24 -0
- data/lib/nanoc/extra/vcses/git.rb +25 -0
- data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
- data/lib/nanoc/extra/vcses/subversion.rb +25 -0
- data/lib/nanoc/filters.rb +59 -0
- data/lib/nanoc/filters/asciidoc.rb +38 -0
- data/lib/nanoc/filters/bluecloth.rb +19 -0
- data/lib/nanoc/filters/coderay.rb +21 -0
- data/lib/nanoc/filters/coffeescript.rb +20 -0
- data/lib/nanoc/filters/colorize_syntax.rb +298 -0
- data/lib/nanoc/filters/erb.rb +38 -0
- data/lib/nanoc/filters/erubis.rb +34 -0
- data/lib/nanoc/filters/haml.rb +27 -0
- data/lib/nanoc/filters/kramdown.rb +20 -0
- data/lib/nanoc/filters/less.rb +53 -0
- data/lib/nanoc/filters/markaby.rb +20 -0
- data/lib/nanoc/filters/maruku.rb +20 -0
- data/lib/nanoc/filters/mustache.rb +24 -0
- data/lib/nanoc/filters/rainpress.rb +19 -0
- data/lib/nanoc/filters/rdiscount.rb +22 -0
- data/lib/nanoc/filters/rdoc.rb +33 -0
- data/lib/nanoc/filters/redcarpet.rb +62 -0
- data/lib/nanoc/filters/redcloth.rb +47 -0
- data/lib/nanoc/filters/relativize_paths.rb +94 -0
- data/lib/nanoc/filters/rubypants.rb +20 -0
- data/lib/nanoc/filters/sass.rb +74 -0
- data/lib/nanoc/filters/slim.rb +25 -0
- data/lib/nanoc/filters/typogruby.rb +23 -0
- data/lib/nanoc/filters/uglify_js.rb +42 -0
- data/lib/nanoc/filters/xsl.rb +46 -0
- data/lib/nanoc/filters/yui_compressor.rb +23 -0
- data/lib/nanoc/helpers.rb +16 -0
- data/lib/nanoc/helpers/blogging.rb +319 -0
- data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
- data/lib/nanoc/helpers/capturing.rb +138 -0
- data/lib/nanoc/helpers/filtering.rb +50 -0
- data/lib/nanoc/helpers/html_escape.rb +55 -0
- data/lib/nanoc/helpers/link_to.rb +151 -0
- data/lib/nanoc/helpers/rendering.rb +140 -0
- data/lib/nanoc/helpers/tagging.rb +71 -0
- data/lib/nanoc/helpers/text.rb +44 -0
- data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
- data/lib/nanoc/tasks.rb +10 -0
- data/lib/nanoc/tasks/clean.rake +16 -0
- data/lib/nanoc/tasks/clean.rb +29 -0
- data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
- data/lib/nanoc/tasks/validate.rake +92 -0
- data/nanoc.gemspec +49 -0
- data/tasks/doc.rake +16 -0
- data/tasks/test.rake +46 -0
- data/test/base/core_ext/array_spec.rb +73 -0
- data/test/base/core_ext/hash_spec.rb +98 -0
- data/test/base/core_ext/pathname_spec.rb +27 -0
- data/test/base/core_ext/string_spec.rb +37 -0
- data/test/base/test_checksum_store.rb +35 -0
- data/test/base/test_code_snippet.rb +31 -0
- data/test/base/test_compiler.rb +403 -0
- data/test/base/test_compiler_dsl.rb +161 -0
- data/test/base/test_context.rb +31 -0
- data/test/base/test_data_source.rb +46 -0
- data/test/base/test_dependency_tracker.rb +262 -0
- data/test/base/test_directed_graph.rb +288 -0
- data/test/base/test_filter.rb +83 -0
- data/test/base/test_item.rb +179 -0
- data/test/base/test_item_rep.rb +579 -0
- data/test/base/test_layout.rb +59 -0
- data/test/base/test_memoization.rb +90 -0
- data/test/base/test_notification_center.rb +34 -0
- data/test/base/test_outdatedness_checker.rb +394 -0
- data/test/base/test_plugin.rb +30 -0
- data/test/base/test_rule.rb +19 -0
- data/test/base/test_rule_context.rb +65 -0
- data/test/base/test_site.rb +190 -0
- data/test/cli/commands/test_compile.rb +33 -0
- data/test/cli/commands/test_create_item.rb +14 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_deploy.rb +74 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +11 -0
- data/test/cli/commands/test_prune.rb +98 -0
- data/test/cli/commands/test_update.rb +10 -0
- data/test/cli/test_cli.rb +102 -0
- data/test/cli/test_error_handler.rb +29 -0
- data/test/cli/test_logger.rb +10 -0
- data/test/data_sources/test_filesystem.rb +433 -0
- data/test/data_sources/test_filesystem_unified.rb +536 -0
- data/test/data_sources/test_filesystem_verbose.rb +357 -0
- data/test/extra/core_ext/test_enumerable.rb +30 -0
- data/test/extra/core_ext/test_pathname.rb +17 -0
- data/test/extra/core_ext/test_time.rb +15 -0
- data/test/extra/deployers/test_fog.rb +67 -0
- data/test/extra/deployers/test_rsync.rb +100 -0
- data/test/extra/test_auto_compiler.rb +417 -0
- data/test/extra/test_file_proxy.rb +19 -0
- data/test/extra/test_vcs.rb +22 -0
- data/test/extra/validators/test_links.rb +62 -0
- data/test/extra/validators/test_w3c.rb +47 -0
- data/test/filters/test_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +18 -0
- data/test/filters/test_coderay.rb +44 -0
- data/test/filters/test_coffeescript.rb +18 -0
- data/test/filters/test_colorize_syntax.rb +379 -0
- data/test/filters/test_erb.rb +105 -0
- data/test/filters/test_erubis.rb +78 -0
- data/test/filters/test_haml.rb +96 -0
- data/test/filters/test_kramdown.rb +18 -0
- data/test/filters/test_less.rb +113 -0
- data/test/filters/test_markaby.rb +24 -0
- data/test/filters/test_maruku.rb +18 -0
- data/test/filters/test_mustache.rb +25 -0
- data/test/filters/test_rainpress.rb +29 -0
- data/test/filters/test_rdiscount.rb +31 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcarpet.rb +73 -0
- data/test/filters/test_redcloth.rb +33 -0
- data/test/filters/test_relativize_paths.rb +533 -0
- data/test/filters/test_rubypants.rb +18 -0
- data/test/filters/test_sass.rb +229 -0
- data/test/filters/test_slim.rb +35 -0
- data/test/filters/test_typogruby.rb +21 -0
- data/test/filters/test_uglify_js.rb +30 -0
- data/test/filters/test_xsl.rb +105 -0
- data/test/filters/test_yui_compressor.rb +44 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +207 -0
- data/test/helpers/test_blogging.rb +754 -0
- data/test/helpers/test_breadcrumbs.rb +81 -0
- data/test/helpers/test_capturing.rb +41 -0
- data/test/helpers/test_filtering.rb +106 -0
- data/test/helpers/test_html_escape.rb +32 -0
- data/test/helpers/test_link_to.rb +249 -0
- data/test/helpers/test_rendering.rb +89 -0
- data/test/helpers/test_tagging.rb +87 -0
- data/test/helpers/test_text.rb +24 -0
- data/test/helpers/test_xml_sitemap.rb +103 -0
- data/test/tasks/test_clean.rb +67 -0
- metadata +327 -15
- data/bin/nanoc-select +0 -86
- data/lib/nanoc-select.rb +0 -11
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
usage 'create_item [options] identifier'
|
4
|
+
summary 'create an item'
|
5
|
+
aliases :ci
|
6
|
+
description <<-EOS
|
7
|
+
Create a new item in the current site. The first data source in the site
|
8
|
+
configuration will be used.
|
9
|
+
EOS
|
10
|
+
|
11
|
+
required :c, :vcs, 'specify the VCS to use'
|
12
|
+
|
13
|
+
module Nanoc::CLI::Commands
|
14
|
+
|
15
|
+
class CreateItem < ::Nanoc::CLI::CommandRunner
|
16
|
+
|
17
|
+
def run
|
18
|
+
# Check arguments
|
19
|
+
if arguments.length != 1
|
20
|
+
$stderr.puts "usage: #{command.usage}"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
# Extract arguments and options
|
25
|
+
identifier = arguments[0].cleaned_identifier
|
26
|
+
|
27
|
+
# Make sure we are in a nanoc site directory
|
28
|
+
self.require_site
|
29
|
+
|
30
|
+
# Set VCS if possible
|
31
|
+
self.set_vcs(options[:vcs])
|
32
|
+
|
33
|
+
# Check whether item is unique
|
34
|
+
if !self.site.items.find { |i| i.identifier == identifier }.nil?
|
35
|
+
$stderr.puts "An item already exists at #{identifier}. Please " +
|
36
|
+
"pick a unique name for the item you are creating."
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
# Setup notifications
|
41
|
+
Nanoc::NotificationCenter.on(:file_created) do |file_path|
|
42
|
+
Nanoc::CLI::Logger.instance.file(:high, :create, file_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Create item
|
46
|
+
data_source = self.site.data_sources[0]
|
47
|
+
data_source.create_item(
|
48
|
+
"Hi, I'm a new item!\n",
|
49
|
+
{ :title => "A New Item" },
|
50
|
+
identifier
|
51
|
+
)
|
52
|
+
|
53
|
+
puts "An item has been created at #{identifier}."
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
runner Nanoc::CLI::Commands::CreateItem
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
usage 'create_layout [options] identifier'
|
4
|
+
aliases 'cl'
|
5
|
+
summary 'create a layout'
|
6
|
+
description <<-EOS
|
7
|
+
Create a new layout in the current site. The first data source in the site
|
8
|
+
configuration will be used.
|
9
|
+
EOS
|
10
|
+
|
11
|
+
module Nanoc::CLI::Commands
|
12
|
+
|
13
|
+
class CreateLayout < ::Nanoc::CLI::CommandRunner
|
14
|
+
|
15
|
+
def run
|
16
|
+
# Check arguments
|
17
|
+
if arguments.length != 1
|
18
|
+
$stderr.puts "usage: #{command.usage}"
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
# Extract arguments
|
23
|
+
identifier = arguments[0].cleaned_identifier
|
24
|
+
|
25
|
+
# Make sure we are in a nanoc site directory
|
26
|
+
self.require_site
|
27
|
+
|
28
|
+
# Set VCS if possible
|
29
|
+
self.set_vcs(options[:vcs])
|
30
|
+
|
31
|
+
# Check whether layout is unique
|
32
|
+
if !self.site.layouts.find { |l| l.identifier == identifier }.nil?
|
33
|
+
$stderr.puts "A layout already exists at #{identifier}. Please " +
|
34
|
+
"pick a unique name for the layout you are creating."
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check whether layout is not at /
|
39
|
+
if identifier == '/'
|
40
|
+
$stderr.puts "There cannot be a layout with the identifier '/'; " +
|
41
|
+
"please pick a different identifier for this layout."
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
# Setup notifications
|
46
|
+
Nanoc::NotificationCenter.on(:file_created) do |file_path|
|
47
|
+
Nanoc::CLI::Logger.instance.file(:high, :create, file_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Create layout
|
51
|
+
data_source = self.site.data_sources[0]
|
52
|
+
data_source.create_layout(
|
53
|
+
"<html>\n" +
|
54
|
+
" <head>\n" +
|
55
|
+
" <title><%= @item[:title] %></title>\n" +
|
56
|
+
" </head>\n" +
|
57
|
+
" <body>\n" +
|
58
|
+
" <p>Hi, I'm a new layout. Please customize me!</p>\n" +
|
59
|
+
"<%= yield %>\n" +
|
60
|
+
" </body>\n" +
|
61
|
+
"</html>\n",
|
62
|
+
{},
|
63
|
+
identifier
|
64
|
+
)
|
65
|
+
|
66
|
+
puts "A layout has been created at #{identifier}."
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
runner Nanoc::CLI::Commands::CreateLayout
|
@@ -0,0 +1,411 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
usage 'create_site [options] path'
|
4
|
+
aliases 'cs'
|
5
|
+
summary 'create a site'
|
6
|
+
description <<-EOS
|
7
|
+
Create a new site at the given path. The site will use the filesystem_unified data source by default, but this can be changed using the --datasource commandline option.
|
8
|
+
EOS
|
9
|
+
|
10
|
+
required :d, :datasource, 'specify the data source for the new site'
|
11
|
+
|
12
|
+
module Nanoc::CLI::Commands
|
13
|
+
|
14
|
+
class CreateSite < ::Nanoc::CLI::CommandRunner
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
# Converts the given array to YAML format
|
21
|
+
def array_to_yaml(array)
|
22
|
+
'[ ' + array.map { |s| "'" + s + "'" }.join(', ') + ' ]'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
DEFAULT_CONFIG = <<EOS
|
28
|
+
# A list of file extensions that nanoc will consider to be textual rather than
|
29
|
+
# binary. If an item with an extension not in this list is found, the file
|
30
|
+
# will be considered as binary.
|
31
|
+
text_extensions: #{array_to_yaml(Nanoc::Site::DEFAULT_CONFIG[:text_extensions])}
|
32
|
+
|
33
|
+
# The path to the directory where all generated files will be written to. This
|
34
|
+
# can be an absolute path starting with a slash, but it can also be path
|
35
|
+
# relative to the site directory.
|
36
|
+
output_dir: #{Nanoc::Site::DEFAULT_CONFIG[:output_dir]}
|
37
|
+
|
38
|
+
# A list of index filenames, i.e. names of files that will be served by a web
|
39
|
+
# server when a directory is requested. Usually, index files are named
|
40
|
+
# “index.html”, but depending on the web server, this may be something else,
|
41
|
+
# such as “default.htm”. This list is used by nanoc to generate pretty URLs.
|
42
|
+
index_filenames: #{array_to_yaml(Nanoc::Site::DEFAULT_CONFIG[:index_filenames])}
|
43
|
+
|
44
|
+
# Whether or not to generate a diff of the compiled content when compiling a
|
45
|
+
# site. The diff will contain the differences between the compiled content
|
46
|
+
# before and after the last site compilation.
|
47
|
+
enable_output_diff: false
|
48
|
+
|
49
|
+
prune:
|
50
|
+
# Whether to automatically remove files not managed by nanoc from the output
|
51
|
+
# directory. For safety reasons, this is turned off by default.
|
52
|
+
auto_prune: false
|
53
|
+
|
54
|
+
# Which files and directories you want to exclude from pruning. If you version
|
55
|
+
# your output directory, you should probably exclude VCS directories such as
|
56
|
+
# .git, .svn etc.
|
57
|
+
exclude: [ '.git', '.hg', '.svn', 'CVS' ]
|
58
|
+
|
59
|
+
# The data sources where nanoc loads its data from. This is an array of
|
60
|
+
# hashes; each array element represents a single data source. By default,
|
61
|
+
# there is only a single data source that reads data from the “content/” and
|
62
|
+
# “layout/” directories in the site directory.
|
63
|
+
data_sources:
|
64
|
+
-
|
65
|
+
# The type is the identifier of the data source. By default, this will be
|
66
|
+
# `filesystem_unified`.
|
67
|
+
type: #{Nanoc::Site::DEFAULT_DATA_SOURCE_CONFIG[:type]}
|
68
|
+
|
69
|
+
# The path where items should be mounted (comparable to mount points in
|
70
|
+
# Unix-like systems). This is “/” by default, meaning that items will have
|
71
|
+
# “/” prefixed to their identifiers. If the items root were “/en/”
|
72
|
+
# instead, an item at content/about.html would have an identifier of
|
73
|
+
# “/en/about/” instead of just “/about/”.
|
74
|
+
items_root: #{Nanoc::Site::DEFAULT_DATA_SOURCE_CONFIG[:items_root]}
|
75
|
+
|
76
|
+
# The path where layouts should be mounted. The layouts root behaves the
|
77
|
+
# same as the items root, but applies to layouts rather than items.
|
78
|
+
layouts_root: #{Nanoc::Site::DEFAULT_DATA_SOURCE_CONFIG[:layouts_root]}
|
79
|
+
|
80
|
+
# Whether to allow periods in identifiers. When turned off, everything
|
81
|
+
# past the first period is considered to be the extension, and when
|
82
|
+
# turned on, only the characters past the last period are considered to
|
83
|
+
# be the extension. For example, a file named “content/about.html.erb”
|
84
|
+
# will have the identifier “/about/” when turned off, but when turned on
|
85
|
+
# it will become “/about.html/” instead.
|
86
|
+
allow_periods_in_identifiers: false
|
87
|
+
|
88
|
+
# Configuration for the “watch” command, which watches a site for changes and
|
89
|
+
# recompiles if necessary.
|
90
|
+
watcher:
|
91
|
+
# A list of directories to watch for changes. When editing this, make sure
|
92
|
+
# that the “output/” and “tmp/” directories are _not_ included in this list,
|
93
|
+
# because recompiling the site will cause these directories to change, which
|
94
|
+
# will cause the site to be recompiled, which will cause these directories
|
95
|
+
# to change, which will cause the site to be recompiled again, and so on.
|
96
|
+
dirs_to_watch: [ 'content', 'layouts', 'lib' ]
|
97
|
+
|
98
|
+
# A list of single files to watch for changes. As mentioned above, don’t put
|
99
|
+
# any files from the “output/” or “tmp/” directories in here.
|
100
|
+
files_to_watch: [ 'config.yaml', 'Rules' ]
|
101
|
+
|
102
|
+
# When to send notifications (using Growl or notify-send).
|
103
|
+
notify_on_compilation_success: true
|
104
|
+
notify_on_compilation_failure: true
|
105
|
+
EOS
|
106
|
+
|
107
|
+
DEFAULT_RULES = <<EOS
|
108
|
+
#!/usr/bin/env ruby
|
109
|
+
|
110
|
+
# A few helpful tips about the Rules file:
|
111
|
+
#
|
112
|
+
# * The string given to #compile and #route are matching patterns for
|
113
|
+
# identifiers--not for paths. Therefore, you can’t match on extension.
|
114
|
+
#
|
115
|
+
# * The order of rules is important: for each item, only the first matching
|
116
|
+
# rule is applied.
|
117
|
+
#
|
118
|
+
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
|
119
|
+
# “content/about.html”). To select all children, grandchildren, … of an
|
120
|
+
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
|
121
|
+
# because “*” matches zero or more characters.
|
122
|
+
|
123
|
+
compile '/stylesheet/' do
|
124
|
+
# don’t filter or layout
|
125
|
+
end
|
126
|
+
|
127
|
+
compile '*' do
|
128
|
+
if item.binary?
|
129
|
+
# don’t filter binary items
|
130
|
+
else
|
131
|
+
filter :erb
|
132
|
+
layout 'default'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
route '/stylesheet/' do
|
137
|
+
'/style.css'
|
138
|
+
end
|
139
|
+
|
140
|
+
route '*' do
|
141
|
+
if item.binary?
|
142
|
+
# Write item with identifier /foo/ to /foo.ext
|
143
|
+
item.identifier.chop + '.' + item[:extension]
|
144
|
+
else
|
145
|
+
# Write item with identifier /foo/ to /foo/index.html
|
146
|
+
item.identifier + 'index.html'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
layout '*', :erb
|
151
|
+
EOS
|
152
|
+
|
153
|
+
DEFAULT_ITEM = <<EOS
|
154
|
+
<h1>A Brand New nanoc Site</h1>
|
155
|
+
|
156
|
+
<p>You’ve 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>
|
157
|
+
|
158
|
+
<ul>
|
159
|
+
<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>
|
160
|
+
<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>
|
161
|
+
</ul>
|
162
|
+
|
163
|
+
<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>
|
164
|
+
EOS
|
165
|
+
|
166
|
+
DEFAULT_STYLESHEET = <<EOS
|
167
|
+
* {
|
168
|
+
margin: 0;
|
169
|
+
padding: 0;
|
170
|
+
|
171
|
+
font-family: Georgia, Palatino, Times, 'Times New Roman', sans-serif;
|
172
|
+
}
|
173
|
+
|
174
|
+
body {
|
175
|
+
background: #fff;
|
176
|
+
}
|
177
|
+
|
178
|
+
a {
|
179
|
+
text-decoration: none;
|
180
|
+
}
|
181
|
+
|
182
|
+
a:link,
|
183
|
+
a:visited {
|
184
|
+
color: #f30;
|
185
|
+
}
|
186
|
+
|
187
|
+
a:hover {
|
188
|
+
color: #f90;
|
189
|
+
}
|
190
|
+
|
191
|
+
#main {
|
192
|
+
position: absolute;
|
193
|
+
|
194
|
+
top: 40px;
|
195
|
+
left: 280px;
|
196
|
+
|
197
|
+
width: 500px;
|
198
|
+
}
|
199
|
+
|
200
|
+
#main h1 {
|
201
|
+
font-size: 40px;
|
202
|
+
font-weight: normal;
|
203
|
+
|
204
|
+
line-height: 40px;
|
205
|
+
|
206
|
+
letter-spacing: -1px;
|
207
|
+
}
|
208
|
+
|
209
|
+
#main p {
|
210
|
+
margin: 20px 0;
|
211
|
+
|
212
|
+
font-size: 15px;
|
213
|
+
|
214
|
+
line-height: 20px;
|
215
|
+
}
|
216
|
+
|
217
|
+
#main ul, #main ol {
|
218
|
+
margin: 20px;
|
219
|
+
}
|
220
|
+
|
221
|
+
#main li {
|
222
|
+
font-size: 15px;
|
223
|
+
|
224
|
+
line-height: 20px;
|
225
|
+
}
|
226
|
+
|
227
|
+
#main ul li {
|
228
|
+
list-style-type: square;
|
229
|
+
}
|
230
|
+
|
231
|
+
#sidebar {
|
232
|
+
position: absolute;
|
233
|
+
|
234
|
+
top: 40px;
|
235
|
+
left: 20px;
|
236
|
+
width: 200px;
|
237
|
+
|
238
|
+
padding: 20px 20px 0 0;
|
239
|
+
|
240
|
+
border-right: 1px solid #ccc;
|
241
|
+
|
242
|
+
text-align: right;
|
243
|
+
}
|
244
|
+
|
245
|
+
#sidebar h2 {
|
246
|
+
text-transform: uppercase;
|
247
|
+
|
248
|
+
font-size: 13px;
|
249
|
+
|
250
|
+
color: #333;
|
251
|
+
|
252
|
+
letter-spacing: 1px;
|
253
|
+
|
254
|
+
line-height: 20px;
|
255
|
+
}
|
256
|
+
|
257
|
+
#sidebar ul {
|
258
|
+
list-style-type: none;
|
259
|
+
|
260
|
+
margin: 20px 0;
|
261
|
+
}
|
262
|
+
|
263
|
+
#sidebar li {
|
264
|
+
font-size: 14px;
|
265
|
+
|
266
|
+
line-height: 20px;
|
267
|
+
}
|
268
|
+
EOS
|
269
|
+
|
270
|
+
DEFAULT_LAYOUT = <<EOS
|
271
|
+
<!DOCTYPE HTML>
|
272
|
+
<html lang="en">
|
273
|
+
<head>
|
274
|
+
<meta charset="utf-8">
|
275
|
+
<title>A Brand New nanoc Site - <%= @item[:title] %></title>
|
276
|
+
<link rel="stylesheet" type="text/css" href="/style.css" media="screen">
|
277
|
+
<meta name="generator" content="nanoc #{Nanoc::VERSION}">
|
278
|
+
</head>
|
279
|
+
<body>
|
280
|
+
<div id="main">
|
281
|
+
<%= yield %>
|
282
|
+
</div>
|
283
|
+
<div id="sidebar">
|
284
|
+
<h2>Documentation</h2>
|
285
|
+
<ul>
|
286
|
+
<li><a href="http://nanoc.stoneship.org/docs/">Documentation</a></li>
|
287
|
+
<li><a href="http://nanoc.stoneship.org/docs/3-getting-started/">Getting Started</a></li>
|
288
|
+
</ul>
|
289
|
+
<h2>Community</h2>
|
290
|
+
<ul>
|
291
|
+
<li><a href="http://groups.google.com/group/nanoc/">Discussion Group</a></li>
|
292
|
+
<li><a href="irc://chat.freenode.net/#nanoc">IRC Channel</a></li>
|
293
|
+
<li><a href="http://projects.stoneship.org/trac/nanoc/">Wiki</a></li>
|
294
|
+
</ul>
|
295
|
+
</div>
|
296
|
+
</body>
|
297
|
+
</html>
|
298
|
+
EOS
|
299
|
+
|
300
|
+
def run
|
301
|
+
# Check arguments
|
302
|
+
if arguments.length != 1
|
303
|
+
$stderr.puts "usage: #{command.usage}"
|
304
|
+
exit 1
|
305
|
+
end
|
306
|
+
|
307
|
+
# Extract arguments and options
|
308
|
+
path = arguments[0]
|
309
|
+
data_source = options[:datasource] || 'filesystem_unified'
|
310
|
+
|
311
|
+
# Check whether site exists
|
312
|
+
if File.exist?(path)
|
313
|
+
$stderr.puts "A site at '#{path}' already exists."
|
314
|
+
exit 1
|
315
|
+
end
|
316
|
+
|
317
|
+
# Check whether data source exists
|
318
|
+
if Nanoc::DataSource.named(data_source).nil?
|
319
|
+
$stderr.puts "Unrecognised data source: #{data_source}"
|
320
|
+
exit 1
|
321
|
+
end
|
322
|
+
|
323
|
+
# Setup notifications
|
324
|
+
Nanoc::NotificationCenter.on(:file_created) do |file_path|
|
325
|
+
Nanoc::CLI::Logger.instance.file(:high, :create, file_path)
|
326
|
+
end
|
327
|
+
|
328
|
+
# Build entire site
|
329
|
+
FileUtils.mkdir_p(path)
|
330
|
+
FileUtils.cd(File.join(path)) do
|
331
|
+
site_create_minimal(data_source)
|
332
|
+
site_setup
|
333
|
+
site_populate
|
334
|
+
end
|
335
|
+
|
336
|
+
puts "Created a blank nanoc site at '#{path}'. Enjoy!"
|
337
|
+
end
|
338
|
+
|
339
|
+
protected
|
340
|
+
|
341
|
+
# Creates a configuration file and a output directory for this site, as
|
342
|
+
# well as a rakefile that loads the standard nanoc tasks.
|
343
|
+
def site_create_minimal(data_source)
|
344
|
+
# Create output
|
345
|
+
FileUtils.mkdir_p('output')
|
346
|
+
|
347
|
+
# Create config
|
348
|
+
File.open('config.yaml', 'w') { |io| io.write(DEFAULT_CONFIG.make_compatible_with_env) }
|
349
|
+
Nanoc::NotificationCenter.post(:file_created, 'config.yaml')
|
350
|
+
|
351
|
+
# Create rules
|
352
|
+
File.open('Rules', 'w') do |io|
|
353
|
+
io.write DEFAULT_RULES.make_compatible_with_env
|
354
|
+
end
|
355
|
+
Nanoc::NotificationCenter.post(:file_created, 'Rules')
|
356
|
+
end
|
357
|
+
|
358
|
+
# Sets up the site's data source, i.e. creates the bare essentials for
|
359
|
+
# this data source to work.
|
360
|
+
def site_setup
|
361
|
+
# Get site
|
362
|
+
site = Nanoc::Site.new('.')
|
363
|
+
|
364
|
+
# Set up data sources
|
365
|
+
site.data_sources.each do |data_source|
|
366
|
+
data_source.loading { data_source.setup }
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# Populates the site with some initial data, such as a root item, a
|
371
|
+
# default layout, and so on.
|
372
|
+
def site_populate
|
373
|
+
# Get site
|
374
|
+
site = Nanoc::Site.new('.')
|
375
|
+
data_source = site.data_sources[0]
|
376
|
+
|
377
|
+
# Create home page
|
378
|
+
data_source.create_item(
|
379
|
+
DEFAULT_ITEM.make_compatible_with_env,
|
380
|
+
{ :title => "Home" },
|
381
|
+
'/'
|
382
|
+
)
|
383
|
+
|
384
|
+
# Create stylesheet
|
385
|
+
data_source.create_item(
|
386
|
+
DEFAULT_STYLESHEET.make_compatible_with_env,
|
387
|
+
{},
|
388
|
+
'/stylesheet/',
|
389
|
+
:extension => '.css'
|
390
|
+
)
|
391
|
+
|
392
|
+
# Create layout
|
393
|
+
data_source.create_layout(
|
394
|
+
DEFAULT_LAYOUT.make_compatible_with_env,
|
395
|
+
{},
|
396
|
+
'/default/'
|
397
|
+
)
|
398
|
+
|
399
|
+
# Create code
|
400
|
+
FileUtils.mkdir_p('lib')
|
401
|
+
File.open('lib/default.rb', 'w') do |io|
|
402
|
+
io.write "\# All files in the 'lib' directory will be loaded\n"
|
403
|
+
io.write "\# before nanoc starts compiling.\n"
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
end
|
408
|
+
|
409
|
+
end
|
410
|
+
|
411
|
+
runner Nanoc::CLI::Commands::CreateSite
|