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,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module MutableDocumentViewMixin
5
- # @api private
6
- class DisallowedAttributeValueError < Nanoc::Error
7
- attr_reader :value
8
-
9
- def initialize(value)
10
- @value = value
11
- end
12
-
13
- def message
14
- "The #{value.class} cannot be stored inside an attribute. Store its identifier instead."
15
- end
16
- end
17
-
18
- def raw_content=(arg)
19
- _unwrap.content = Nanoc::Core::Content.create(arg)
20
- end
21
-
22
- # Sets the value for the given attribute.
23
- #
24
- # @param [Symbol] key
25
- #
26
- # @see Hash#[]=
27
- def []=(key, value)
28
- disallowed_value_classes = Set.new([
29
- Nanoc::Core::Item,
30
- Nanoc::Core::Layout,
31
- Nanoc::CompilationItemView,
32
- Nanoc::LayoutView,
33
- ])
34
- if disallowed_value_classes.include?(value.class)
35
- raise DisallowedAttributeValueError.new(value)
36
- end
37
-
38
- _unwrap.set_attribute(key, value)
39
- end
40
-
41
- # Sets the identifier to the given argument.
42
- #
43
- # @param [String, Nanoc::Core::Identifier] arg
44
- def identifier=(arg)
45
- _unwrap.identifier = Nanoc::Core::Identifier.from(arg)
46
- end
47
-
48
- # Updates the attributes based on the given hash.
49
- #
50
- # @param [Hash] hash
51
- #
52
- # @return [self]
53
- def update_attributes(hash)
54
- hash.each { |k, v| _unwrap.set_attribute(k, v) }
55
- self
56
- end
57
- end
58
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class MutableConfigView < Nanoc::ConfigView
5
- # Sets the value for the given attribute.
6
- #
7
- # @param [Symbol] key
8
- #
9
- # @see Hash#[]=
10
- def []=(key, value)
11
- @config[key] = value
12
- end
13
- end
14
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class MutableIdentifiableCollectionView < Nanoc::IdentifiableCollectionView
5
- # Deletes every object for which the block evaluates to true.
6
- #
7
- # @yieldparam [#identifier] object
8
- #
9
- # @yieldreturn [Boolean]
10
- #
11
- # @return [self]
12
- def delete_if(&_block)
13
- @objects = @objects.reject { |o| yield(view_class.new(o, @context)) }
14
- self
15
- end
16
- end
17
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class MutableItemCollectionView < Nanoc::MutableIdentifiableCollectionView
5
- # @api private
6
- def view_class
7
- Nanoc::MutableItemView
8
- end
9
-
10
- # Creates a new item and adds it to the site’s collection of items.
11
- #
12
- # @param [String] content The uncompiled item content (if it is a textual
13
- # item) or the path to the filename containing the content (if it is a
14
- # binary item).
15
- #
16
- # @param [Hash] attributes A hash containing this item's attributes.
17
- #
18
- # @param [Nanoc::Core::Identifier, String] identifier This item's identifier.
19
- #
20
- # @param [Boolean] binary Whether or not this item is binary
21
- #
22
- # @param [String] filename Absolute path to the file
23
- # containing this content (if any)
24
- #
25
- # @return [self]
26
- def create(content, attributes, identifier, binary: false, filename: nil)
27
- content = Nanoc::Core::Content.create(content, binary: binary, filename: filename)
28
- @objects = @objects.add(Nanoc::Core::Item.new(content, attributes, identifier))
29
- self
30
- end
31
- end
32
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class MutableItemView < Nanoc::BasicItemView
5
- include Nanoc::MutableDocumentViewMixin
6
- end
7
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class MutableLayoutCollectionView < Nanoc::MutableIdentifiableCollectionView
5
- # @api private
6
- def view_class
7
- Nanoc::MutableLayoutView
8
- end
9
-
10
- # Creates a new layout and adds it to the site’s collection of layouts.
11
- #
12
- # @param [String] content The layout content.
13
- #
14
- # @param [Hash] attributes A hash containing this layout's attributes.
15
- #
16
- # @param [Nanoc::Core::Identifier, String] identifier This layout's identifier.
17
- #
18
- # @return [self]
19
- def create(content, attributes, identifier)
20
- @objects = @objects.add(Nanoc::Core::Layout.new(content, attributes, identifier))
21
- self
22
- end
23
- end
24
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class MutableLayoutView < Nanoc::LayoutView
5
- include Nanoc::MutableDocumentViewMixin
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class PostCompileItemCollectionView < Nanoc::IdentifiableCollectionView
5
- # @api private
6
- def view_class
7
- Nanoc::PostCompileItemView
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class PostCompileItemRepCollectionView < Nanoc::BasicItemRepCollectionView
5
- # @api private
6
- def view_class
7
- Nanoc::PostCompileItemRepView
8
- end
9
- end
10
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class PostCompileItemRepView < ::Nanoc::BasicItemRepView
5
- def item_view_class
6
- Nanoc::PostCompileItemView
7
- end
8
-
9
- def compiled_content(snapshot: nil)
10
- compilation_context = @context.compilation_context
11
- snapshot_contents = compilation_context.compiled_content_cache[_unwrap] || {}
12
-
13
- snapshot_name = snapshot || (snapshot_contents[:pre] ? :pre : :last)
14
-
15
- unless snapshot_contents[snapshot_name]
16
- raise Nanoc::Int::Errors::NoSuchSnapshot.new(_unwrap, snapshot_name)
17
- end
18
-
19
- content = snapshot_contents[snapshot_name]
20
- if content.binary?
21
- raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(_unwrap)
22
- end
23
-
24
- content.string
25
- end
26
-
27
- def raw_path(snapshot: :last)
28
- @item_rep.raw_path(snapshot: snapshot)
29
- end
30
- end
31
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class PostCompileItemView < Nanoc::CompilationItemView
5
- def reps
6
- Nanoc::PostCompileItemRepCollectionView.new(@context.reps[_unwrap], @context)
7
- end
8
-
9
- # @deprecated Use {#modified_reps} instead
10
- def modified
11
- modified_reps
12
- end
13
-
14
- def modified_reps
15
- reps.select { |rep| rep._unwrap.modified? }
16
- end
17
- end
18
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class View
5
- include Nanoc::Core::ContractsSupport
6
-
7
- # @api private
8
- # TODO: disallow nil
9
- contract C::Maybe[C::Or[
10
- Nanoc::Core::ViewContextForCompilation,
11
- Nanoc::Core::ViewContextForPreCompilation,
12
- Nanoc::Core::ViewContextForShell
13
- ]] => C::Any
14
- def initialize(context)
15
- @context = context
16
- end
17
-
18
- # @api private
19
- def _context
20
- @context
21
- end
22
-
23
- # @api private
24
- def _unwrap
25
- raise NotImplementedError
26
- end
27
-
28
- # True if the wrapped object is frozen; false otherwise.
29
- #
30
- # @return [Boolean]
31
- #
32
- # @see Object#frozen?
33
- def frozen?
34
- _unwrap.frozen?
35
- end
36
-
37
- def inspect
38
- "<#{self.class}>"
39
- end
40
- end
41
- end
@@ -1,241 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require 'cri'
5
- rescue LoadError => e
6
- $stderr.puts e
7
- $stderr.puts "If you are using a Gemfile, make sure that the Gemfile contains Nanoc ('gem \"nanoc\"')."
8
- exit 1
9
- end
10
-
11
- # @api private
12
- module Nanoc::CLI
13
- module Commands
14
- end
15
- end
16
-
17
- require_relative 'cli/ansi_string_colorizer'
18
- require_relative 'cli/logger'
19
- require_relative 'cli/command_runner'
20
- require_relative 'cli/cleaning_stream'
21
- require_relative 'cli/stream_cleaners'
22
- require_relative 'cli/error_handler'
23
- require_relative 'cli/stack_trace_writer'
24
- require_relative 'cli/transform'
25
-
26
- require_relative 'cli/commands/compile_listeners/abstract'
27
- require_relative 'cli/commands/compile_listeners/debug_printer'
28
- require_relative 'cli/commands/compile_listeners/diff_generator'
29
- require_relative 'cli/commands/compile_listeners/file_action_printer'
30
- require_relative 'cli/commands/compile_listeners/timing_recorder'
31
- require_relative 'cli/commands/compile_listeners/aggregate'
32
-
33
- # @api private
34
- module Nanoc::CLI
35
- # @return [Boolean] true if debug output is enabled, false if not
36
- def self.debug?
37
- @debug || false
38
- end
39
-
40
- # @param [Boolean] boolean true if debug output should be enabled,
41
- # false if it should not
42
- #
43
- # @return [void]
44
- def self.debug=(boolean)
45
- @debug = boolean
46
- end
47
-
48
- def self.verbosity
49
- @verbosity || 0
50
- end
51
-
52
- def self.verbosity=(val)
53
- @verbosity = val
54
- end
55
-
56
- # Invokes the Nanoc command-line tool with the given arguments.
57
- #
58
- # @param [Array<String>] args An array of command-line arguments
59
- #
60
- # @return [void]
61
- def self.run(args)
62
- Nanoc::CLI::ErrorHandler.handle_while do
63
- setup
64
- root_command.run(args)
65
- end
66
- end
67
-
68
- # @return [Cri::Command] The root command, i.e. the command-line tool itself
69
- def self.root_command
70
- @root_command
71
- end
72
-
73
- # Adds the given command to the collection of available commands.
74
- #
75
- # @param [Cri::Command] cmd The command to add
76
- #
77
- # @return [void]
78
- def self.add_command(cmd)
79
- root_command.add_command(cmd)
80
- end
81
-
82
- # Schedules the given block to be executed after the CLI has been set up.
83
- #
84
- # @return [void]
85
- def self.after_setup(&block)
86
- # TODO: decide what should happen if the CLI is already set up
87
- add_after_setup_proc(block)
88
- end
89
-
90
- # Makes the command-line interface ready for use.
91
- #
92
- # @return [void]
93
- def self.setup
94
- setup_cleaning_streams
95
- setup_commands
96
- load_custom_commands
97
- after_setup_procs.each(&:call)
98
- end
99
-
100
- # Sets up the root command and base subcommands.
101
- #
102
- # @return [void]
103
- def self.setup_commands
104
- # Reinit
105
- @root_command = nil
106
-
107
- # Add root command
108
- filename = __dir__ + '/cli/commands/nanoc.rb'
109
- @root_command = Cri::Command.load_file(filename, infer_name: true)
110
-
111
- # Add help command
112
- help_cmd = Cri::Command.new_basic_help
113
- add_command(help_cmd)
114
-
115
- # Add other commands
116
- cmd_filenames = Dir[__dir__ + '/cli/commands/*.rb']
117
- cmd_filenames.each do |cmd_filename|
118
- basename = File.basename(cmd_filename, '.rb')
119
-
120
- next if basename == 'nanoc'
121
-
122
- cmd = Cri::Command.load_file(cmd_filename, infer_name: true)
123
- add_command(cmd)
124
- end
125
-
126
- if defined?(Bundler)
127
- # Discover external commands through Bundler
128
- begin
129
- Bundler.require(:nanoc)
130
- rescue Bundler::GemfileNotFound
131
- # When running Nanoc with Bundler being defined but
132
- # no gemfile being present (rubygems automatically loads
133
- # Bundler when executing from command line), don't crash.
134
- end
135
- end
136
- end
137
-
138
- # Loads site-specific commands.
139
- #
140
- # @return [void]
141
- def self.load_custom_commands
142
- if Nanoc::Int::SiteLoader.cwd_is_nanoc_site?
143
- config = Nanoc::Int::ConfigLoader.new.new_from_cwd
144
- config[:commands_dirs].each do |path|
145
- load_commands_at(path)
146
- end
147
- end
148
- end
149
-
150
- def self.load_commands_at(path)
151
- recursive_contents_of(path).each do |filename|
152
- # Create command
153
- command = Cri::Command.load_file(filename, infer_name: true)
154
-
155
- # Get supercommand
156
- pieces = filename.gsub(/^#{path}\/|\.rb$/, '').split('/')
157
- pieces = pieces[0, pieces.size - 1] || []
158
- root = Nanoc::CLI.root_command
159
- supercommand = pieces.reduce(root) do |cmd, piece|
160
- cmd.nil? ? nil : cmd.command_named(piece)
161
- end
162
-
163
- # Add to supercommand
164
- if supercommand.nil?
165
- raise "Cannot load command at #{filename} because its supercommand cannot be found"
166
- end
167
-
168
- supercommand.add_command(command)
169
- end
170
- end
171
-
172
- # Loads the command in the file with the given filename.
173
- #
174
- # @param [String] filename The name of the file that contains the command
175
- #
176
- # @return [Cri::Command] The loaded command
177
- #
178
- # @deprecated
179
- def self.load_command_at(filename)
180
- # TODO: remove me one guard-nanoc is in this repo
181
- Cri::Command.load_file(filename, infer_name: true)
182
- end
183
-
184
- # @return [Array] The directory contents
185
- def self.recursive_contents_of(path)
186
- return [] unless File.directory?(path)
187
-
188
- files, dirs = *Dir[path + '/*'].sort.partition { |e| File.file?(e) }
189
- dirs.each { |d| files.concat recursive_contents_of(d) }
190
- files
191
- end
192
-
193
- # Wraps the given stream in a cleaning stream. The cleaning streams will
194
- # have the proper stream cleaners configured.
195
- #
196
- # @param [IO] io The stream to wrap
197
- #
198
- # @return [::Nanoc::CLI::CleaningStream]
199
- def self.wrap_in_cleaning_stream(io)
200
- cio = ::Nanoc::CLI::CleaningStream.new(io)
201
-
202
- unless enable_utf8?(io)
203
- cio.add_stream_cleaner(Nanoc::CLI::StreamCleaners::UTF8)
204
- end
205
-
206
- unless enable_ansi_colors?(io)
207
- cio.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
208
- end
209
-
210
- cio
211
- end
212
-
213
- # Wraps `$stdout` and `$stderr` in appropriate cleaning streams.
214
- #
215
- # @return [void]
216
- def self.setup_cleaning_streams
217
- $stdout = wrap_in_cleaning_stream($stdout)
218
- $stderr = wrap_in_cleaning_stream($stderr)
219
- end
220
-
221
- # @return [Boolean] true if UTF-8 support is present, false if not
222
- def self.enable_utf8?(io)
223
- return true unless io.tty?
224
-
225
- %w[LC_ALL LC_CTYPE LANG].any? { |e| ENV[e] =~ /UTF/i }
226
- end
227
-
228
- # @return [Boolean] true if color support is present, false if not
229
- def self.enable_ansi_colors?(io)
230
- io.tty? && !ENV.key?('NO_COLOR')
231
- end
232
-
233
- def self.after_setup_procs
234
- @after_setup_procs || []
235
- end
236
-
237
- def self.add_after_setup_proc(proc)
238
- @after_setup_procs ||= []
239
- @after_setup_procs << proc
240
- end
241
- end