nanoc 4.11.12 → 4.11.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +7 -1
  3. data/bin/nanoc +1 -1
  4. data/lib/nanoc.rb +2 -27
  5. data/lib/nanoc/base.rb +3 -6
  6. data/lib/nanoc/base/errors.rb +6 -104
  7. data/lib/nanoc/checking/check.rb +4 -4
  8. data/lib/nanoc/checking/checks/external_links.rb +1 -1
  9. data/lib/nanoc/checking/checks/stale.rb +1 -1
  10. data/lib/nanoc/checking/runner.rb +2 -2
  11. data/lib/nanoc/data_sources/filesystem/tools.rb +4 -4
  12. data/lib/nanoc/extra.rb +1 -1
  13. data/lib/nanoc/helpers/blogging.rb +8 -8
  14. data/lib/nanoc/helpers/capturing.rb +1 -1
  15. data/lib/nanoc/helpers/link_to.rb +1 -1
  16. data/lib/nanoc/orig_cli.rb +20 -0
  17. data/lib/nanoc/{cli → orig_cli}/commands/check.rb +3 -3
  18. data/lib/nanoc/{cli → orig_cli}/commands/deploy.rb +8 -8
  19. data/lib/nanoc/{cli → orig_cli}/commands/show-rules.rb +3 -3
  20. data/lib/nanoc/rule_dsl/action_provider.rb +5 -5
  21. data/lib/nanoc/rule_dsl/action_recorder.rb +4 -4
  22. data/lib/nanoc/rule_dsl/compilation_rule_context.rb +1 -1
  23. data/lib/nanoc/rule_dsl/compiler_dsl.rb +1 -1
  24. data/lib/nanoc/rule_dsl/rule_context.rb +6 -6
  25. data/lib/nanoc/version.rb +1 -1
  26. metadata +13 -152
  27. data/lib/nanoc/base/error.rb +0 -7
  28. data/lib/nanoc/base/feature.rb +0 -104
  29. data/lib/nanoc/base/repos.rb +0 -4
  30. data/lib/nanoc/base/repos/config_loader.rb +0 -95
  31. data/lib/nanoc/base/repos/site_loader.rb +0 -102
  32. data/lib/nanoc/base/services.rb +0 -23
  33. data/lib/nanoc/base/services/compiler.rb +0 -214
  34. data/lib/nanoc/base/services/compiler/phases.rb +0 -19
  35. data/lib/nanoc/base/services/compiler/phases/abstract.rb +0 -50
  36. data/lib/nanoc/base/services/compiler/phases/cache.rb +0 -45
  37. data/lib/nanoc/base/services/compiler/phases/mark_done.rb +0 -25
  38. data/lib/nanoc/base/services/compiler/phases/notify.rb +0 -21
  39. data/lib/nanoc/base/services/compiler/phases/recalculate.rb +0 -51
  40. data/lib/nanoc/base/services/compiler/phases/resume.rb +0 -54
  41. data/lib/nanoc/base/services/compiler/phases/write.rb +0 -86
  42. data/lib/nanoc/base/services/compiler/stages.rb +0 -23
  43. data/lib/nanoc/base/services/compiler/stages/build_reps.rb +0 -38
  44. data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +0 -44
  45. data/lib/nanoc/base/services/compiler/stages/cleanup.rb +0 -45
  46. data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +0 -98
  47. data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +0 -51
  48. data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +0 -22
  49. data/lib/nanoc/base/services/compiler/stages/load_stores.rb +0 -37
  50. data/lib/nanoc/base/services/compiler/stages/postprocess.rb +0 -23
  51. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +0 -34
  52. data/lib/nanoc/base/services/compiler/stages/prune.rb +0 -32
  53. data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +0 -22
  54. data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +0 -34
  55. data/lib/nanoc/base/services/compiler_loader.rb +0 -48
  56. data/lib/nanoc/base/services/executor.rb +0 -134
  57. data/lib/nanoc/base/services/filter.rb +0 -267
  58. data/lib/nanoc/base/services/item_rep_builder.rb +0 -54
  59. data/lib/nanoc/base/services/item_rep_selector.rb +0 -69
  60. data/lib/nanoc/base/services/item_rep_writer.rb +0 -86
  61. data/lib/nanoc/base/services/outdatedness_checker.rb +0 -222
  62. data/lib/nanoc/base/services/outdatedness_rules.rb +0 -18
  63. data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +0 -41
  64. data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +0 -31
  65. data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +0 -21
  66. data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +0 -20
  67. data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +0 -20
  68. data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +0 -17
  69. data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +0 -45
  70. data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +0 -26
  71. data/lib/nanoc/base/services/pruner.rb +0 -123
  72. data/lib/nanoc/base/views.rb +0 -40
  73. data/lib/nanoc/base/views/basic_item_rep_collection_view.rb +0 -86
  74. data/lib/nanoc/base/views/basic_item_rep_view.rb +0 -81
  75. data/lib/nanoc/base/views/basic_item_view.rb +0 -52
  76. data/lib/nanoc/base/views/compilation_item_rep_collection_view.rb +0 -10
  77. data/lib/nanoc/base/views/compilation_item_rep_view.rb +0 -49
  78. data/lib/nanoc/base/views/compilation_item_view.rb +0 -45
  79. data/lib/nanoc/base/views/config_view.rb +0 -68
  80. data/lib/nanoc/base/views/identifiable_collection_view.rb +0 -109
  81. data/lib/nanoc/base/views/item_collection_with_reps_view.rb +0 -10
  82. data/lib/nanoc/base/views/item_collection_without_reps_view.rb +0 -10
  83. data/lib/nanoc/base/views/layout_collection_view.rb +0 -10
  84. data/lib/nanoc/base/views/layout_view.rb +0 -7
  85. data/lib/nanoc/base/views/mixins/document_view_mixin.rb +0 -88
  86. data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +0 -58
  87. data/lib/nanoc/base/views/mutable_config_view.rb +0 -14
  88. data/lib/nanoc/base/views/mutable_identifiable_collection_view.rb +0 -17
  89. data/lib/nanoc/base/views/mutable_item_collection_view.rb +0 -32
  90. data/lib/nanoc/base/views/mutable_item_view.rb +0 -7
  91. data/lib/nanoc/base/views/mutable_layout_collection_view.rb +0 -24
  92. data/lib/nanoc/base/views/mutable_layout_view.rb +0 -7
  93. data/lib/nanoc/base/views/post_compile_item_collection_view.rb +0 -10
  94. data/lib/nanoc/base/views/post_compile_item_rep_collection_view.rb +0 -10
  95. data/lib/nanoc/base/views/post_compile_item_rep_view.rb +0 -31
  96. data/lib/nanoc/base/views/post_compile_item_view.rb +0 -18
  97. data/lib/nanoc/base/views/view.rb +0 -41
  98. data/lib/nanoc/cli.rb +0 -241
  99. data/lib/nanoc/cli/ansi_string_colorizer.rb +0 -28
  100. data/lib/nanoc/cli/cleaning_stream.rb +0 -160
  101. data/lib/nanoc/cli/command_runner.rb +0 -72
  102. data/lib/nanoc/cli/commands/compile.rb +0 -57
  103. data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +0 -58
  104. data/lib/nanoc/cli/commands/compile_listeners/aggregate.rb +0 -50
  105. data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +0 -100
  106. data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +0 -101
  107. data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +0 -76
  108. data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +0 -170
  109. data/lib/nanoc/cli/commands/create-site.rb +0 -257
  110. data/lib/nanoc/cli/commands/nanoc.rb +0 -42
  111. data/lib/nanoc/cli/commands/prune.rb +0 -49
  112. data/lib/nanoc/cli/commands/shell.rb +0 -57
  113. data/lib/nanoc/cli/commands/show-data.rb +0 -185
  114. data/lib/nanoc/cli/commands/show-plugins.rb +0 -89
  115. data/lib/nanoc/cli/commands/view.rb +0 -68
  116. data/lib/nanoc/cli/error_handler.rb +0 -365
  117. data/lib/nanoc/cli/logger.rb +0 -75
  118. data/lib/nanoc/cli/stack_trace_writer.rb +0 -50
  119. data/lib/nanoc/cli/stream_cleaners.rb +0 -10
  120. data/lib/nanoc/cli/stream_cleaners/abstract.rb +0 -21
  121. data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +0 -13
  122. data/lib/nanoc/cli/stream_cleaners/utf8.rb +0 -17
  123. data/lib/nanoc/cli/transform.rb +0 -16
  124. data/lib/nanoc/spec.rb +0 -240
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc::CLI::Commands::CompileListeners
4
- class DiffGenerator < Abstract
5
- class Differ
6
- def initialize(path, str_a, str_b)
7
- @path = path
8
- @str_a = str_a
9
- @str_b = str_b
10
- end
11
-
12
- def call
13
- run
14
- end
15
-
16
- private
17
-
18
- def run
19
- lines_a = @str_a.lines.map(&:chomp)
20
- lines_b = @str_b.lines.map(&:chomp)
21
-
22
- diffs = Diff::LCS.diff(lines_a, lines_b)
23
-
24
- output = +''
25
- output << "--- #{@path}\n"
26
- output << "+++ #{@path}\n"
27
-
28
- prev_hunk = hunk = nil
29
- file_length_difference = 0
30
- diffs.each do |piece|
31
- begin
32
- hunk = Diff::LCS::Hunk.new(lines_a, lines_b, piece, 3, file_length_difference)
33
- file_length_difference = hunk.file_length_difference
34
-
35
- next unless prev_hunk
36
- next if hunk.merge(prev_hunk)
37
-
38
- output << prev_hunk.diff(:unified) << "\n"
39
- ensure
40
- prev_hunk = hunk
41
- end
42
- end
43
- last = prev_hunk.diff(:unified)
44
- output << last << "\n"
45
-
46
- output
47
- end
48
- end
49
-
50
- # @see Listener#enable_for?
51
- def self.enable_for?(command_runner, site)
52
- site.config[:enable_output_diff] || command_runner.options[:diff]
53
- end
54
-
55
- # @see Listener#start
56
- def start
57
- setup_diffs
58
-
59
- on(:rep_ready_for_diff) do |raw_path, old_content, new_content|
60
- generate_diff_for(raw_path, old_content, new_content)
61
- end
62
- end
63
-
64
- # @see Listener#stop
65
- def stop
66
- teardown_diffs
67
- end
68
-
69
- protected
70
-
71
- def setup_diffs
72
- @diff_lock = Mutex.new
73
- @diff_threads = []
74
- FileUtils.rm('output.diff') if File.file?('output.diff')
75
- end
76
-
77
- def teardown_diffs
78
- @diff_threads.each(&:join)
79
- end
80
-
81
- def generate_diff_for(path, old_content, new_content)
82
- return if old_content == new_content
83
-
84
- @diff_threads << Thread.new do
85
- # Simplify path
86
- # FIXME: do not depend on working directory
87
- if path.start_with?(Dir.getwd)
88
- path = path[(Dir.getwd.size + 1)..path.size]
89
- end
90
-
91
- # Generate diff
92
- diff = Differ.new(path, old_content, new_content).call
93
-
94
- # Write diff
95
- @diff_lock.synchronize do
96
- File.open('output.diff', 'a') { |io| io.write(diff) }
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc::CLI::Commands::CompileListeners
4
- class FileActionPrinter < Abstract
5
- def initialize(reps:)
6
- @reps = reps
7
-
8
- @stopwatches = {}
9
- end
10
-
11
- # @see Listener#start
12
- def start
13
- on(:compilation_started) do |rep|
14
- @stopwatches[rep] ||= DDMetrics::Stopwatch.new
15
- @stopwatches[rep].start
16
- end
17
-
18
- on(:compilation_suspended) do |rep|
19
- @stopwatches[rep].stop
20
- end
21
-
22
- cached_reps = Set.new
23
- on(:cached_content_used) do |rep|
24
- cached_reps << rep
25
- end
26
-
27
- on(:rep_write_enqueued) do |rep|
28
- @stopwatches[rep].stop
29
- end
30
-
31
- on(:rep_write_started) do |rep, _raw_path|
32
- @stopwatches[rep].start
33
- end
34
-
35
- on(:rep_write_ended) do |rep, _binary, path, is_created, is_modified|
36
- @stopwatches[rep].stop
37
- duration = @stopwatches[rep].duration
38
-
39
- action =
40
- if is_created then :create
41
- elsif is_modified then :update
42
- elsif cached_reps.include?(rep) then :cached
43
- else :identical
44
- end
45
- level =
46
- if is_created then :high
47
- elsif is_modified then :high
48
- else :low
49
- end
50
-
51
- # FIXME: do not depend on working directory
52
- if path.start_with?(Dir.getwd)
53
- path = path[(Dir.getwd.size + 1)..path.size]
54
- end
55
-
56
- log(level, action, path, duration)
57
- end
58
- end
59
-
60
- # @see Listener#stop
61
- def stop
62
- @reps.reject(&:compiled?).each do |rep|
63
- raw_paths = rep.raw_paths.values.flatten.uniq
64
- raw_paths.each do |raw_path|
65
- log(:low, :skip, raw_path, nil)
66
- end
67
- end
68
- end
69
-
70
- private
71
-
72
- def log(level, action, path, duration)
73
- Nanoc::CLI::Logger.instance.file(level, action, path, duration)
74
- end
75
- end
76
- end
@@ -1,170 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc::CLI::Commands::CompileListeners
4
- class TimingRecorder < Abstract
5
- attr_reader :stages_summary
6
- attr_reader :phases_summary
7
- attr_reader :outdatedness_rules_summary
8
- attr_reader :filters_summary
9
-
10
- # @see Listener#enable_for?
11
- def self.enable_for?(_command_runner, _site)
12
- Nanoc::CLI.verbosity >= 1
13
- end
14
-
15
- # @param [Enumerable<Nanoc::Core::ItemRep>] reps
16
- def initialize(reps:)
17
- @reps = reps
18
-
19
- @stages_summary = DDMetrics::Summary.new
20
- @phases_summary = DDMetrics::Summary.new
21
- @outdatedness_rules_summary = DDMetrics::Summary.new
22
- @filters_summary = DDMetrics::Summary.new
23
- @load_stores_summary = DDMetrics::Summary.new
24
- end
25
-
26
- # @see Listener#start
27
- def start
28
- on(:stage_ran) do |duration, klass|
29
- @stages_summary.observe(duration, name: klass.to_s.sub(/.*::/, ''))
30
- end
31
-
32
- on(:outdatedness_rule_ran) do |duration, klass|
33
- @outdatedness_rules_summary.observe(duration, name: klass.to_s.sub(/.*::/, ''))
34
- end
35
-
36
- filter_stopwatches = {}
37
-
38
- on(:filtering_started) do |rep, _filter_name|
39
- stopwatch_stack = filter_stopwatches.fetch(rep) { filter_stopwatches[rep] = [] }
40
- stopwatch_stack << DDMetrics::Stopwatch.new
41
- stopwatch_stack.last.start
42
- end
43
-
44
- on(:filtering_ended) do |rep, filter_name|
45
- stopwatch = filter_stopwatches.fetch(rep).pop
46
- stopwatch.stop
47
-
48
- @filters_summary.observe(stopwatch.duration, name: filter_name.to_s)
49
- end
50
-
51
- on(:store_loaded) do |duration, klass|
52
- @load_stores_summary.observe(duration, name: klass.to_s)
53
- end
54
-
55
- on(:compilation_suspended) do |rep, _target_rep, _snapshot_name|
56
- filter_stopwatches.fetch(rep).each(&:stop)
57
- end
58
-
59
- on(:compilation_started) do |rep|
60
- filter_stopwatches.fetch(rep, []).each(&:start)
61
- end
62
-
63
- setup_phase_notifications
64
- end
65
-
66
- # @see Listener#stop
67
- def stop
68
- print_profiling_feedback
69
- end
70
-
71
- protected
72
-
73
- def setup_phase_notifications
74
- stopwatches = {}
75
-
76
- on(:phase_started) do |phase_name, rep|
77
- stopwatch = stopwatches[[phase_name, rep]] = DDMetrics::Stopwatch.new
78
- stopwatch.start
79
- end
80
-
81
- on(:phase_ended) do |phase_name, rep|
82
- stopwatch = stopwatches[[phase_name, rep]]
83
- stopwatch.stop
84
-
85
- @phases_summary.observe(stopwatch.duration, name: phase_name)
86
- end
87
-
88
- on(:phase_yielded) do |phase_name, rep|
89
- stopwatch = stopwatches[[phase_name, rep]]
90
- stopwatch.stop
91
- end
92
-
93
- on(:phase_resumed) do |phase_name, rep|
94
- # It probably looks weird that a phase can be resumed even though it was not suspended earlier. This can happen when compilation is suspended, where you’d get the sequence started -> suspended -> started -> resumed.
95
- stopwatch = stopwatches[[phase_name, rep]]
96
- stopwatch.start unless stopwatch.running?
97
- end
98
-
99
- on(:phase_aborted) do |phase_name, rep|
100
- stopwatch = stopwatches[[phase_name, rep]]
101
- stopwatch.stop if stopwatch.running?
102
-
103
- @phases_summary.observe(stopwatch.duration, name: phase_name)
104
- end
105
- end
106
-
107
- def table_for_summary(name, summary)
108
- headers = [name.to_s, 'count', 'min', '.50', '.90', '.95', 'max', 'tot']
109
-
110
- rows = summary.map do |label, stats|
111
- name = label.fetch(:name)
112
-
113
- count = stats.count
114
- min = stats.min
115
- p50 = stats.quantile(0.50)
116
- p90 = stats.quantile(0.90)
117
- p95 = stats.quantile(0.95)
118
- tot = stats.sum
119
- max = stats.max
120
-
121
- [name, count.to_s] + [min, p50, p90, p95, max, tot].map { |r| "#{format('%4.2f', r)}s" }
122
- end
123
-
124
- [headers] + rows
125
- end
126
-
127
- def table_for_summary_durations(name, summary)
128
- headers = [name.to_s, 'tot']
129
-
130
- rows = summary.map do |label, stats|
131
- name = label.fetch(:name)
132
- [name, "#{format('%4.2f', stats.sum)}s"]
133
- end
134
-
135
- [headers] + rows
136
- end
137
-
138
- def print_profiling_feedback
139
- print_table_for_summary(:filters, @filters_summary)
140
- print_table_for_summary(:phases, @phases_summary) if Nanoc::CLI.verbosity >= 2
141
- print_table_for_summary_duration(:stages, @stages_summary) if Nanoc::CLI.verbosity >= 2
142
- print_table_for_summary(:outdatedness_rules, @outdatedness_rules_summary) if Nanoc::CLI.verbosity >= 2
143
- print_table_for_summary_duration(:load_stores, @load_stores_summary) if Nanoc::CLI.verbosity >= 2
144
- print_ddmemoize_metrics if Nanoc::CLI.verbosity >= 2
145
- end
146
-
147
- def print_table_for_summary(name, summary)
148
- return unless summary.any?
149
-
150
- puts
151
- print_table(table_for_summary(name, summary))
152
- end
153
-
154
- def print_table_for_summary_duration(name, summary)
155
- return unless summary.any?
156
-
157
- puts
158
- print_table(table_for_summary_durations(name, summary))
159
- end
160
-
161
- def print_ddmemoize_metrics
162
- puts
163
- DDMemoize.print_metrics
164
- end
165
-
166
- def print_table(rows)
167
- puts DDMetrics::Table.new(rows).to_s
168
- end
169
- end
170
- end
@@ -1,257 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- usage 'create-site [options] path'
4
- aliases :create_site, :cs
5
- summary 'create a site'
6
- description 'Create a new site at the given path. The site will use the `filesystem` data source.'
7
- flag nil, :force, 'force creation of new site'
8
- param :path
9
-
10
- module Nanoc::CLI::Commands
11
- class CreateSite < ::Nanoc::CLI::CommandRunner
12
- class << self
13
- protected
14
-
15
- # Converts the given array to YAML format
16
- def array_to_yaml(array)
17
- '[ ' + array.map { |s| "'" + s + "'" }.join(', ') + ' ]'
18
- end
19
- end
20
-
21
- DEFAULT_CONFIG = <<~EOS unless defined? DEFAULT_CONFIG
22
- # A list of file extensions that Nanoc will consider to be textual rather than
23
- # binary. If an item with an extension not in this list is found, the file
24
- # will be considered as binary.
25
- text_extensions: #{array_to_yaml(Nanoc::Core::Configuration::DEFAULT_CONFIG[:text_extensions])}
26
-
27
- prune:
28
- auto_prune: true
29
-
30
- data_sources:
31
- - type: filesystem
32
- encoding: utf-8
33
- EOS
34
-
35
- DEFAULT_RULES = <<~EOS unless defined? DEFAULT_RULES
36
- #!/usr/bin/env ruby
37
-
38
- compile '/index.html' do
39
- layout '/default.*'
40
- write '/index.html'
41
- end
42
-
43
- compile '/**/*.html' do
44
- layout '/default.*'
45
- write item.identifier.without_ext + '/index.html'
46
- end
47
-
48
- # This is an example rule that matches Markdown (.md) files, and filters them
49
- # using the :kramdown filter. It is commented out by default, because kramdown
50
- # is not bundled with Nanoc or Ruby.
51
- #
52
- #compile '/**/*.md' do
53
- # filter :kramdown
54
- # layout '/default.*'
55
- # write item.identifier.without_ext + '/index.html'
56
- #end
57
-
58
- compile '/**/*' do
59
- write item.identifier.to_s
60
- end
61
-
62
- layout '/**/*', :erb
63
- EOS
64
-
65
- DEFAULT_ITEM = <<~EOS unless defined? DEFAULT_ITEM
66
- ---
67
- title: Home
68
- ---
69
-
70
- <h1>A Brand New Nanoc Site</h1>
71
-
72
- <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>
73
-
74
- <ul>
75
- <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>
76
- <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>
77
- </ul>
78
-
79
- <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>
80
- EOS
81
-
82
- DEFAULT_STYLESHEET = <<~EOS unless defined? DEFAULT_STYLESHEET
83
- * {
84
- margin: 0;
85
- padding: 0;
86
-
87
- font-family: Georgia, Palatino, serif;
88
- }
89
-
90
- body {
91
- background: #fff;
92
- }
93
-
94
- a {
95
- text-decoration: none;
96
- }
97
-
98
- a:link,
99
- a:visited {
100
- color: #f30;
101
- }
102
-
103
- a:hover {
104
- color: #f90;
105
- }
106
-
107
- #main {
108
- position: absolute;
109
-
110
- top: 40px;
111
- left: 280px;
112
-
113
- width: 500px;
114
- }
115
-
116
- #main h1 {
117
- font-size: 40px;
118
- font-weight: normal;
119
-
120
- line-height: 40px;
121
-
122
- letter-spacing: -1px;
123
- }
124
-
125
- #main p {
126
- margin: 20px 0;
127
-
128
- font-size: 15px;
129
-
130
- line-height: 20px;
131
- }
132
-
133
- #main ul, #main ol {
134
- margin: 20px;
135
- }
136
-
137
- #main li {
138
- font-size: 15px;
139
-
140
- line-height: 20px;
141
- }
142
-
143
- #main ul li {
144
- list-style-type: square;
145
- }
146
-
147
- #sidebar {
148
- position: absolute;
149
-
150
- top: 40px;
151
- left: 20px;
152
- width: 200px;
153
-
154
- padding: 20px 20px 0 0;
155
-
156
- border-right: 1px solid #ccc;
157
-
158
- text-align: right;
159
- }
160
-
161
- #sidebar h2 {
162
- text-transform: uppercase;
163
-
164
- font-size: 13px;
165
-
166
- color: #333;
167
-
168
- letter-spacing: 1px;
169
-
170
- line-height: 20px;
171
- }
172
-
173
- #sidebar ul {
174
- list-style-type: none;
175
-
176
- margin: 20px 0;
177
- }
178
-
179
- #sidebar li {
180
- font-size: 14px;
181
-
182
- line-height: 20px;
183
- }
184
- EOS
185
-
186
- DEFAULT_LAYOUT = <<~EOS unless defined? DEFAULT_LAYOUT
187
- <!DOCTYPE HTML>
188
- <html lang="en">
189
- <head>
190
- <meta charset="utf-8">
191
- <title>A Brand New Nanoc Site - <%= @item[:title] %></title>
192
- <link rel="stylesheet" href="/stylesheet.css">
193
-
194
- <!-- you don't need to keep this, but it's cool for stats! -->
195
- <meta name="generator" content="Nanoc <%= Nanoc::VERSION %>">
196
- </head>
197
- <body>
198
- <div id="main">
199
- <%= yield %>
200
- </div>
201
- <div id="sidebar">
202
- <h2>Documentation</h2>
203
- <ul>
204
- <li><a href="https://nanoc.ws/doc/">Documentation</a></li>
205
- <li><a href="https://nanoc.ws/doc/tutorial/">Tutorial</a></li>
206
- </ul>
207
- <h2>Community</h2>
208
- <ul>
209
- <li><a href="http://groups.google.com/group/nanoc/">Discussion group</a></li>
210
- <li><a href="https://gitter.im/nanoc/nanoc">Gitter channel</a></li>
211
- <li><a href="https://nanoc.ws/contributing/">Contributing</a></li>
212
- </ul>
213
- </div>
214
- </body>
215
- </html>
216
- EOS
217
-
218
- def run
219
- path = arguments[:path]
220
-
221
- # Check whether site exists
222
- if File.exist?(path) && (!File.directory?(path) || !(Dir.entries(path) - %w[. ..]).empty?) && !options[:force]
223
- raise(
224
- Nanoc::Int::Errors::GenericTrivial,
225
- "The site was not created because '#{path}' already exists. " \
226
- 'Re-run the command using --force to create the site anyway.',
227
- )
228
- end
229
-
230
- # Build entire site
231
- FileUtils.mkdir_p(path)
232
- FileUtils.cd(File.join(path)) do
233
- FileUtils.mkdir_p('content')
234
- FileUtils.mkdir_p('layouts')
235
- FileUtils.mkdir_p('lib')
236
- FileUtils.mkdir_p('output')
237
-
238
- write('nanoc.yaml', DEFAULT_CONFIG)
239
- write('Rules', DEFAULT_RULES)
240
- write('content/index.html', DEFAULT_ITEM)
241
- write('content/stylesheet.css', DEFAULT_STYLESHEET)
242
- write('layouts/default.html', DEFAULT_LAYOUT)
243
- end
244
-
245
- puts "Created a blank Nanoc site at '#{path}'. Enjoy!"
246
- end
247
-
248
- private
249
-
250
- def write(filename, content)
251
- File.write(filename, content)
252
- Nanoc::CLI::Logger.instance.file(:high, :create, filename)
253
- end
254
- end
255
- end
256
-
257
- runner Nanoc::CLI::Commands::CreateSite