nanoc3 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/ChangeLog +3 -0
  2. data/LICENSE +19 -0
  3. data/NEWS.rdoc +262 -0
  4. data/README.rdoc +80 -0
  5. data/Rakefile +11 -0
  6. data/bin/nanoc3 +16 -0
  7. data/lib/nanoc3/base/code_snippet.rb +42 -0
  8. data/lib/nanoc3/base/compiler.rb +225 -0
  9. data/lib/nanoc3/base/compiler_dsl.rb +110 -0
  10. data/lib/nanoc3/base/core_ext/array.rb +21 -0
  11. data/lib/nanoc3/base/core_ext/hash.rb +23 -0
  12. data/lib/nanoc3/base/core_ext/string.rb +14 -0
  13. data/lib/nanoc3/base/core_ext.rb +5 -0
  14. data/lib/nanoc3/base/data_source.rb +197 -0
  15. data/lib/nanoc3/base/dependency_tracker.rb +291 -0
  16. data/lib/nanoc3/base/errors.rb +95 -0
  17. data/lib/nanoc3/base/filter.rb +60 -0
  18. data/lib/nanoc3/base/item.rb +87 -0
  19. data/lib/nanoc3/base/item_rep.rb +236 -0
  20. data/lib/nanoc3/base/layout.rb +53 -0
  21. data/lib/nanoc3/base/notification_center.rb +68 -0
  22. data/lib/nanoc3/base/plugin.rb +88 -0
  23. data/lib/nanoc3/base/preprocessor_context.rb +37 -0
  24. data/lib/nanoc3/base/rule.rb +37 -0
  25. data/lib/nanoc3/base/rule_context.rb +68 -0
  26. data/lib/nanoc3/base/site.rb +334 -0
  27. data/lib/nanoc3/base.rb +25 -0
  28. data/lib/nanoc3/cli/base.rb +151 -0
  29. data/lib/nanoc3/cli/commands/autocompile.rb +89 -0
  30. data/lib/nanoc3/cli/commands/compile.rb +279 -0
  31. data/lib/nanoc3/cli/commands/create_item.rb +79 -0
  32. data/lib/nanoc3/cli/commands/create_layout.rb +94 -0
  33. data/lib/nanoc3/cli/commands/create_site.rb +320 -0
  34. data/lib/nanoc3/cli/commands/help.rb +71 -0
  35. data/lib/nanoc3/cli/commands/info.rb +114 -0
  36. data/lib/nanoc3/cli/commands/update.rb +96 -0
  37. data/lib/nanoc3/cli/commands.rb +13 -0
  38. data/lib/nanoc3/cli/logger.rb +73 -0
  39. data/lib/nanoc3/cli.rb +16 -0
  40. data/lib/nanoc3/data_sources/delicious.rb +66 -0
  41. data/lib/nanoc3/data_sources/filesystem.rb +231 -0
  42. data/lib/nanoc3/data_sources/filesystem_combined.rb +202 -0
  43. data/lib/nanoc3/data_sources/filesystem_common.rb +22 -0
  44. data/lib/nanoc3/data_sources/filesystem_compact.rb +232 -0
  45. data/lib/nanoc3/data_sources/last_fm.rb +103 -0
  46. data/lib/nanoc3/data_sources/twitter.rb +53 -0
  47. data/lib/nanoc3/data_sources.rb +20 -0
  48. data/lib/nanoc3/extra/auto_compiler.rb +97 -0
  49. data/lib/nanoc3/extra/chick.rb +119 -0
  50. data/lib/nanoc3/extra/context.rb +24 -0
  51. data/lib/nanoc3/extra/core_ext/time.rb +19 -0
  52. data/lib/nanoc3/extra/core_ext.rb +3 -0
  53. data/lib/nanoc3/extra/deployers/rsync.rb +64 -0
  54. data/lib/nanoc3/extra/deployers.rb +12 -0
  55. data/lib/nanoc3/extra/file_proxy.rb +31 -0
  56. data/lib/nanoc3/extra/validators/links.rb +0 -0
  57. data/lib/nanoc3/extra/validators/w3c.rb +71 -0
  58. data/lib/nanoc3/extra/validators.rb +12 -0
  59. data/lib/nanoc3/extra/vcs.rb +65 -0
  60. data/lib/nanoc3/extra/vcses/bazaar.rb +21 -0
  61. data/lib/nanoc3/extra/vcses/dummy.rb +20 -0
  62. data/lib/nanoc3/extra/vcses/git.rb +21 -0
  63. data/lib/nanoc3/extra/vcses/mercurial.rb +21 -0
  64. data/lib/nanoc3/extra/vcses/subversion.rb +21 -0
  65. data/lib/nanoc3/extra/vcses.rb +17 -0
  66. data/lib/nanoc3/extra.rb +16 -0
  67. data/lib/nanoc3/filters/bluecloth.rb +13 -0
  68. data/lib/nanoc3/filters/coderay.rb +17 -0
  69. data/lib/nanoc3/filters/erb.rb +19 -0
  70. data/lib/nanoc3/filters/erubis.rb +17 -0
  71. data/lib/nanoc3/filters/haml.rb +20 -0
  72. data/lib/nanoc3/filters/less.rb +13 -0
  73. data/lib/nanoc3/filters/markaby.rb +14 -0
  74. data/lib/nanoc3/filters/maruku.rb +14 -0
  75. data/lib/nanoc3/filters/rainpress.rb +13 -0
  76. data/lib/nanoc3/filters/rdiscount.rb +13 -0
  77. data/lib/nanoc3/filters/rdoc.rb +23 -0
  78. data/lib/nanoc3/filters/redcloth.rb +14 -0
  79. data/lib/nanoc3/filters/relativize_paths.rb +32 -0
  80. data/lib/nanoc3/filters/rubypants.rb +14 -0
  81. data/lib/nanoc3/filters/sass.rb +17 -0
  82. data/lib/nanoc3/filters.rb +37 -0
  83. data/lib/nanoc3/helpers/blogging.rb +226 -0
  84. data/lib/nanoc3/helpers/breadcrumbs.rb +25 -0
  85. data/lib/nanoc3/helpers/capturing.rb +71 -0
  86. data/lib/nanoc3/helpers/filtering.rb +46 -0
  87. data/lib/nanoc3/helpers/html_escape.rb +22 -0
  88. data/lib/nanoc3/helpers/link_to.rb +120 -0
  89. data/lib/nanoc3/helpers/rendering.rb +76 -0
  90. data/lib/nanoc3/helpers/tagging.rb +58 -0
  91. data/lib/nanoc3/helpers/text.rb +40 -0
  92. data/lib/nanoc3/helpers/xml_sitemap.rb +69 -0
  93. data/lib/nanoc3/helpers.rb +16 -0
  94. data/lib/nanoc3/package.rb +106 -0
  95. data/lib/nanoc3/tasks/clean.rake +16 -0
  96. data/lib/nanoc3/tasks/clean.rb +33 -0
  97. data/lib/nanoc3/tasks/deploy/rsync.rake +11 -0
  98. data/lib/nanoc3/tasks/validate.rake +35 -0
  99. data/lib/nanoc3/tasks.rb +9 -0
  100. data/lib/nanoc3.rb +19 -0
  101. data/vendor/cri/ChangeLog +0 -0
  102. data/vendor/cri/LICENSE +19 -0
  103. data/vendor/cri/NEWS +0 -0
  104. data/vendor/cri/README +4 -0
  105. data/vendor/cri/Rakefile +25 -0
  106. data/vendor/cri/lib/cri/base.rb +153 -0
  107. data/vendor/cri/lib/cri/command.rb +105 -0
  108. data/vendor/cri/lib/cri/core_ext/string.rb +41 -0
  109. data/vendor/cri/lib/cri/core_ext.rb +8 -0
  110. data/vendor/cri/lib/cri/option_parser.rb +186 -0
  111. data/vendor/cri/lib/cri.rb +12 -0
  112. data/vendor/cri/test/test_base.rb +6 -0
  113. data/vendor/cri/test/test_command.rb +6 -0
  114. data/vendor/cri/test/test_core_ext.rb +21 -0
  115. data/vendor/cri/test/test_option_parser.rb +279 -0
  116. metadata +225 -0
@@ -0,0 +1,320 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+
5
+ class CreateSite < Cri::Command
6
+
7
+ DEFAULT_ITEM = <<EOS
8
+ <h1>A Brand New nanoc Site</h1>
9
+
10
+ <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>
11
+
12
+ <p>To get started, consider replacing this default homepage with your own customized homepage. Some pointers on how to do so:</p>
13
+
14
+ <ul>
15
+ <li><p><strong>Change this page&#8217;s content</strong> by editing &#8220;content.html&#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).</p></li>
16
+ <li><p><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).</p></li>
17
+ </ul>
18
+
19
+ <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>
20
+ EOS
21
+
22
+ DEFAULT_STYLESHEET = <<EOS
23
+ * {
24
+ margin: 0;
25
+ padding: 0;
26
+
27
+ font-family: Georgia, Palatino, Times, 'Times New Roman', sans-serif;
28
+ }
29
+
30
+ body {
31
+ background: #fff;
32
+ }
33
+
34
+ a {
35
+ text-decoration: none;
36
+ }
37
+
38
+ a:link,
39
+ a:visited {
40
+ color: #f30;
41
+ }
42
+
43
+ a:hover {
44
+ color: #f90;
45
+ }
46
+
47
+ #main {
48
+ position: absolute;
49
+
50
+ top: 40px;
51
+ left: 280px;
52
+
53
+ width: 500px;
54
+ }
55
+
56
+ #main h1 {
57
+ font-size: 40px;
58
+ font-weight: normal;
59
+
60
+ line-height: 40px;
61
+
62
+ letter-spacing: -1px;
63
+ }
64
+
65
+ #main p {
66
+ margin: 20px 0;
67
+
68
+ font-size: 15px;
69
+
70
+ line-height: 20px;
71
+ }
72
+
73
+ #main ul {
74
+ margin: 20px;
75
+ }
76
+
77
+ #main li {
78
+ list-style-type: square;
79
+
80
+ font-size: 15px;
81
+
82
+ line-height: 20px;
83
+ }
84
+
85
+ #sidebar {
86
+ position: absolute;
87
+
88
+ top: 40px;
89
+ left: 20px;
90
+ width: 200px;
91
+
92
+ padding: 20px 20px 0 0;
93
+
94
+ border-right: 1px solid #ccc;
95
+
96
+ text-align: right;
97
+ }
98
+
99
+ #sidebar h2 {
100
+ text-transform: uppercase;
101
+
102
+ font-size: 13px;
103
+
104
+ color: #333;
105
+
106
+ letter-spacing: 1px;
107
+
108
+ line-height: 20px;
109
+ }
110
+
111
+ #sidebar ul {
112
+ list-style-type: none;
113
+
114
+ margin: 20px 0;
115
+ }
116
+
117
+ #sidebar li {
118
+ font-size: 14px;
119
+
120
+ line-height: 20px;
121
+ }
122
+ EOS
123
+
124
+ DEFAULT_LAYOUT = <<EOS
125
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
126
+ <html>
127
+ <head>
128
+ <title>A Brand New nanoc Site - <%= @item[:title] %></title>
129
+ <link rel="stylesheet" type="text/css" href="/style.css" media="screen">
130
+ </head>
131
+ <body>
132
+ <div id="main">
133
+ <%= yield %>
134
+ </div>
135
+ <div id="sidebar">
136
+ <h2>Documentation</h2>
137
+ <ul>
138
+ <li><a href="http://nanoc.stoneship.org/help/tutorial/">Tutorial</a></li>
139
+ <li><a href="http://nanoc.stoneship.org/help/manual/">Manual</a></li>
140
+ </ul>
141
+ <h2>Community</h2>
142
+ <ul>
143
+ <li><a href="http://groups.google.com/group/nanoc/">Discussion Group</a></li>
144
+ <li><a href="http://groups.google.com/group/nanoc-es/">Spanish Discussion Group</a></li>
145
+ <li><a href="http://projects.stoneship.org/trac/nanoc/">Wiki</a></li>
146
+ </ul>
147
+ </div>
148
+ </body>
149
+ </html>
150
+ EOS
151
+
152
+ def name
153
+ 'create_site'
154
+ end
155
+
156
+ def aliases
157
+ [ 'cs' ]
158
+ end
159
+
160
+ def short_desc
161
+ 'create a site'
162
+ end
163
+
164
+ def long_desc
165
+ 'Create a new site at the given path. The site will use the ' +
166
+ 'filesystem_compact data source by default, but this can be ' +
167
+ 'changed using the --datasource commandline option.'
168
+ end
169
+
170
+ def usage
171
+ "nanoc3 create_site [path]"
172
+ end
173
+
174
+ def option_definitions
175
+ [
176
+ # --datasource
177
+ {
178
+ :long => 'datasource', :short => 'd', :argument => :required,
179
+ :desc => 'specify the data source for the new site'
180
+ }
181
+ ]
182
+ end
183
+
184
+ def run(options, arguments)
185
+ # Check arguments
186
+ if arguments.length != 1
187
+ $stderr.puts "usage: #{usage}"
188
+ exit 1
189
+ end
190
+
191
+ # Extract arguments and options
192
+ path = arguments[0]
193
+ data_source = options[:datasource] || 'filesystem_compact'
194
+
195
+ # Check whether site exists
196
+ if File.exist?(path)
197
+ $stderr.puts "A site at '#{path}' already exists."
198
+ exit 1
199
+ end
200
+
201
+ # Check whether data source exists
202
+ if Nanoc3::DataSource.named(data_source).nil?
203
+ $stderr.puts "Unrecognised data source: #{data_source}"
204
+ exit 1
205
+ end
206
+
207
+ # Setup notifications
208
+ Nanoc3::NotificationCenter.on(:file_created) do |file_path|
209
+ Nanoc3::CLI::Logger.instance.file(:high, :create, file_path)
210
+ end
211
+
212
+ # Build entire site
213
+ FileUtils.mkdir_p(path)
214
+ FileUtils.cd(File.join(path)) do
215
+ site_create_minimal(data_source)
216
+ site_setup
217
+ site_populate
218
+ end
219
+
220
+ puts "Created a blank nanoc site at '#{path}'. Enjoy!"
221
+ end
222
+
223
+ protected
224
+
225
+ # Creates a configuration file and a output directory for this site, as
226
+ # well as a rakefile that loads the standard nanoc tasks.
227
+ def site_create_minimal(data_source)
228
+ # Create output
229
+ FileUtils.mkdir_p('output')
230
+
231
+ # Create config
232
+ File.open('config.yaml', 'w') do |io|
233
+ io.write(YAML.dump(
234
+ 'output_dir' => 'output',
235
+ 'data_sources' => [
236
+ {
237
+ 'type' => data_source,
238
+ 'items_root' => '/',
239
+ 'layouts_root' => '/'
240
+ }
241
+ ]
242
+ ))
243
+ end
244
+ Nanoc3::NotificationCenter.post(:file_created, 'config.yaml')
245
+
246
+ # Create rakefile
247
+ File.open('Rakefile', 'w') do |io|
248
+ io.write "require 'nanoc3/tasks'"
249
+ end
250
+ Nanoc3::NotificationCenter.post(:file_created, 'Rakefile')
251
+
252
+ # Create rules
253
+ File.open('Rules', 'w') do |io|
254
+ io.write "#!/usr/bin/env ruby\n"
255
+ io.write "\n"
256
+ io.write "compile '*' do\n"
257
+ io.write " filter :erb\n"
258
+ io.write " layout 'default'\n"
259
+ io.write "end\n"
260
+ io.write "\n"
261
+ io.write "route '*' do\n"
262
+ io.write " item.identifier + 'index.html'\n"
263
+ io.write "end\n"
264
+ io.write "\n"
265
+ io.write "layout '*', :erb\n"
266
+ end
267
+ Nanoc3::NotificationCenter.post(:file_created, 'Rules')
268
+ end
269
+
270
+ # Sets up the site's data source, i.e. creates the bare essentials for
271
+ # this data source to work.
272
+ def site_setup
273
+ # Get site
274
+ site = Nanoc3::Site.new('.')
275
+
276
+ # Set up data sources
277
+ site.data_sources.each do |data_source|
278
+ data_source.loading { data_source.setup }
279
+ end
280
+ end
281
+
282
+ # Populates the site with some initial data, such as a root item, a
283
+ # default layout, and so on.
284
+ def site_populate
285
+ # Get site
286
+ site = Nanoc3::Site.new('.')
287
+
288
+ # Create item
289
+ data_source = site.data_sources[0]
290
+ data_source.create_item(
291
+ DEFAULT_ITEM,
292
+ { :title => "Home" },
293
+ '/'
294
+ )
295
+
296
+ # Create layout
297
+ data_source = site.data_sources[0]
298
+ data_source.create_layout(
299
+ DEFAULT_LAYOUT,
300
+ {},
301
+ '/default/'
302
+ )
303
+
304
+ # Create stylesheet
305
+ FileUtils.mkdir_p('output')
306
+ File.open('output/style.css', 'w') do |io|
307
+ io.write DEFAULT_STYLESHEET
308
+ end
309
+
310
+ # Create code
311
+ FileUtils.mkdir_p('lib')
312
+ File.open('lib/default.rb', 'w') do |io|
313
+ io.write "\# All files in the 'lib' directory will be loaded\n"
314
+ io.write "\# before nanoc starts compiling.\n"
315
+ end
316
+ end
317
+
318
+ end
319
+
320
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+
5
+ class Help < Cri::Command
6
+
7
+ def name
8
+ 'help'
9
+ end
10
+
11
+ def aliases
12
+ []
13
+ end
14
+
15
+ def short_desc
16
+ 'show help for a command'
17
+ end
18
+
19
+ def long_desc
20
+ 'Show help for the given command, or show general help. When no ' +
21
+ 'command is given, a list of available commands is displayed, as ' +
22
+ 'well as a list of global commandline options. When a command is ' +
23
+ 'given, a command description as well as command-specific ' +
24
+ 'commandline options are shown.'
25
+ end
26
+
27
+ def usage
28
+ "nanoc3 help [command]"
29
+ end
30
+
31
+ def run(options, arguments)
32
+ # Check arguments
33
+ if arguments.size > 1
34
+ $stderr.puts "usage: #{usage}"
35
+ exit 1
36
+ end
37
+
38
+ if arguments.length == 0
39
+ # Build help text
40
+ text = ''
41
+
42
+ # Add title
43
+ text << "nanoc, a static site compiler written in Ruby.\n"
44
+
45
+ # Add available commands
46
+ text << "\n"
47
+ text << "Available commands:\n"
48
+ text << "\n"
49
+ @base.commands.sort.each do |command|
50
+ text << sprintf(" %-20s %s\n", command.name, command.short_desc)
51
+ end
52
+
53
+ # Add global options
54
+ text << "\n"
55
+ text << "Global options:\n"
56
+ text << "\n"
57
+ @base.global_option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def|
58
+ text << sprintf(" -%1s --%-15s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc])
59
+ end
60
+
61
+ # Display text
62
+ puts text
63
+ elsif arguments.length == 1
64
+ command = @base.command_named(arguments[0])
65
+ puts command.help
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,114 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+
5
+ class Info < Cri::Command
6
+
7
+ def name
8
+ 'info'
9
+ end
10
+
11
+ def aliases
12
+ []
13
+ end
14
+
15
+ def short_desc
16
+ 'show info about available plugins'
17
+ end
18
+
19
+ def long_desc
20
+ 'Show a list of available plugins, including filters, data sources ' +
21
+ 'and VCSes. If the current directory contains a nanoc web site, ' +
22
+ 'the plugins defined in this site will be shown as well.'
23
+ end
24
+
25
+ def usage
26
+ "nanoc3 info"
27
+ end
28
+
29
+ def option_definitions
30
+ []
31
+ end
32
+
33
+ def run(options, arguments)
34
+ # Check arguments
35
+ if arguments.size != 0
36
+ $stderr.puts "usage: #{usage}"
37
+ exit 1
38
+ end
39
+
40
+ # Get list of plugins (before and after)
41
+ plugins_before = Nanoc3::Plugin.all
42
+ @base.site
43
+ @base.site.load_data if @base.site
44
+ plugins_after = Nanoc3::Plugin.all
45
+
46
+ # Divide list of plugins into builtin and custom
47
+ plugins_builtin = plugins_before
48
+ plugins_custom = plugins_after - plugins_before
49
+
50
+ # Find max identifiers length
51
+ plugin_with_longest_identifiers = plugins_after.inject do |longest, current|
52
+ longest[:identifiers].join(', ').size > current[:identifiers].join(', ').size ? longest : current
53
+ end
54
+ max_identifiers_length = plugin_with_longest_identifiers[:identifiers].join(', ').size
55
+
56
+ PLUGIN_CLASS_ORDER.each do |superclass|
57
+ plugins_with_this_superclass = {
58
+ :builtin => plugins_builtin.select { |p| p[:superclass] == superclass },
59
+ :custom => plugins_custom.select { |p| p[:superclass] == superclass }
60
+ }
61
+
62
+ # Print kind
63
+ kind = name_for_plugin_class(superclass)
64
+ puts "#{kind}:"
65
+ puts
66
+
67
+ # Print plugins organised by subtype
68
+ [ :builtin, :custom ].each do |type|
69
+ # Find relevant plugins
70
+ relevant_plugins = plugins_with_this_superclass[type]
71
+
72
+ # Print type
73
+ puts " #{type}:"
74
+ if relevant_plugins.empty?
75
+ puts " (none)"
76
+ next
77
+ end
78
+
79
+ # Print plugins
80
+ relevant_plugins.sort_by { |k| k[:identifiers].join(', ') }.each do |plugin|
81
+ # Display
82
+ puts sprintf(
83
+ " %-#{max_identifiers_length}s (%s)",
84
+ plugin[:identifiers].join(', '),
85
+ plugin[:class].to_s.sub(/^::/, '')
86
+ )
87
+ end
88
+ end
89
+
90
+ puts
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ PLUGIN_CLASS_ORDER = [
97
+ Nanoc3::Filter,
98
+ Nanoc3::Extra::VCS,
99
+ Nanoc3::DataSource
100
+ ]
101
+
102
+ PLUGIN_CLASSES = {
103
+ Nanoc3::Filter => 'Filters',
104
+ Nanoc3::DataSource => 'Data Sources',
105
+ Nanoc3::Extra::VCS => 'VCSes'
106
+ }
107
+
108
+ def name_for_plugin_class(klass)
109
+ PLUGIN_CLASSES[klass]
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+
5
+ class Update < Cri::Command
6
+
7
+ def name
8
+ 'update'
9
+ end
10
+
11
+ def aliases
12
+ []
13
+ end
14
+
15
+ def short_desc
16
+ 'update the data stored by the data source to a newer version'
17
+ end
18
+
19
+ def long_desc
20
+ 'Update the data stored by the data source to a newer format. The ' +
21
+ 'format in which data is stored can change between releases, and ' +
22
+ 'even though backward compatibility is usually preserved, it is ' +
23
+ 'often a good idea to store the site data in a newer format so newer ' +
24
+ 'features can be taken advantage of.' +
25
+ "\n" +
26
+ 'This command will change data, and it is therefore recommended to ' +
27
+ 'make a backup in case something goes wrong.'
28
+ end
29
+
30
+ def usage
31
+ "nanoc3 update [options]"
32
+ end
33
+
34
+ def option_definitions
35
+ [
36
+ # --vcs
37
+ {
38
+ :long => 'vcs', :short => 'c', :argument => :required,
39
+ :desc => 'select the VCS to use'
40
+ },
41
+ # --yes
42
+ {
43
+ :long => 'yes', :short => 'y', :argument => :forbidden,
44
+ :desc => 'updates the data without warning'
45
+ }
46
+ ]
47
+ end
48
+
49
+ def run(options, arguments)
50
+ # Check arguments
51
+ if arguments.size != 0
52
+ $stderr.puts "usage: #{usage}"
53
+ exit 1
54
+ end
55
+
56
+ # Make sure we are in a nanoc site directory
57
+ @base.require_site
58
+ @base.site.load_data
59
+
60
+ # Set VCS if possible
61
+ @base.set_vcs(options[:vcs])
62
+
63
+ # Check for -y switch
64
+ unless options.has_key?(:yes)
65
+ $stderr.puts '*************'
66
+ $stderr.puts '** WARNING **'
67
+ $stderr.puts '*************'
68
+ $stderr.puts
69
+ $stderr.puts 'Are you absolutely sure you want to update the ' +
70
+ 'content for this site? Updating the site content ' +
71
+ 'will change the structure of existing data. This ' +
72
+ 'operation is destructive and cannot be reverted. ' +
73
+ 'Please do not interrupt this operation; doing so can ' +
74
+ 'result in data loss. As always, consider making a ' +
75
+ 'backup copy.'
76
+ $stderr.puts
77
+ $stderr.puts 'If this nanoc site is versioned using a VCS ' +
78
+ 'supported by nanoc, consider using the --vcs option ' +
79
+ 'to have nanoc perform add/delete/move operations ' +
80
+ 'using the specified VCS. To get a list of VCSes ' +
81
+ 'supported by nanoc, issue the "info" command.'
82
+ $stderr.puts
83
+ $stderr.puts 'To continue, use the -y/--yes option, like "nanoc3 ' +
84
+ 'update -y".'
85
+ exit 1
86
+ end
87
+
88
+ # Update
89
+ @base.site.data_sources.each do |data_source|
90
+ data_source.update
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::CLI::Commands
4
+ end
5
+
6
+ require 'nanoc3/cli/commands/autocompile'
7
+ require 'nanoc3/cli/commands/compile'
8
+ require 'nanoc3/cli/commands/create_layout'
9
+ require 'nanoc3/cli/commands/create_item'
10
+ require 'nanoc3/cli/commands/create_site'
11
+ require 'nanoc3/cli/commands/help'
12
+ require 'nanoc3/cli/commands/info'
13
+ require 'nanoc3/cli/commands/update'
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singleton'
4
+
5
+ module Nanoc3::CLI
6
+
7
+ # Nanoc3::CLI::Logger is a singleton class responsible for generating
8
+ # feedback in the terminal.
9
+ class Logger
10
+
11
+ ACTION_COLORS = {
12
+ :create => "\e[1m" + "\e[32m", # bold + green
13
+ :update => "\e[1m" + "\e[33m", # bold + yellow
14
+ :identical => "\e[1m", # bold
15
+ :skip => "\e[1m" # bold
16
+ }
17
+
18
+ include Singleton
19
+
20
+ # The log level, which can be :high, :low or :off (which will log all
21
+ # messages, only high-priority messages, or no messages at all,
22
+ # respectively).
23
+ attr_accessor :level
24
+
25
+ # Whether to use color in log messages or not
26
+ attr_accessor :color
27
+ alias_method :color?, :color
28
+
29
+ def initialize
30
+ @level = :high
31
+ @color = true
32
+ end
33
+
34
+ # Logs a file-related action.
35
+ #
36
+ # +level+:: The importance of this action. Can be :high or :low.
37
+ #
38
+ # +action+:: The kind of file action. Can be :create, :update or
39
+ # :identical.
40
+ #
41
+ # +identifier+:: The identifier of the item the action was performed on.
42
+ def file(level, action, identifier, duration=nil)
43
+ log(
44
+ level,
45
+ '%s%12s%s %s%s' % [
46
+ color? ? ACTION_COLORS[action.to_sym] : '',
47
+ action,
48
+ color? ? "\e[0m" : '',
49
+ duration.nil? ? '' : "[%2.2fs] " % [ duration ],
50
+ identifier
51
+ ]
52
+ )
53
+ end
54
+
55
+ # Logs a message.
56
+ #
57
+ # +level+:: The importance of this message. Can be :high or :low.
58
+ #
59
+ # +s+:: The message to be logged.
60
+ #
61
+ # +io+:: The IO instance to which the message will be written. Defaults to
62
+ # standard output.
63
+ def log(level, s, io=$stdout)
64
+ # Don't log when logging is disabled
65
+ return if @level == :off
66
+
67
+ # Log when level permits it
68
+ io.puts(s) if (@level == :low or @level == level)
69
+ end
70
+
71
+ end
72
+
73
+ end
data/lib/nanoc3/cli.rb ADDED
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ # Add Cri to load path
4
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../../vendor/cri/lib'))
5
+
6
+ # Load Cri
7
+ require 'cri'
8
+
9
+ # Module for CLI
10
+ module Nanoc3::CLI
11
+ end
12
+
13
+ # Load CLI
14
+ require 'nanoc3/cli/logger'
15
+ require 'nanoc3/cli/commands'
16
+ require 'nanoc3/cli/base'