nanoc 4.11.12 → 4.11.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +788 -743
  3. data/bin/nanoc +1 -1
  4. data/lib/nanoc.rb +6 -29
  5. data/lib/nanoc/data_sources/filesystem.rb +9 -3
  6. data/lib/nanoc/data_sources/filesystem/tools.rb +4 -4
  7. data/lib/nanoc/extra.rb +2 -1
  8. data/lib/nanoc/extra/core_ext.rb +0 -1
  9. data/lib/nanoc/extra/srcset_parser.rb +79 -0
  10. data/lib/nanoc/filters/colorize_syntax/colorizers.rb +1 -1
  11. data/lib/nanoc/filters/erb.rb +1 -5
  12. data/lib/nanoc/filters/relativize_paths.rb +62 -10
  13. data/lib/nanoc/filters/sass/functions.rb +1 -1
  14. data/lib/nanoc/helpers/blogging.rb +8 -8
  15. data/lib/nanoc/helpers/capturing.rb +1 -1
  16. data/lib/nanoc/helpers/link_to.rb +1 -1
  17. data/lib/nanoc/helpers/rendering.rb +5 -4
  18. data/lib/nanoc/orig_cli.rb +15 -0
  19. data/lib/nanoc/{cli → orig_cli}/commands/show-rules.rb +3 -3
  20. data/lib/nanoc/rule_dsl.rb +1 -0
  21. data/lib/nanoc/rule_dsl/action_provider.rb +6 -6
  22. data/lib/nanoc/rule_dsl/action_recorder.rb +4 -4
  23. data/lib/nanoc/rule_dsl/compilation_rule_context.rb +1 -1
  24. data/lib/nanoc/rule_dsl/compiler_dsl.rb +2 -2
  25. data/lib/nanoc/rule_dsl/errors.rb +25 -0
  26. data/lib/nanoc/rule_dsl/rule_context.rb +6 -6
  27. data/lib/nanoc/rule_dsl/rules_loader.rb +1 -1
  28. data/lib/nanoc/version.rb +1 -1
  29. metadata +23 -158
  30. data/lib/nanoc/base.rb +0 -16
  31. data/lib/nanoc/base/changes_stream.rb +0 -53
  32. data/lib/nanoc/base/error.rb +0 -7
  33. data/lib/nanoc/base/errors.rb +0 -163
  34. data/lib/nanoc/base/feature.rb +0 -104
  35. data/lib/nanoc/base/repos.rb +0 -4
  36. data/lib/nanoc/base/repos/config_loader.rb +0 -95
  37. data/lib/nanoc/base/repos/site_loader.rb +0 -102
  38. data/lib/nanoc/base/services.rb +0 -23
  39. data/lib/nanoc/base/services/compiler.rb +0 -214
  40. data/lib/nanoc/base/services/compiler/phases.rb +0 -19
  41. data/lib/nanoc/base/services/compiler/phases/abstract.rb +0 -50
  42. data/lib/nanoc/base/services/compiler/phases/cache.rb +0 -45
  43. data/lib/nanoc/base/services/compiler/phases/mark_done.rb +0 -25
  44. data/lib/nanoc/base/services/compiler/phases/notify.rb +0 -21
  45. data/lib/nanoc/base/services/compiler/phases/recalculate.rb +0 -51
  46. data/lib/nanoc/base/services/compiler/phases/resume.rb +0 -54
  47. data/lib/nanoc/base/services/compiler/phases/write.rb +0 -86
  48. data/lib/nanoc/base/services/compiler/stages.rb +0 -23
  49. data/lib/nanoc/base/services/compiler/stages/build_reps.rb +0 -38
  50. data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +0 -44
  51. data/lib/nanoc/base/services/compiler/stages/cleanup.rb +0 -45
  52. data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +0 -98
  53. data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +0 -51
  54. data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +0 -22
  55. data/lib/nanoc/base/services/compiler/stages/load_stores.rb +0 -37
  56. data/lib/nanoc/base/services/compiler/stages/postprocess.rb +0 -23
  57. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +0 -34
  58. data/lib/nanoc/base/services/compiler/stages/prune.rb +0 -32
  59. data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +0 -22
  60. data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +0 -34
  61. data/lib/nanoc/base/services/compiler_loader.rb +0 -48
  62. data/lib/nanoc/base/services/executor.rb +0 -134
  63. data/lib/nanoc/base/services/filter.rb +0 -267
  64. data/lib/nanoc/base/services/item_rep_builder.rb +0 -54
  65. data/lib/nanoc/base/services/item_rep_selector.rb +0 -69
  66. data/lib/nanoc/base/services/item_rep_writer.rb +0 -86
  67. data/lib/nanoc/base/services/outdatedness_checker.rb +0 -222
  68. data/lib/nanoc/base/services/outdatedness_rules.rb +0 -18
  69. data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +0 -41
  70. data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +0 -31
  71. data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +0 -21
  72. data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +0 -20
  73. data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +0 -20
  74. data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +0 -17
  75. data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +0 -45
  76. data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +0 -26
  77. data/lib/nanoc/base/services/pruner.rb +0 -123
  78. data/lib/nanoc/base/views.rb +0 -40
  79. data/lib/nanoc/base/views/basic_item_rep_collection_view.rb +0 -86
  80. data/lib/nanoc/base/views/basic_item_rep_view.rb +0 -81
  81. data/lib/nanoc/base/views/basic_item_view.rb +0 -52
  82. data/lib/nanoc/base/views/compilation_item_rep_collection_view.rb +0 -10
  83. data/lib/nanoc/base/views/compilation_item_rep_view.rb +0 -49
  84. data/lib/nanoc/base/views/compilation_item_view.rb +0 -45
  85. data/lib/nanoc/base/views/config_view.rb +0 -68
  86. data/lib/nanoc/base/views/identifiable_collection_view.rb +0 -109
  87. data/lib/nanoc/base/views/item_collection_with_reps_view.rb +0 -10
  88. data/lib/nanoc/base/views/item_collection_without_reps_view.rb +0 -10
  89. data/lib/nanoc/base/views/layout_collection_view.rb +0 -10
  90. data/lib/nanoc/base/views/layout_view.rb +0 -7
  91. data/lib/nanoc/base/views/mixins/document_view_mixin.rb +0 -88
  92. data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +0 -58
  93. data/lib/nanoc/base/views/mutable_config_view.rb +0 -14
  94. data/lib/nanoc/base/views/mutable_identifiable_collection_view.rb +0 -17
  95. data/lib/nanoc/base/views/mutable_item_collection_view.rb +0 -32
  96. data/lib/nanoc/base/views/mutable_item_view.rb +0 -7
  97. data/lib/nanoc/base/views/mutable_layout_collection_view.rb +0 -24
  98. data/lib/nanoc/base/views/mutable_layout_view.rb +0 -7
  99. data/lib/nanoc/base/views/post_compile_item_collection_view.rb +0 -10
  100. data/lib/nanoc/base/views/post_compile_item_rep_collection_view.rb +0 -10
  101. data/lib/nanoc/base/views/post_compile_item_rep_view.rb +0 -31
  102. data/lib/nanoc/base/views/post_compile_item_view.rb +0 -18
  103. data/lib/nanoc/base/views/view.rb +0 -41
  104. data/lib/nanoc/checking.rb +0 -14
  105. data/lib/nanoc/checking/check.rb +0 -93
  106. data/lib/nanoc/checking/checks.rb +0 -14
  107. data/lib/nanoc/checking/checks/css.rb +0 -16
  108. data/lib/nanoc/checking/checks/external_links.rb +0 -151
  109. data/lib/nanoc/checking/checks/html.rb +0 -16
  110. data/lib/nanoc/checking/checks/internal_links.rb +0 -95
  111. data/lib/nanoc/checking/checks/mixed_content.rb +0 -37
  112. data/lib/nanoc/checking/checks/stale.rb +0 -41
  113. data/lib/nanoc/checking/checks/w3c_validator.rb +0 -31
  114. data/lib/nanoc/checking/dsl.rb +0 -27
  115. data/lib/nanoc/checking/issue.rb +0 -16
  116. data/lib/nanoc/checking/loader.rb +0 -50
  117. data/lib/nanoc/checking/runner.rb +0 -136
  118. data/lib/nanoc/cli.rb +0 -241
  119. data/lib/nanoc/cli/ansi_string_colorizer.rb +0 -28
  120. data/lib/nanoc/cli/cleaning_stream.rb +0 -160
  121. data/lib/nanoc/cli/command_runner.rb +0 -72
  122. data/lib/nanoc/cli/commands/check.rb +0 -43
  123. data/lib/nanoc/cli/commands/compile.rb +0 -57
  124. data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +0 -58
  125. data/lib/nanoc/cli/commands/compile_listeners/aggregate.rb +0 -50
  126. data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +0 -100
  127. data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +0 -101
  128. data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +0 -76
  129. data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +0 -170
  130. data/lib/nanoc/cli/commands/create-site.rb +0 -257
  131. data/lib/nanoc/cli/commands/deploy.rb +0 -126
  132. data/lib/nanoc/cli/commands/nanoc.rb +0 -42
  133. data/lib/nanoc/cli/commands/prune.rb +0 -49
  134. data/lib/nanoc/cli/commands/shell.rb +0 -57
  135. data/lib/nanoc/cli/commands/show-data.rb +0 -185
  136. data/lib/nanoc/cli/commands/show-plugins.rb +0 -89
  137. data/lib/nanoc/cli/commands/view.rb +0 -68
  138. data/lib/nanoc/cli/error_handler.rb +0 -365
  139. data/lib/nanoc/cli/logger.rb +0 -75
  140. data/lib/nanoc/cli/stack_trace_writer.rb +0 -50
  141. data/lib/nanoc/cli/stream_cleaners.rb +0 -10
  142. data/lib/nanoc/cli/stream_cleaners/abstract.rb +0 -21
  143. data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +0 -13
  144. data/lib/nanoc/cli/stream_cleaners/utf8.rb +0 -17
  145. data/lib/nanoc/cli/transform.rb +0 -16
  146. data/lib/nanoc/deploying.rb +0 -10
  147. data/lib/nanoc/deploying/deployer.rb +0 -45
  148. data/lib/nanoc/deploying/deployers.rb +0 -11
  149. data/lib/nanoc/deploying/deployers/fog.rb +0 -220
  150. data/lib/nanoc/deploying/deployers/git.rb +0 -112
  151. data/lib/nanoc/deploying/deployers/rsync.rb +0 -68
  152. data/lib/nanoc/extra/core_ext/pathname.rb +0 -27
  153. data/lib/nanoc/spec.rb +0 -240
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- module Nanoc
5
- module Int
6
- end
7
- end
8
-
9
- require_relative 'base/error'
10
- require_relative 'base/errors'
11
- require_relative 'base/changes_stream'
12
-
13
- require_relative 'base/feature'
14
- require_relative 'base/repos'
15
- require_relative 'base/services'
16
- require_relative 'base/views'
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- class ChangesStream
5
- class ChangesListener
6
- def initialize(y)
7
- @y = y
8
- end
9
-
10
- def unknown
11
- @y << :unknown
12
- end
13
-
14
- def lib
15
- @y << :lib
16
- end
17
-
18
- def to_stop(&block)
19
- if block_given?
20
- @to_stop = block
21
- else
22
- @to_stop
23
- end
24
- end
25
- end
26
-
27
- def initialize(enum: nil)
28
- @enum = enum
29
- @enum ||=
30
- Enumerator.new do |y|
31
- @listener = ChangesListener.new(y)
32
- yield(@listener)
33
- end.lazy
34
- end
35
-
36
- def stop
37
- @listener&.to_stop&.call
38
- end
39
-
40
- def map
41
- self.class.new(enum: @enum.map { |e| yield(e) })
42
- end
43
-
44
- def to_enum
45
- @enum
46
- end
47
-
48
- def each
49
- @enum.each { |e| yield(e) }
50
- nil
51
- end
52
- end
53
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- # Generic error. Superclass for all Nanoc-specific errors.
5
- class Error < ::StandardError
6
- end
7
- end
@@ -1,163 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- # Module that contains all Nanoc-specific errors.
6
- #
7
- # @api private
8
- module Errors
9
- Generic = ::Nanoc::Error
10
-
11
- UnmetDependency = ::Nanoc::Core::Errors::UnmetDependency
12
- NoSuchSnapshot = ::Nanoc::Core::Errors::NoSuchSnapshot
13
- CannotGetCompiledContentOfBinaryItem = ::Nanoc::Core::Errors::CannotGetCompiledContentOfBinaryItem
14
-
15
- # Generic trivial error. Superclass for all Nanoc-specific errors that are
16
- # considered "trivial", i.e. errors that do not require a full crash report.
17
- class GenericTrivial < Generic
18
- end
19
-
20
- # Error that is raised when compilation of an item rep fails. The
21
- # underlying error is available by calling `#unwrap`.
22
- class CompilationError < Generic
23
- attr_reader :item_rep
24
-
25
- def initialize(wrapped, item_rep)
26
- @wrapped = wrapped
27
- @item_rep = item_rep
28
- end
29
-
30
- def unwrap
31
- @wrapped
32
- end
33
- end
34
-
35
- # Error that is raised when a site is loaded that uses a data source with
36
- # an unknown identifier.
37
- class UnknownDataSource < Generic
38
- # @param [String] data_source_name The data source name for which no
39
- # data source could be found
40
- def initialize(data_source_name)
41
- super("The data source specified in the site’s configuration file, “#{data_source_name}”, does not exist.")
42
- end
43
- end
44
-
45
- # Error that is raised during site compilation when an item uses a layout
46
- # that is not present in the site.
47
- class UnknownLayout < Generic
48
- # @param [String] layout_identifier The layout identifier for which no
49
- # layout could be found
50
- def initialize(layout_identifier)
51
- super("The site does not have a layout with identifier “#{layout_identifier}”.")
52
- end
53
- end
54
-
55
- # Error that is raised during site compilation when a layout is compiled
56
- # for which the filter cannot be determined. This is similar to the
57
- # {UnknownFilter} error, but specific for filters for layouts.
58
- class CannotDetermineFilter < Generic
59
- # @param [String] layout_identifier The identifier of the layout for
60
- # which the filter could not be determined
61
- def initialize(layout_identifier)
62
- super("The filter to be used for the “#{layout_identifier}” layout could not be determined. Make sure the layout does have a filter.")
63
- end
64
- end
65
-
66
- # Error that is raised during site compilation when an item (directly or
67
- # indirectly) includes its own item content, leading to endless recursion.
68
- class DependencyCycle < Generic
69
- def initialize(stack)
70
- start_idx = stack.index(stack.last)
71
- cycle = stack[start_idx..-2]
72
-
73
- msg_bits = []
74
- msg_bits << 'The site cannot be compiled because there is a dependency cycle:'
75
- msg_bits << ''
76
- cycle.each.with_index do |r, i|
77
- msg_bits << " (#{i + 1}) item #{r.item.identifier}, rep #{r.name.inspect}, uses compiled content of"
78
- end
79
- msg_bits << msg_bits.pop + ' (1)'
80
-
81
- super(msg_bits.map { |x| x + "\n" }.join(''))
82
- end
83
- end
84
-
85
- # Error that is raised when no rules file can be found in the current
86
- # working directory.
87
- class NoRulesFileFound < Generic
88
- def initialize
89
- super('This site does not have a rules file, which is required for Nanoc sites.')
90
- end
91
- end
92
-
93
- # Error that is raised when no compilation rule that can be applied to the
94
- # current item can be found.
95
- class NoMatchingCompilationRuleFound < Generic
96
- # @param [Nanoc::Core::Item] item The item for which no compilation rule
97
- # could be found
98
- def initialize(item)
99
- super("No compilation rules were found for the “#{item.identifier}” item.")
100
- end
101
- end
102
-
103
- # Error that is raised when no routing rule that can be applied to the
104
- # current item can be found.
105
- class NoMatchingRoutingRuleFound < Generic
106
- # @param [Nanoc::Core::ItemRep] rep The item repiresentation for which no
107
- # routing rule could be found
108
- def initialize(rep)
109
- super("No routing rules were found for the “#{rep.item.identifier}” item (rep “#{rep.name}”).")
110
- end
111
- end
112
-
113
- # Error that is raised when a binary item is attempted to be laid out.
114
- class CannotLayoutBinaryItem < Generic
115
- # @param [Nanoc::Core::ItemRep] rep The item representation that was attempted
116
- # to be laid out
117
- def initialize(rep)
118
- super("The “#{rep.item.identifier}” item (rep “#{rep.name}”) cannot be laid out because it is a binary item. If you are getting this error for an item that should be textual instead of binary, make sure that its extension is included in the text_extensions array in the site configuration.")
119
- end
120
- end
121
-
122
- # Error that is raised when a textual filter is attempted to be applied to
123
- # a binary item representation.
124
- class CannotUseTextualFilter < Generic
125
- # @param [Nanoc::Core::ItemRep] rep The item representation that was
126
- # attempted to be filtered
127
- #
128
- # @param [Class] filter_class The filter class that was used
129
- def initialize(rep, filter_class)
130
- super("The “#{filter_class.inspect}” filter cannot be used to filter the “#{rep.item.identifier}” item (rep “#{rep.name}”), because textual filters cannot be used on binary items.")
131
- end
132
- end
133
-
134
- # Error that is raised when a binary filter is attempted to be applied to
135
- # a textual item representation.
136
- class CannotUseBinaryFilter < Generic
137
- # @param [Nanoc::Core::ItemRep] rep The item representation that was
138
- # attempted to be filtered
139
- #
140
- # @param [Class] filter_class The filter class that was used
141
- def initialize(rep, filter_class)
142
- super("The “#{filter_class.inspect}” filter cannot be used to filter the “#{rep.item.identifier}” item (rep “#{rep.name}”), because binary filters cannot be used on textual items. If you are getting this error for an item that should be textual instead of binary, make sure that its extension is included in the text_extensions array in the site configuration.")
143
- end
144
- end
145
-
146
- # Error that is raised when attempting to call #parent or #children on an item with a legacy identifier.
147
- class CannotGetParentOrChildrenOfNonLegacyItem < Generic
148
- def initialize(identifier)
149
- super("You cannot get the parent or children of an item that has a “full” identifier (#{identifier}). Getting the parent or children of an item is only possible for items that have a legacy identifier.")
150
- end
151
- end
152
-
153
- class AmbiguousMetadataAssociation < Generic
154
- def initialize(content_filenames, meta_filename)
155
- super("There are multiple content files (#{content_filenames.sort.join(', ')}) that could match the file containing metadata (#{meta_filename}).")
156
- end
157
- end
158
-
159
- class InternalInconsistency < Generic
160
- end
161
- end
162
- end
163
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- # @api private
5
- #
6
- # @example Defining a feature and checking its enabledness
7
- #
8
- # Nanoc::Feature.define('environments', version: '4.3')
9
- # Nanoc::Feature.enabled?(Nanoc::Feature::ENVIRONMENTS)
10
- #
11
- module Feature
12
- # Defines a new feature with the given name, experimental in the given
13
- # version. The feature will be made available as a constant with the same
14
- # name, in uppercase, on the Nanoc::Feature module.
15
- #
16
- # @example Defining Nanoc::Feature::ENVIRONMENTS
17
- #
18
- # Nanoc::Feature.define('environments', version: '4.3')
19
- #
20
- # @param name The name of the feature
21
- #
22
- # @param version The minor version in which the feature is considered
23
- # experimental.
24
- #
25
- # @return [void]
26
- def self.define(name, version:)
27
- repo[name] = version
28
- const_set(name.upcase, name)
29
- end
30
-
31
- # Undefines the feature with the given name. For testing purposes only.
32
- #
33
- # @param name The name of the feature
34
- #
35
- # @return [void]
36
- #
37
- # @private
38
- def self.undefine(name)
39
- repo.delete(name)
40
- remove_const(name.upcase)
41
- end
42
-
43
- # @param [String] feature_name
44
- #
45
- # @return [Boolean] Whether or not the feature with the given name is enabled
46
- def self.enabled?(feature_name)
47
- enabled_features.include?(feature_name) ||
48
- enabled_features.include?('all')
49
- end
50
-
51
- # @api private
52
- def self.enable(feature_name)
53
- raise ArgumentError, 'no block given' unless block_given?
54
-
55
- if enabled?(feature_name)
56
- yield
57
- else
58
- begin
59
- enabled_features << feature_name
60
- yield
61
- ensure
62
- enabled_features.delete(feature_name)
63
- end
64
- end
65
- end
66
-
67
- # @api private
68
- def self.reset_caches
69
- @enabled_features = nil
70
- end
71
-
72
- # @api private
73
- def self.enabled_features
74
- @enabled_features ||= Set.new(ENV.fetch('NANOC_FEATURES', '').split(','))
75
- end
76
-
77
- # @api private
78
- def self.repo
79
- @repo ||= {}
80
- end
81
-
82
- # @return [Enumerable<String>] Names of features that still exist, but
83
- # should not be considered as experimental in the current version of
84
- # Nanoc.
85
- def self.all_outdated
86
- repo.keys.reject do |name|
87
- version = repo[name]
88
- Nanoc::VERSION.start_with?(version)
89
- end
90
- end
91
- end
92
- end
93
-
94
- # Tracking issue:
95
- # https://github.com/nanoc/features/issues/24
96
- Nanoc::Feature.define('live_cmd', version: '4.11')
97
-
98
- # Tracking issue:
99
- # https://github.com/nanoc/features/issues/40
100
- Nanoc::Feature.define('toml', version: '4.11')
101
-
102
- # Tracking issue:
103
- # https://github.com/nanoc/features/issues/20
104
- Nanoc::Feature.define('binary_compiled_content_cache', version: '4.11')
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'repos/config_loader'
4
- require_relative 'repos/site_loader'
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- # @api private
6
- class ConfigLoader
7
- class NoConfigFileFoundError < ::Nanoc::Error
8
- def initialize
9
- super('No configuration file found')
10
- end
11
- end
12
-
13
- class NoParentConfigFileFoundError < ::Nanoc::Error
14
- def initialize(filename)
15
- super("There is no parent configuration file at #{filename}")
16
- end
17
- end
18
-
19
- class CyclicalConfigFileError < ::Nanoc::Error
20
- def initialize(filename)
21
- super("The parent configuration file at #{filename} includes one of its descendants")
22
- end
23
- end
24
-
25
- # @return [Boolean]
26
- def self.cwd_is_nanoc_site?
27
- !config_filename_for_cwd.nil?
28
- end
29
-
30
- # @return [String]
31
- def self.config_filename_for_cwd
32
- filenames =
33
- if Nanoc::Feature.enabled?(Nanoc::Feature::TOML)
34
- %w[nanoc.yaml config.yaml nanoc.toml]
35
- else
36
- %w[nanoc.yaml config.yaml]
37
- end
38
- candidate = filenames.find { |f| File.file?(f) }
39
- candidate && File.expand_path(candidate)
40
- end
41
-
42
- def new_from_cwd
43
- # Determine path
44
- filename = self.class.config_filename_for_cwd
45
- raise NoConfigFileFoundError if filename.nil?
46
-
47
- # Read
48
- config =
49
- apply_parent_config(
50
- Nanoc::Core::Configuration.new(
51
- hash: load_file(filename),
52
- dir: File.dirname(filename),
53
- ),
54
- [filename],
55
- ).with_defaults
56
-
57
- # Load environment
58
- config.with_environment
59
- end
60
-
61
- def load_file(filename)
62
- case File.extname(filename)
63
- when '.yaml'
64
- YAML.load_file(filename)
65
- when '.toml'
66
- Tomlrb.load_file(filename)
67
- else
68
- raise Nanoc::Int::Errors::InternalInconsistency, 'Unhandled config file extension'
69
- end
70
- end
71
-
72
- # @api private
73
- def apply_parent_config(config, processed_paths = [])
74
- parent_path = config[:parent_config_file]
75
- return config if parent_path.nil?
76
-
77
- # Get absolute path
78
- parent_path = File.absolute_path(parent_path, File.dirname(processed_paths.last))
79
- unless File.file?(parent_path)
80
- raise NoParentConfigFileFoundError.new(parent_path)
81
- end
82
-
83
- # Check recursion
84
- if processed_paths.include?(parent_path)
85
- raise CyclicalConfigFileError.new(parent_path)
86
- end
87
-
88
- # Load
89
- parent_config = Nanoc::Core::Configuration.new(hash: load_file(parent_path), dir: config.dir)
90
- full_parent_config = apply_parent_config(parent_config, processed_paths + [parent_path])
91
- full_parent_config.merge(config.without(:parent_config_file))
92
- end
93
- end
94
- end
95
- end