nanoc 4.11.12 → 4.11.13

Sign up to get free protection for your applications and to get access to all the features.
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,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- usage 'nanoc command [options] [arguments]'
4
- summary 'Nanoc, a static site compiler written in Ruby'
5
- default_subcommand 'compile'
6
-
7
- opt :l, :color, 'enable color' do
8
- $stdout.remove_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
9
- $stderr.remove_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
10
- end
11
-
12
- opt :d, :debug, 'enable debugging' do
13
- Nanoc::CLI.debug = true
14
- end
15
-
16
- opt :e, :env, 'set environment', argument: :required do |value|
17
- ENV.store('NANOC_ENV', value)
18
- end
19
-
20
- opt :h, :help, 'show the help message and quit' do |_value, cmd|
21
- puts cmd.help
22
- exit 0
23
- end
24
-
25
- opt :C, :'no-color', 'disable color' do
26
- $stdout.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
27
- $stderr.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
28
- end
29
-
30
- opt :V, :verbose, 'make output more detailed', multiple: true do |val|
31
- Nanoc::CLI::Logger.instance.level = :low
32
- Nanoc::CLI.verbosity = val.size
33
- end
34
-
35
- opt :v, :version, 'show version information and quit' do
36
- puts Nanoc.version_information
37
- exit 0
38
- end
39
-
40
- opt :w, :warn, 'enable warnings' do
41
- $-w = true
42
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- usage 'prune'
4
- summary 'remove files not managed by Nanoc from the output directory'
5
- description <<~EOS
6
- Find all files in the output directory that do not correspond to an item
7
- managed by Nanoc and remove them. Since this is a hazardous operation, an
8
- additional `--yes` flag is needed as confirmation.
9
-
10
- Also see the `auto_prune` configuration option in `nanoc.yaml` (`config.yaml`
11
- for older Nanoc sites), which will automatically prune after compilation.
12
- EOS
13
- no_params
14
-
15
- flag :y, :yes, 'confirm deletion'
16
- flag :n, :'dry-run', 'print files to be deleted instead of actually deleting them'
17
-
18
- module Nanoc::CLI::Commands
19
- class Prune < ::Nanoc::CLI::CommandRunner
20
- def run
21
- @site = load_site
22
- res = Nanoc::Int::Compiler.new_for(@site).run_until_reps_built
23
- reps = res.fetch(:reps)
24
-
25
- if options.key?(:yes)
26
- Nanoc::Pruner.new(@site.config, reps, exclude: prune_config_exclude).run
27
- elsif options.key?(:'dry-run')
28
- Nanoc::Pruner.new(@site.config, reps, exclude: prune_config_exclude, dry_run: true).run
29
- else
30
- $stderr.puts 'WARNING: Since the prune command is a destructive command, it requires an additional --yes flag in order to work.'
31
- $stderr.puts
32
- $stderr.puts 'Please ensure that the output directory does not contain any files (such as images or stylesheets) that are necessary but are not managed by Nanoc. If you want to get a list of all files that would be removed, pass --dry-run.'
33
- exit 1
34
- end
35
- end
36
-
37
- protected
38
-
39
- def prune_config
40
- @site.config[:prune] || {}
41
- end
42
-
43
- def prune_config_exclude
44
- prune_config[:exclude] || {}
45
- end
46
- end
47
- end
48
-
49
- runner Nanoc::CLI::Commands::Prune
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- usage 'shell'
4
- summary 'open a shell on the Nanoc environment'
5
- aliases 'console', 'sh'
6
- description "
7
- Open an IRB shell on a context that contains @items, @layouts, and @config.
8
- "
9
- flag :p, :preprocess, 'run preprocessor'
10
- no_params
11
-
12
- module Nanoc::CLI::Commands
13
- class Shell < ::Nanoc::CLI::CommandRunner
14
- def run
15
- require 'pry'
16
-
17
- # Needed to make pry behave properly sometimes -- see nanoc/nanoc#1309
18
- Signal.trap('SIGINT') { raise Interrupt }
19
-
20
- @site = load_site
21
- Nanoc::Int::Compiler.new_for(@site).run_until_preprocessed if options[:preprocess]
22
-
23
- Nanoc::Core::Context.new(env).pry
24
- end
25
-
26
- def env
27
- self.class.env_for_site(@site)
28
- end
29
-
30
- def self.reps_for(site)
31
- Nanoc::Core::ItemRepRepo.new.tap do |reps|
32
- action_provider = Nanoc::Core::ActionProvider.named(site.config.action_provider).for(site)
33
- builder = Nanoc::Int::ItemRepBuilder.new(site, action_provider, reps)
34
- builder.run
35
- end
36
- end
37
-
38
- def self.view_context_for(site)
39
- Nanoc::Core::ViewContextForShell.new(
40
- items: site.items,
41
- reps: reps_for(site),
42
- )
43
- end
44
-
45
- def self.env_for_site(site)
46
- view_context = view_context_for(site)
47
-
48
- {
49
- items: Nanoc::ItemCollectionWithRepsView.new(site.items, view_context),
50
- layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context),
51
- config: Nanoc::ConfigView.new(site.config, view_context),
52
- }
53
- end
54
- end
55
- end
56
-
57
- runner Nanoc::CLI::Commands::Shell
@@ -1,185 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- usage 'show-data'
4
- aliases :debug
5
- summary 'show data in this site'
6
- description <<~EOS
7
- Show information about all items, item representations and layouts in the
8
- current site, along with dependency information.
9
- EOS
10
- no_params
11
-
12
- module Nanoc::CLI::Commands
13
- class ShowData < ::Nanoc::CLI::CommandRunner
14
- def run
15
- site = load_site
16
- res = Nanoc::Int::Compiler.new_for(site).run_until_precompiled
17
-
18
- items = site.items
19
- layouts = site.layouts
20
- reps = res.fetch(:reps)
21
- dependency_store = res.fetch(:dependency_store)
22
- outdatedness_checker = res.fetch(:outdatedness_checker)
23
-
24
- # Print data
25
- print_item_dependencies(items, dependency_store)
26
- print_item_rep_paths(items, reps)
27
- print_item_rep_outdatedness(items, outdatedness_checker, reps)
28
- print_layouts(layouts, outdatedness_checker)
29
- end
30
-
31
- protected
32
-
33
- def sorted_with_prev(objects)
34
- prev = nil
35
- objects.sort_by(&:identifier).each do |object|
36
- yield(object, prev)
37
- prev = object
38
- end
39
- end
40
-
41
- def sorted_reps_with_prev(items, reps)
42
- prev = nil
43
- items.sort_by(&:identifier).each do |item|
44
- reps[item].sort_by { |r| r.name.to_s }.each do |rep|
45
- yield(rep, prev)
46
- prev = rep
47
- end
48
- end
49
- end
50
-
51
- def print_header(title)
52
- header = '=' * 78
53
- header[3..(title.length + 5)] = " #{title} "
54
-
55
- puts
56
- puts header
57
- puts
58
- end
59
-
60
- def print_item_dependencies(items, dependency_store)
61
- print_header('Item dependencies')
62
-
63
- puts 'Legend:'
64
- puts ' r = dependency on raw content'
65
- puts ' a = dependency on attributes'
66
- puts ' c = dependency on compiled content'
67
- puts ' p = dependency on the path'
68
- puts
69
-
70
- sorter =
71
- lambda do |dep|
72
- case dep
73
- when Nanoc::Core::Document
74
- dep.from.identifier.to_s
75
- else
76
- ''
77
- end
78
- end
79
-
80
- sorted_with_prev(items) do |item, prev|
81
- puts if prev
82
- puts "item #{item.identifier} depends on:"
83
- dependencies =
84
- dependency_store
85
- .dependencies_causing_outdatedness_of(item)
86
- .sort_by(&sorter)
87
- dependencies.each do |dep|
88
- pred = dep.from
89
-
90
- type =
91
- case pred
92
- when Nanoc::Core::Layout
93
- 'layout'
94
- when Nanoc::Core::Item
95
- 'item'
96
- when Nanoc::Core::Configuration
97
- 'config'
98
- when Nanoc::Core::ItemCollection
99
- 'items'
100
- when Nanoc::Core::LayoutCollection
101
- 'layouts'
102
- else
103
- raise Nanoc::Int::Errors::InternalInconsistency, "unexpected pred type #{pred}"
104
- end
105
-
106
- pred_identifier =
107
- case pred
108
- when Nanoc::Core::Document
109
- pred.identifier.to_s
110
- when Nanoc::Core::Configuration
111
- nil
112
- when Nanoc::Core::IdentifiableCollection
113
- case dep.props.raw_content
114
- when true
115
- 'matching any'
116
- else
117
- "matching any of #{dep.props.raw_content.sort.join(', ')}"
118
- end
119
- else
120
- raise Nanoc::Int::Errors::InternalInconsistency, "unexpected pred type #{pred}"
121
- end
122
-
123
- if pred
124
- puts " [ #{format '%6s', type} ] (#{dep.props}) #{pred_identifier}"
125
- else
126
- puts ' ( removed item )'
127
- end
128
- end
129
- puts ' (nothing)' if dependencies.empty?
130
- end
131
- end
132
-
133
- def print_item_rep_paths(items, reps)
134
- print_header('Item representation paths')
135
-
136
- sorted_reps_with_prev(items, reps) do |rep, prev|
137
- puts if prev
138
- puts "item #{rep.item.identifier}, rep #{rep.name}:"
139
- if rep.raw_paths.empty?
140
- puts ' (not written)'
141
- end
142
- length = rep.raw_paths.keys.map { |s| s.to_s.length }.max
143
- rep.raw_paths.each do |snapshot_name, raw_paths|
144
- raw_paths.each do |raw_path|
145
- puts format(" [ %-#{length}s ] %s", snapshot_name, raw_path)
146
- end
147
- end
148
- end
149
- end
150
-
151
- def print_item_rep_outdatedness(items, outdatedness_checker, reps)
152
- print_header('Item representation outdatedness')
153
-
154
- sorted_reps_with_prev(items, reps) do |rep, prev|
155
- puts if prev
156
- puts "item #{rep.item.identifier}, rep #{rep.name}:"
157
- print_outdatedness_reasons_for(rep, outdatedness_checker)
158
- end
159
- end
160
-
161
- def print_layouts(layouts, outdatedness_checker)
162
- print_header('Layouts')
163
-
164
- sorted_with_prev(layouts) do |layout, prev|
165
- puts if prev
166
- puts "layout #{layout.identifier}:"
167
- print_outdatedness_reasons_for(layout, outdatedness_checker)
168
- end
169
- end
170
-
171
- def print_outdatedness_reasons_for(obj, outdatedness_checker)
172
- reasons = outdatedness_checker.outdatedness_reasons_for(obj)
173
- if reasons.any?
174
- puts ' is outdated:'
175
- reasons.each do |reason|
176
- puts " - #{reason.message}"
177
- end
178
- else
179
- puts ' is not outdated'
180
- end
181
- end
182
- end
183
- end
184
-
185
- runner Nanoc::CLI::Commands::ShowData
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- summary 'show all available plugins'
4
- aliases :info
5
- usage 'show-plugins [options]'
6
- description <<~EOS
7
- Show a list of available plugins, including filters and data sources.
8
- If the current directory contains a Nanoc web site, the plugins defined in this site will be shown as well.
9
- EOS
10
- no_params
11
-
12
- module Nanoc::CLI::Commands
13
- class ShowPlugins < ::Nanoc::CLI::CommandRunner
14
- def run
15
- # Get list of plugins (before and after)
16
- plugins_before = PLUGIN_CLASSES.keys.each_with_object({}) { |c, acc| acc[c] = c.all }
17
- site = load_site
18
- site&.code_snippets
19
- plugins_after = PLUGIN_CLASSES.keys.each_with_object({}) { |c, acc| acc[c] = c.all }
20
-
21
- # Divide list of plugins into builtin and custom
22
- plugins_builtin = plugins_before
23
- plugins_custom = plugins_after.each_with_object({}) do |(superclass, klasses), acc|
24
- acc[superclass] = klasses - plugins_before[superclass]
25
- end
26
-
27
- # Find max identifiers length
28
- all_identifiers = plugins_after.values.flatten.map(&:identifiers)
29
- max_identifiers_length = all_identifiers.map(&:to_s).map(&:size).max
30
-
31
- PLUGIN_CLASS_ORDER.each do |superclass|
32
- plugins_with_this_superclass = {
33
- builtin: plugins_builtin.fetch(superclass, []),
34
- custom: plugins_custom.fetch(superclass, []),
35
- }
36
-
37
- # Print kind
38
- kind = name_for_plugin_class(superclass)
39
- puts "#{kind}:"
40
- puts
41
-
42
- # Print plugins organised by subtype
43
- %i[builtin custom].each do |type|
44
- # Find relevant plugins
45
- relevant_plugins = plugins_with_this_superclass[type]
46
-
47
- # Print type
48
- puts " #{type}:"
49
- if relevant_plugins.empty?
50
- puts ' (none)'
51
- next
52
- end
53
-
54
- # Print plugins
55
- relevant_plugins.sort_by { |k| k.identifiers.join(', ') }.each do |plugin|
56
- # Display
57
- puts format(
58
- " %-#{max_identifiers_length}s (%s)",
59
- plugin.identifiers.join(', '),
60
- plugin.to_s.sub(/^::/, ''),
61
- )
62
- end
63
- end
64
-
65
- puts
66
- end
67
- end
68
-
69
- private
70
-
71
- PLUGIN_CLASS_ORDER = [
72
- Nanoc::Filter,
73
- Nanoc::DataSource,
74
- Nanoc::Deploying::Deployer,
75
- ].freeze
76
-
77
- PLUGIN_CLASSES = {
78
- Nanoc::Filter => 'Filters',
79
- Nanoc::DataSource => 'Data Sources',
80
- Nanoc::Deploying::Deployer => 'Deployers',
81
- }.freeze
82
-
83
- def name_for_plugin_class(klass)
84
- PLUGIN_CLASSES[klass]
85
- end
86
- end
87
- end
88
-
89
- runner Nanoc::CLI::Commands::ShowPlugins
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- usage 'view [options]'
4
- summary 'start the web server that serves static files'
5
- description <<~EOS
6
- Start the static web server. Unless specified, the web server will run on port
7
- 3000 and listen on all IP addresses. Running this static web server requires
8
- `adsf` (not `asdf`!).
9
- EOS
10
-
11
- required :H, :handler, 'specify the handler to use (webrick/mongrel/...)'
12
- required :o, :host, 'specify the host to listen on (default: 127.0.0.1)', default: '127.0.0.1'
13
- required :p, :port, 'specify the port to listen on (default: 3000)', transform: Nanoc::CLI::Transform::Port, default: 3000
14
- flag :L, :'live-reload', 'reload on changes'
15
- no_params
16
-
17
- module Nanoc::CLI::Commands
18
- class View < ::Nanoc::CLI::CommandRunner
19
- DEFAULT_HANDLER_NAME = :thin
20
-
21
- def run
22
- load_adsf
23
-
24
- config = Nanoc::Int::ConfigLoader.new.new_from_cwd
25
-
26
- # Create output dir so that viewer/watcher doesn’t explode.
27
- FileUtils.mkdir_p(config.output_dir)
28
-
29
- server =
30
- Adsf::Server.new(
31
- root: File.absolute_path(config.output_dir),
32
- live: options[:'live-reload'],
33
- index_filenames: config[:index_filenames],
34
- host: options[:host],
35
- port: options[:port],
36
- handler: options[:handler],
37
- )
38
-
39
- server.run
40
- end
41
-
42
- protected
43
-
44
- def load_adsf
45
- # Load adsf
46
- begin
47
- require 'adsf'
48
- return
49
- rescue LoadError
50
- $stderr.puts "Could not find the required 'adsf' gem, " \
51
- 'which is necessary for the view command.'
52
- end
53
-
54
- # Check asdf
55
- begin
56
- require 'asdf'
57
- $stderr.puts "You appear to have 'asdf' installed, " \
58
- "but not 'adsf'. Please install 'adsf' (check the spelling)!"
59
- rescue LoadError
60
- end
61
-
62
- # Done
63
- exit 1
64
- end
65
- end
66
- end
67
-
68
- runner Nanoc::CLI::Commands::View