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