nanoc 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/.gemtest +0 -0
  2. data/ChangeLog +3 -0
  3. data/Gemfile +32 -0
  4. data/LICENSE +19 -0
  5. data/NEWS.md +470 -0
  6. data/README.md +114 -0
  7. data/Rakefile +14 -0
  8. data/bin/nanoc +7 -27
  9. data/bin/nanoc3 +3 -0
  10. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  11. data/lib/nanoc.rb +41 -0
  12. data/lib/nanoc/base.rb +49 -0
  13. data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
  14. data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
  15. data/lib/nanoc/base/compilation/compiler.rb +458 -0
  16. data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
  17. data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
  18. data/lib/nanoc/base/compilation/filter.rb +165 -0
  19. data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
  20. data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
  21. data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
  22. data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
  23. data/lib/nanoc/base/compilation/rule.rb +73 -0
  24. data/lib/nanoc/base/compilation/rule_context.rb +84 -0
  25. data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
  26. data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
  27. data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
  28. data/lib/nanoc/base/context.rb +47 -0
  29. data/lib/nanoc/base/core_ext.rb +6 -0
  30. data/lib/nanoc/base/core_ext/array.rb +62 -0
  31. data/lib/nanoc/base/core_ext/hash.rb +63 -0
  32. data/lib/nanoc/base/core_ext/pathname.rb +26 -0
  33. data/lib/nanoc/base/core_ext/string.rb +46 -0
  34. data/lib/nanoc/base/directed_graph.rb +275 -0
  35. data/lib/nanoc/base/errors.rb +211 -0
  36. data/lib/nanoc/base/memoization.rb +67 -0
  37. data/lib/nanoc/base/notification_center.rb +84 -0
  38. data/lib/nanoc/base/ordered_hash.rb +200 -0
  39. data/lib/nanoc/base/plugin_registry.rb +181 -0
  40. data/lib/nanoc/base/result_data/item_rep.rb +492 -0
  41. data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
  42. data/lib/nanoc/base/source_data/configuration.rb +24 -0
  43. data/lib/nanoc/base/source_data/data_source.rb +234 -0
  44. data/lib/nanoc/base/source_data/item.rb +301 -0
  45. data/lib/nanoc/base/source_data/layout.rb +130 -0
  46. data/lib/nanoc/base/source_data/site.rb +361 -0
  47. data/lib/nanoc/base/store.rb +135 -0
  48. data/lib/nanoc/cli.rb +137 -0
  49. data/lib/nanoc/cli/command_runner.rb +104 -0
  50. data/lib/nanoc/cli/commands/autocompile.rb +58 -0
  51. data/lib/nanoc/cli/commands/compile.rb +297 -0
  52. data/lib/nanoc/cli/commands/create_item.rb +60 -0
  53. data/lib/nanoc/cli/commands/create_layout.rb +73 -0
  54. data/lib/nanoc/cli/commands/create_site.rb +411 -0
  55. data/lib/nanoc/cli/commands/debug.rb +117 -0
  56. data/lib/nanoc/cli/commands/deploy.rb +79 -0
  57. data/lib/nanoc/cli/commands/info.rb +98 -0
  58. data/lib/nanoc/cli/commands/nanoc.rb +38 -0
  59. data/lib/nanoc/cli/commands/prune.rb +50 -0
  60. data/lib/nanoc/cli/commands/update.rb +70 -0
  61. data/lib/nanoc/cli/commands/view.rb +82 -0
  62. data/lib/nanoc/cli/commands/watch.rb +124 -0
  63. data/lib/nanoc/cli/error_handler.rb +199 -0
  64. data/lib/nanoc/cli/logger.rb +92 -0
  65. data/lib/nanoc/data_sources.rb +29 -0
  66. data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
  67. data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
  68. data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
  69. data/lib/nanoc/data_sources/filesystem.rb +299 -0
  70. data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
  71. data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
  72. data/lib/nanoc/extra.rb +24 -0
  73. data/lib/nanoc/extra/auto_compiler.rb +103 -0
  74. data/lib/nanoc/extra/chick.rb +125 -0
  75. data/lib/nanoc/extra/core_ext.rb +6 -0
  76. data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
  77. data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
  78. data/lib/nanoc/extra/core_ext/time.rb +19 -0
  79. data/lib/nanoc/extra/deployer.rb +47 -0
  80. data/lib/nanoc/extra/deployers.rb +15 -0
  81. data/lib/nanoc/extra/deployers/fog.rb +98 -0
  82. data/lib/nanoc/extra/deployers/rsync.rb +70 -0
  83. data/lib/nanoc/extra/file_proxy.rb +40 -0
  84. data/lib/nanoc/extra/pruner.rb +86 -0
  85. data/lib/nanoc/extra/validators.rb +12 -0
  86. data/lib/nanoc/extra/validators/links.rb +268 -0
  87. data/lib/nanoc/extra/validators/w3c.rb +95 -0
  88. data/lib/nanoc/extra/vcs.rb +66 -0
  89. data/lib/nanoc/extra/vcses.rb +17 -0
  90. data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
  91. data/lib/nanoc/extra/vcses/dummy.rb +24 -0
  92. data/lib/nanoc/extra/vcses/git.rb +25 -0
  93. data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
  94. data/lib/nanoc/extra/vcses/subversion.rb +25 -0
  95. data/lib/nanoc/filters.rb +59 -0
  96. data/lib/nanoc/filters/asciidoc.rb +38 -0
  97. data/lib/nanoc/filters/bluecloth.rb +19 -0
  98. data/lib/nanoc/filters/coderay.rb +21 -0
  99. data/lib/nanoc/filters/coffeescript.rb +20 -0
  100. data/lib/nanoc/filters/colorize_syntax.rb +298 -0
  101. data/lib/nanoc/filters/erb.rb +38 -0
  102. data/lib/nanoc/filters/erubis.rb +34 -0
  103. data/lib/nanoc/filters/haml.rb +27 -0
  104. data/lib/nanoc/filters/kramdown.rb +20 -0
  105. data/lib/nanoc/filters/less.rb +53 -0
  106. data/lib/nanoc/filters/markaby.rb +20 -0
  107. data/lib/nanoc/filters/maruku.rb +20 -0
  108. data/lib/nanoc/filters/mustache.rb +24 -0
  109. data/lib/nanoc/filters/rainpress.rb +19 -0
  110. data/lib/nanoc/filters/rdiscount.rb +22 -0
  111. data/lib/nanoc/filters/rdoc.rb +33 -0
  112. data/lib/nanoc/filters/redcarpet.rb +62 -0
  113. data/lib/nanoc/filters/redcloth.rb +47 -0
  114. data/lib/nanoc/filters/relativize_paths.rb +94 -0
  115. data/lib/nanoc/filters/rubypants.rb +20 -0
  116. data/lib/nanoc/filters/sass.rb +74 -0
  117. data/lib/nanoc/filters/slim.rb +25 -0
  118. data/lib/nanoc/filters/typogruby.rb +23 -0
  119. data/lib/nanoc/filters/uglify_js.rb +42 -0
  120. data/lib/nanoc/filters/xsl.rb +46 -0
  121. data/lib/nanoc/filters/yui_compressor.rb +23 -0
  122. data/lib/nanoc/helpers.rb +16 -0
  123. data/lib/nanoc/helpers/blogging.rb +319 -0
  124. data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
  125. data/lib/nanoc/helpers/capturing.rb +138 -0
  126. data/lib/nanoc/helpers/filtering.rb +50 -0
  127. data/lib/nanoc/helpers/html_escape.rb +55 -0
  128. data/lib/nanoc/helpers/link_to.rb +151 -0
  129. data/lib/nanoc/helpers/rendering.rb +140 -0
  130. data/lib/nanoc/helpers/tagging.rb +71 -0
  131. data/lib/nanoc/helpers/text.rb +44 -0
  132. data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
  133. data/lib/nanoc/tasks.rb +10 -0
  134. data/lib/nanoc/tasks/clean.rake +16 -0
  135. data/lib/nanoc/tasks/clean.rb +29 -0
  136. data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
  137. data/lib/nanoc/tasks/validate.rake +92 -0
  138. data/nanoc.gemspec +49 -0
  139. data/tasks/doc.rake +16 -0
  140. data/tasks/test.rake +46 -0
  141. data/test/base/core_ext/array_spec.rb +73 -0
  142. data/test/base/core_ext/hash_spec.rb +98 -0
  143. data/test/base/core_ext/pathname_spec.rb +27 -0
  144. data/test/base/core_ext/string_spec.rb +37 -0
  145. data/test/base/test_checksum_store.rb +35 -0
  146. data/test/base/test_code_snippet.rb +31 -0
  147. data/test/base/test_compiler.rb +403 -0
  148. data/test/base/test_compiler_dsl.rb +161 -0
  149. data/test/base/test_context.rb +31 -0
  150. data/test/base/test_data_source.rb +46 -0
  151. data/test/base/test_dependency_tracker.rb +262 -0
  152. data/test/base/test_directed_graph.rb +288 -0
  153. data/test/base/test_filter.rb +83 -0
  154. data/test/base/test_item.rb +179 -0
  155. data/test/base/test_item_rep.rb +579 -0
  156. data/test/base/test_layout.rb +59 -0
  157. data/test/base/test_memoization.rb +90 -0
  158. data/test/base/test_notification_center.rb +34 -0
  159. data/test/base/test_outdatedness_checker.rb +394 -0
  160. data/test/base/test_plugin.rb +30 -0
  161. data/test/base/test_rule.rb +19 -0
  162. data/test/base/test_rule_context.rb +65 -0
  163. data/test/base/test_site.rb +190 -0
  164. data/test/cli/commands/test_compile.rb +33 -0
  165. data/test/cli/commands/test_create_item.rb +14 -0
  166. data/test/cli/commands/test_create_layout.rb +28 -0
  167. data/test/cli/commands/test_create_site.rb +24 -0
  168. data/test/cli/commands/test_deploy.rb +74 -0
  169. data/test/cli/commands/test_help.rb +12 -0
  170. data/test/cli/commands/test_info.rb +11 -0
  171. data/test/cli/commands/test_prune.rb +98 -0
  172. data/test/cli/commands/test_update.rb +10 -0
  173. data/test/cli/test_cli.rb +102 -0
  174. data/test/cli/test_error_handler.rb +29 -0
  175. data/test/cli/test_logger.rb +10 -0
  176. data/test/data_sources/test_filesystem.rb +433 -0
  177. data/test/data_sources/test_filesystem_unified.rb +536 -0
  178. data/test/data_sources/test_filesystem_verbose.rb +357 -0
  179. data/test/extra/core_ext/test_enumerable.rb +30 -0
  180. data/test/extra/core_ext/test_pathname.rb +17 -0
  181. data/test/extra/core_ext/test_time.rb +15 -0
  182. data/test/extra/deployers/test_fog.rb +67 -0
  183. data/test/extra/deployers/test_rsync.rb +100 -0
  184. data/test/extra/test_auto_compiler.rb +417 -0
  185. data/test/extra/test_file_proxy.rb +19 -0
  186. data/test/extra/test_vcs.rb +22 -0
  187. data/test/extra/validators/test_links.rb +62 -0
  188. data/test/extra/validators/test_w3c.rb +47 -0
  189. data/test/filters/test_asciidoc.rb +22 -0
  190. data/test/filters/test_bluecloth.rb +18 -0
  191. data/test/filters/test_coderay.rb +44 -0
  192. data/test/filters/test_coffeescript.rb +18 -0
  193. data/test/filters/test_colorize_syntax.rb +379 -0
  194. data/test/filters/test_erb.rb +105 -0
  195. data/test/filters/test_erubis.rb +78 -0
  196. data/test/filters/test_haml.rb +96 -0
  197. data/test/filters/test_kramdown.rb +18 -0
  198. data/test/filters/test_less.rb +113 -0
  199. data/test/filters/test_markaby.rb +24 -0
  200. data/test/filters/test_maruku.rb +18 -0
  201. data/test/filters/test_mustache.rb +25 -0
  202. data/test/filters/test_rainpress.rb +29 -0
  203. data/test/filters/test_rdiscount.rb +31 -0
  204. data/test/filters/test_rdoc.rb +18 -0
  205. data/test/filters/test_redcarpet.rb +73 -0
  206. data/test/filters/test_redcloth.rb +33 -0
  207. data/test/filters/test_relativize_paths.rb +533 -0
  208. data/test/filters/test_rubypants.rb +18 -0
  209. data/test/filters/test_sass.rb +229 -0
  210. data/test/filters/test_slim.rb +35 -0
  211. data/test/filters/test_typogruby.rb +21 -0
  212. data/test/filters/test_uglify_js.rb +30 -0
  213. data/test/filters/test_xsl.rb +105 -0
  214. data/test/filters/test_yui_compressor.rb +44 -0
  215. data/test/gem_loader.rb +11 -0
  216. data/test/helper.rb +207 -0
  217. data/test/helpers/test_blogging.rb +754 -0
  218. data/test/helpers/test_breadcrumbs.rb +81 -0
  219. data/test/helpers/test_capturing.rb +41 -0
  220. data/test/helpers/test_filtering.rb +106 -0
  221. data/test/helpers/test_html_escape.rb +32 -0
  222. data/test/helpers/test_link_to.rb +249 -0
  223. data/test/helpers/test_rendering.rb +89 -0
  224. data/test/helpers/test_tagging.rb +87 -0
  225. data/test/helpers/test_text.rb +24 -0
  226. data/test/helpers/test_xml_sitemap.rb +103 -0
  227. data/test/tasks/test_clean.rb +67 -0
  228. metadata +327 -15
  229. data/bin/nanoc-select +0 -86
  230. 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