nanoc-core 4.14.6 → 4.14.8

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nanoc/core/action_sequence.rb +1 -1
  3. data/lib/nanoc/core/action_sequence_builder.rb +12 -4
  4. data/lib/nanoc/core/action_sequence_store.rb +8 -5
  5. data/lib/nanoc/core/assertions.rb +12 -2
  6. data/lib/nanoc/core/basic_outdatedness_checker.rb +26 -10
  7. data/lib/nanoc/core/binary_compiled_content_cache.rb +24 -10
  8. data/lib/nanoc/core/checksum_collection.rb +7 -2
  9. data/lib/nanoc/core/checksum_store.rb +26 -9
  10. data/lib/nanoc/core/checksummer.rb +63 -32
  11. data/lib/nanoc/core/code_snippet.rb +1 -1
  12. data/lib/nanoc/core/compilation_stages/build_reps.rb +7 -2
  13. data/lib/nanoc/core/compilation_stages/calculate_checksums.rb +2 -0
  14. data/lib/nanoc/core/compilation_stages/cleanup.rb +8 -2
  15. data/lib/nanoc/core/compilation_stages/compile_reps.rb +78 -36
  16. data/lib/nanoc/core/compilation_stages/determine_outdatedness.rb +2 -0
  17. data/lib/nanoc/core/compilation_stages/forget_outdated_dependencies.rb +5 -1
  18. data/lib/nanoc/core/compilation_stages/load_stores.rb +6 -1
  19. data/lib/nanoc/core/compilation_stages/postprocess.rb +2 -0
  20. data/lib/nanoc/core/compilation_stages/preprocess.rb +12 -3
  21. data/lib/nanoc/core/compilation_stages/prune.rb +6 -1
  22. data/lib/nanoc/core/compilation_stages/store_post_compilation_state.rb +2 -0
  23. data/lib/nanoc/core/compilation_stages/store_pre_compilation_state.rb +6 -1
  24. data/lib/nanoc/core/compiled_content_cache.rb +7 -2
  25. data/lib/nanoc/core/compiled_content_repo.rb +13 -5
  26. data/lib/nanoc/core/compiler.rb +12 -3
  27. data/lib/nanoc/core/compiler_loader.rb +13 -4
  28. data/lib/nanoc/core/config_loader.rb +14 -4
  29. data/lib/nanoc/core/configuration.rb +36 -15
  30. data/lib/nanoc/core/content.rb +5 -1
  31. data/lib/nanoc/core/context.rb +4 -5
  32. data/lib/nanoc/core/contracts_support.rb +26 -8
  33. data/lib/nanoc/core/core_ext/hash.rb +12 -2
  34. data/lib/nanoc/core/data_source.rb +22 -6
  35. data/lib/nanoc/core/dependency.rb +8 -2
  36. data/lib/nanoc/core/dependency_props.rb +27 -8
  37. data/lib/nanoc/core/dependency_store.rb +55 -22
  38. data/lib/nanoc/core/dependency_tracker.rb +20 -4
  39. data/lib/nanoc/core/directed_graph.rb +27 -64
  40. data/lib/nanoc/core/document.rb +4 -1
  41. data/lib/nanoc/core/errors.rb +45 -12
  42. data/lib/nanoc/core/executor.rb +26 -9
  43. data/lib/nanoc/core/feature.rb +2 -1
  44. data/lib/nanoc/core/filter.rb +27 -11
  45. data/lib/nanoc/core/identifiable_collection.rb +2 -1
  46. data/lib/nanoc/core/identifier.rb +23 -8
  47. data/lib/nanoc/core/in_memory_data_source.rb +3 -1
  48. data/lib/nanoc/core/item.rb +1 -1
  49. data/lib/nanoc/core/item_collection.rb +2 -2
  50. data/lib/nanoc/core/item_rep.rb +1 -1
  51. data/lib/nanoc/core/item_rep_builder.rb +14 -5
  52. data/lib/nanoc/core/item_rep_router.rb +27 -13
  53. data/lib/nanoc/core/item_rep_writer.rb +28 -5
  54. data/lib/nanoc/core/layout.rb +1 -1
  55. data/lib/nanoc/core/layout_collection.rb +2 -2
  56. data/lib/nanoc/core/mutable_document_view_mixin.rb +3 -6
  57. data/lib/nanoc/core/outdatedness_checker.rb +170 -95
  58. data/lib/nanoc/core/outdatedness_reasons.rb +45 -16
  59. data/lib/nanoc/core/outdatedness_rules/attributes_modified.rb +24 -10
  60. data/lib/nanoc/core/outdatedness_rules/item_added.rb +9 -4
  61. data/lib/nanoc/core/outdatedness_rules/layout_added.rb +9 -4
  62. data/lib/nanoc/core/outdatedness_rules/not_written.rb +7 -2
  63. data/lib/nanoc/core/outdatedness_rules/rules_modified.rb +14 -6
  64. data/lib/nanoc/core/outdatedness_rules/uses_always_outdated_filter.rb +1 -1
  65. data/lib/nanoc/core/outdatedness_store.rb +7 -1
  66. data/lib/nanoc/core/pattern.rb +4 -1
  67. data/lib/nanoc/core/prefixed_data_source.rb +6 -2
  68. data/lib/nanoc/core/processing_actions/filter.rb +2 -0
  69. data/lib/nanoc/core/processing_actions/layout.rb +2 -0
  70. data/lib/nanoc/core/processing_actions/snapshot.rb +12 -3
  71. data/lib/nanoc/core/pruner.rb +11 -3
  72. data/lib/nanoc/core/regexp_pattern.rb +1 -1
  73. data/lib/nanoc/core/site.rb +10 -4
  74. data/lib/nanoc/core/site_loader.rb +25 -17
  75. data/lib/nanoc/core/store.rb +33 -6
  76. data/lib/nanoc/core/string_pattern.rb +1 -1
  77. data/lib/nanoc/core/textual_compiled_content_cache.rb +60 -5
  78. data/lib/nanoc/core/textual_content.rb +4 -1
  79. data/lib/nanoc/core/version.rb +1 -1
  80. data/lib/nanoc/core/view_context_for_compilation.rb +6 -2
  81. data/lib/nanoc/core/views/basic_item_rep_collection_view.rb +11 -4
  82. data/lib/nanoc/core/views/basic_item_rep_view.rb +9 -2
  83. data/lib/nanoc/core/views/basic_item_view.rb +17 -9
  84. data/lib/nanoc/core/views/compilation_item_rep_view.rb +12 -4
  85. data/lib/nanoc/core/views/compilation_item_view.rb +3 -1
  86. data/lib/nanoc/core/views/identifiable_collection_view.rb +17 -5
  87. data/lib/nanoc/core/views/mutable_item_collection_view.rb +5 -2
  88. data/lib/nanoc/core/views/mutable_layout_collection_view.rb +5 -2
  89. data/lib/nanoc/core/views/post_compile_item_view.rb +3 -1
  90. data/lib/nanoc/core.rb +4 -4
  91. metadata +3 -9
  92. data/lib/nanoc/core/compilation_phases/abstract.rb +0 -48
  93. data/lib/nanoc/core/compilation_phases/cache.rb +0 -28
  94. data/lib/nanoc/core/compilation_phases/mark_done.rb +0 -23
  95. data/lib/nanoc/core/compilation_phases/notify.rb +0 -22
  96. data/lib/nanoc/core/compilation_phases/recalculate.rb +0 -59
  97. data/lib/nanoc/core/compilation_phases/write.rb +0 -31
@@ -7,7 +7,12 @@ module Nanoc
7
7
  include Nanoc::Core::ContractsSupport
8
8
  include Nanoc::Core::Assertions::Mixin
9
9
 
10
- def initialize(reps:, outdatedness_store:, dependency_store:, action_sequences:, compilation_context:, compiled_content_cache:, focus:)
10
+ def initialize(
11
+ reps:, outdatedness_store:, dependency_store:, action_sequences:,
12
+ compilation_context:, compiled_content_cache:, focus:
13
+ )
14
+ super()
15
+
11
16
  @reps = reps
12
17
  @outdatedness_store = outdatedness_store
13
18
  @dependency_store = dependency_store
@@ -15,13 +20,18 @@ module Nanoc
15
20
  @compilation_context = compilation_context
16
21
  @compiled_content_cache = compiled_content_cache
17
22
  @focus = focus
23
+
24
+ @compiled_content_repo = @compilation_context.compiled_content_repo
25
+
26
+ @writer = Nanoc::Core::ItemRepWriter.new
18
27
  end
19
28
 
20
29
  def run
21
30
  outdated_reps = @reps.select { |r| @outdatedness_store.include?(r) }
22
31
 
23
32
  # If a focus is specified, only compile reps that match this focus.
24
- # (If no focus is specified, `@focus` will be `nil`, not an empty array.)
33
+ # (If no focus is specified, `@focus` will be `nil`, not an empty
34
+ # array.)
25
35
  if @focus
26
36
  focus_patterns = @focus.map { |f| Nanoc::Core::Pattern.from(f) }
27
37
 
@@ -39,11 +49,9 @@ module Nanoc
39
49
  dependency_store: @dependency_store,
40
50
  )
41
51
 
42
- run_phase_stack do |phase_stack|
43
- selector.each do |rep|
44
- handle_errors_while(rep) do
45
- compile_rep(rep, phase_stack:, is_outdated: @outdatedness_store.include?(rep))
46
- end
52
+ selector.each do |rep|
53
+ handle_errors_while(rep) do
54
+ compile_rep(rep, outdated_reps:)
47
55
  end
48
56
  end
49
57
 
@@ -67,44 +75,78 @@ module Nanoc
67
75
  raise Nanoc::Core::Errors::CompilationError.new(e, item_rep)
68
76
  end
69
77
 
70
- def compile_rep(rep, phase_stack:, is_outdated:)
71
- phase_stack.call(rep, is_outdated:)
72
- end
78
+ def compile_rep(rep, outdated_reps:)
79
+ Nanoc::Core::NotificationCenter.post(:compilation_started, rep)
73
80
 
74
- def run_phase_stack
75
- phase_stack = build_phase_stack
76
- phase_stack.start
77
- yield(phase_stack)
78
- ensure
79
- phase_stack.stop
81
+ outdated = outdated_reps.include?(rep)
82
+ if !outdated && @compiled_content_cache.full_cache_available?(rep)
83
+ Nanoc::Core::NotificationCenter.post(:cached_content_used, rep)
84
+ @compiled_content_repo.set_all(rep, @compiled_content_cache[rep])
85
+ rep.compiled = true
86
+ end
87
+
88
+ unless rep.compiled?
89
+ recalculate_rep(rep)
90
+ @compiled_content_cache[rep] = @compiled_content_repo.get_all(rep)
91
+ rep.compiled = true
92
+ end
93
+
94
+ if outdated
95
+ # Caution: Notification must be posted before enqueueing the rep,
96
+ # or we risk a race condition where the :rep_write_ended
97
+ # notification happens before the :rep_write_enqueued one.
98
+ Nanoc::Core::NotificationCenter.post(:rep_write_enqueued, rep)
99
+ @writer.write_all(rep, @compiled_content_repo)
100
+ end
101
+
102
+ @outdatedness_store.remove(rep)
103
+
104
+ Nanoc::Core::NotificationCenter.post(:compilation_ended, rep)
105
+ rescue Nanoc::Core::Errors::UnmetDependency
106
+ Nanoc::Core::NotificationCenter.post(:compilation_suspended, rep)
107
+ raise
80
108
  end
81
109
 
82
- def build_phase_stack
83
- recalculate_phase = Nanoc::Core::CompilationPhases::Recalculate.new(
84
- action_sequences: @action_sequences,
85
- dependency_store: @dependency_store,
86
- compilation_context: @compilation_context,
110
+ def recalculate_rep(rep)
111
+ dependency_tracker = Nanoc::Core::DependencyTracker.new(
112
+ @dependency_store, root: rep.item
87
113
  )
88
114
 
89
- cache_phase = Nanoc::Core::CompilationPhases::Cache.new(
90
- compiled_content_cache: @compiled_content_cache,
91
- compiled_content_repo: @compilation_context.compiled_content_repo,
92
- wrapped: recalculate_phase,
115
+ executor = Nanoc::Core::Executor.new(
116
+ rep, @compilation_context, dependency_tracker
93
117
  )
94
118
 
95
- write_phase = Nanoc::Core::CompilationPhases::Write.new(
96
- compiled_content_repo: @compilation_context.compiled_content_repo,
97
- wrapped: cache_phase,
98
- )
119
+ # Set initial content, if not already present
120
+ compiled_content_repo = @compilation_context.compiled_content_repo
121
+ unless compiled_content_repo.get_current(rep)
122
+ compiled_content_repo.set_current(rep, rep.item.content)
123
+ end
99
124
 
100
- mark_done_phase = Nanoc::Core::CompilationPhases::MarkDone.new(
101
- wrapped: write_phase,
102
- outdatedness_store: @outdatedness_store,
103
- )
125
+ actions = pending_action_sequence_for(rep:)
126
+ until actions.empty?
127
+ action = actions.first
128
+
129
+ case action
130
+ when Nanoc::Core::ProcessingActions::Filter
131
+ executor.filter(action.filter_name, action.params)
132
+ when Nanoc::Core::ProcessingActions::Layout
133
+ executor.layout(action.layout_identifier, action.params)
134
+ when Nanoc::Core::ProcessingActions::Snapshot
135
+ action.snapshot_names.each do |snapshot_name|
136
+ executor.snapshot(snapshot_name)
137
+ end
138
+ else
139
+ raise Nanoc::Core::Errors::InternalInconsistency,
140
+ "unknown action #{action.inspect}"
141
+ end
104
142
 
105
- Nanoc::Core::CompilationPhases::Notify.new(
106
- wrapped: mark_done_phase,
107
- )
143
+ actions.shift
144
+ end
145
+ end
146
+
147
+ def pending_action_sequence_for(rep:)
148
+ @_pending_action_sequences ||= {}
149
+ @_pending_action_sequences[rep] ||= @action_sequences[rep].to_a
108
150
  end
109
151
  end
110
152
  end
@@ -7,6 +7,8 @@ module Nanoc
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
9
  def initialize(reps:, outdatedness_checker:, outdatedness_store:)
10
+ super()
11
+
10
12
  @reps = reps
11
13
  @outdatedness_checker = outdatedness_checker
12
14
  @outdatedness_store = outdatedness_store
@@ -7,12 +7,16 @@ module Nanoc
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
9
  def initialize(dependency_store:)
10
+ super()
11
+
10
12
  @dependency_store = dependency_store
11
13
  end
12
14
 
13
15
  contract C::IterOf[Nanoc::Core::Item] => C::Any
14
16
  def run(outdated_items)
15
- outdated_items.each { |i| @dependency_store.forget_dependencies_for(i) }
17
+ outdated_items.each do |i|
18
+ @dependency_store.forget_dependencies_for(i)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -6,7 +6,12 @@ module Nanoc
6
6
  class LoadStores < Nanoc::Core::CompilationStage
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
- def initialize(checksum_store:, compiled_content_cache:, dependency_store:, action_sequence_store:, outdatedness_store:)
9
+ def initialize(
10
+ checksum_store:, compiled_content_cache:, dependency_store:,
11
+ action_sequence_store:, outdatedness_store:
12
+ )
13
+ super()
14
+
10
15
  @checksum_store = checksum_store
11
16
  @compiled_content_cache = compiled_content_cache
12
17
  @dependency_store = dependency_store
@@ -7,6 +7,8 @@ module Nanoc
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
9
  def initialize(action_provider:, site:)
10
+ super()
11
+
10
12
  @action_provider = action_provider
11
13
  @site = site
12
14
  end
@@ -4,7 +4,10 @@ module Nanoc
4
4
  module Core
5
5
  module CompilationStages
6
6
  class Preprocess < Nanoc::Core::CompilationStage
7
- def initialize(action_provider:, site:, dependency_store:, checksum_store:)
7
+ def initialize(action_provider:, site:, dependency_store:,
8
+ checksum_store:)
9
+ super()
10
+
8
11
  @action_provider = action_provider
9
12
  @site = site
10
13
  @dependency_store = dependency_store
@@ -15,12 +18,18 @@ module Nanoc
15
18
  return if @site.preprocessed?
16
19
 
17
20
  if @action_provider.need_preprocessing?
18
- @site.data_source = Nanoc::Core::InMemoryDataSource.new(@site.items, @site.layouts, @site.data_source)
21
+ @site.data_source = Nanoc::Core::InMemoryDataSource.new(
22
+ @site.items, @site.layouts, @site.data_source
23
+ )
19
24
  @action_provider.preprocess(@site)
20
25
 
21
26
  @dependency_store.items = @site.items
22
27
  @dependency_store.layouts = @site.layouts
23
- @checksum_store.objects = @site.items.to_a + @site.layouts.to_a + @site.code_snippets + [@site.config]
28
+ @checksum_store.objects =
29
+ @site.items.to_a +
30
+ @site.layouts.to_a +
31
+ @site.code_snippets +
32
+ [@site.config]
24
33
  end
25
34
 
26
35
  @site.mark_as_preprocessed
@@ -5,13 +5,18 @@ module Nanoc
5
5
  module CompilationStages
6
6
  class Prune < Nanoc::Core::CompilationStage
7
7
  def initialize(config:, reps:)
8
+ super()
9
+
8
10
  @config = config
9
11
  @reps = reps
10
12
  end
11
13
 
12
14
  def run
13
15
  if @config[:prune][:auto_prune]
14
- Nanoc::Core::Pruner.new(@config, @reps, exclude: prune_config_exclude).run
16
+ Nanoc::Core::Pruner.new(
17
+ @config, @reps,
18
+ exclude: prune_config_exclude
19
+ ).run
15
20
  end
16
21
  end
17
22
 
@@ -7,6 +7,8 @@ module Nanoc
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
9
  def initialize(dependency_store:)
10
+ super()
11
+
10
12
  @dependency_store = dependency_store
11
13
  end
12
14
 
@@ -6,7 +6,12 @@ module Nanoc
6
6
  class StorePreCompilationState < Nanoc::Core::CompilationStage
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
- def initialize(reps:, layouts:, checksum_store:, action_sequence_store:, action_sequences:)
9
+ def initialize(
10
+ reps:, layouts:, checksum_store:,
11
+ action_sequence_store:, action_sequences:
12
+ )
13
+ super()
14
+
10
15
  @reps = reps
11
16
  @layouts = layouts
12
17
  @checksum_store = checksum_store
@@ -6,7 +6,7 @@ module Nanoc
6
6
  # to prevent it from being needlessly recompiled.
7
7
  #
8
8
  # @api private
9
- class CompiledContentCache < ::Nanoc::Core::Store
9
+ class CompiledContentCache
10
10
  include Nanoc::Core::ContractsSupport
11
11
 
12
12
  contract C::KeywordArgs[config: Nanoc::Core::Configuration] => C::Any
@@ -36,7 +36,12 @@ module Nanoc
36
36
  textual_content_map.merge(binary_content_map)
37
37
  end
38
38
 
39
- contract Nanoc::Core::ItemRep, C::HashOf[Symbol => Nanoc::Core::Content] => C::Any
39
+ def include?(rep)
40
+ @textual_cache.include?(rep) || @binary_cache.include?(rep)
41
+ end
42
+
43
+ contract Nanoc::Core::ItemRep,
44
+ C::HashOf[Symbol => Nanoc::Core::Content] => C::Any
40
45
  # Sets the compiled content for the given representation.
41
46
  #
42
47
  # This cached compiled content is a hash where the keys are the snapshot
@@ -36,19 +36,24 @@ module Nanoc
36
36
  @contents[rep]
37
37
  end
38
38
 
39
- contract Nanoc::Core::ItemRep, C::HashOf[Symbol => Nanoc::Core::Content] => C::Any
39
+ contract Nanoc::Core::ItemRep,
40
+ C::HashOf[Symbol => Nanoc::Core::Content] =>
41
+ C::Any
40
42
  def set_all(rep, contents_per_snapshot)
41
43
  @contents[rep] = contents_per_snapshot
42
44
  end
43
45
 
44
- contract C::KeywordArgs[rep: Nanoc::Core::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => Nanoc::Core::Content
46
+ contract C::KeywordArgs[
47
+ rep: Nanoc::Core::ItemRep,
48
+ snapshot: C::Optional[C::Maybe[Symbol]]] => Nanoc::Core::Content
45
49
  def raw_compiled_content(rep:, snapshot: nil)
46
50
  # Get name of last pre-layout snapshot
47
51
  has_pre = rep.snapshot_defs.any? { |sd| sd.name == :pre }
48
52
  snapshot_name = snapshot || (has_pre ? :pre : :last)
49
53
 
50
54
  # Check existance of snapshot
51
- snapshot_def = rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
55
+ snapshot_def =
56
+ rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
52
57
  unless snapshot_def
53
58
  raise Nanoc::Core::Errors::NoSuchSnapshot.new(rep, snapshot_name)
54
59
  end
@@ -61,12 +66,15 @@ module Nanoc
61
66
  raise Nanoc::Core::Errors::UnmetDependency.new(rep, snapshot_name)
62
67
  end
63
68
 
64
- contract C::KeywordArgs[rep: Nanoc::Core::ItemRep, snapshot: C::Optional[C::Maybe[Symbol]]] => String
69
+ contract C::KeywordArgs[
70
+ rep: Nanoc::Core::ItemRep,
71
+ snapshot: C::Optional[C::Maybe[Symbol]]] => String
65
72
  def compiled_content(rep:, snapshot: nil)
66
73
  snapshot_content = raw_compiled_content(rep:, snapshot:)
67
74
 
68
75
  if snapshot_content.binary?
69
- raise Nanoc::Core::Errors::CannotGetCompiledContentOfBinaryItem.new(rep)
76
+ raise Nanoc::Core::Errors::CannotGetCompiledContentOfBinaryItem
77
+ .new(rep)
70
78
  end
71
79
 
72
80
  snapshot_content.string
@@ -15,7 +15,10 @@ module Nanoc
15
15
  Nanoc::Core::CompilerLoader.new.load(site, focus:)
16
16
  end
17
17
 
18
- def initialize(site, compiled_content_cache:, checksum_store:, action_sequence_store:, action_provider:, dependency_store:, outdatedness_store:, focus:)
18
+ def initialize(
19
+ site, compiled_content_cache:, checksum_store:, action_sequence_store:,
20
+ action_provider:, dependency_store:, outdatedness_store:, focus:
21
+ )
19
22
  @site = site
20
23
 
21
24
  # Needed because configuration is mutable :(
@@ -65,7 +68,10 @@ module Nanoc
65
68
  action_sequences:,
66
69
  reps:,
67
70
  )
68
- outdated_items = determine_outdatedness_stage(outdatedness_checker, reps).call
71
+ outdated_items = determine_outdatedness_stage(
72
+ outdatedness_checker,
73
+ reps,
74
+ ).call
69
75
 
70
76
  prev.merge(
71
77
  checksums:,
@@ -84,7 +90,10 @@ module Nanoc
84
90
  outdated_items = res.fetch(:outdated_items)
85
91
 
86
92
  forget_outdated_dependencies_stage.call(outdated_items)
87
- store_pre_compilation_state_stage(action_sequences, reps).call(checksums)
93
+ store_pre_compilation_state_stage(
94
+ action_sequences,
95
+ reps,
96
+ ).call(checksums)
88
97
  prune_stage(reps).call
89
98
  compile_reps_stage(action_sequences, reps).call
90
99
  store_post_compilation_state_stage.call
@@ -5,17 +5,26 @@ module Nanoc
5
5
  # @api private
6
6
  class CompilerLoader
7
7
  def load(site, focus: nil, action_provider: nil)
8
- action_sequence_store = Nanoc::Core::ActionSequenceStore.new(config: site.config)
8
+ action_sequence_store =
9
+ Nanoc::Core::ActionSequenceStore.new(config: site.config)
9
10
 
10
11
  dependency_store =
11
- Nanoc::Core::DependencyStore.new(site.items, site.layouts, site.config)
12
+ Nanoc::Core::DependencyStore.new(
13
+ site.items, site.layouts, site.config
14
+ )
12
15
 
13
- objects = site.items.to_a + site.layouts.to_a + site.code_snippets + [site.config]
16
+ objects = site.items.to_a +
17
+ site.layouts.to_a +
18
+ site.code_snippets +
19
+ [site.config]
14
20
 
15
21
  checksum_store =
16
22
  Nanoc::Core::ChecksumStore.new(config: site.config, objects:)
17
23
 
18
- action_provider ||= Nanoc::Core::ActionProvider.named(site.config.action_provider).for(site)
24
+ action_provider ||=
25
+ Nanoc::Core::ActionProvider
26
+ .named(site.config.action_provider)
27
+ .for(site)
19
28
 
20
29
  outdatedness_store =
21
30
  Nanoc::Core::OutdatednessStore.new(config: site.config)
@@ -18,7 +18,8 @@ module Nanoc
18
18
 
19
19
  class CyclicalConfigFileError < ::Nanoc::Core::Error
20
20
  def initialize(filename)
21
- super("The parent configuration file at #{filename} includes one of its descendants")
21
+ super("The parent configuration file at #{filename} includes one " \
22
+ 'of its descendants')
22
23
  end
23
24
  end
24
25
 
@@ -68,7 +69,10 @@ module Nanoc
68
69
  return config if parent_path.nil?
69
70
 
70
71
  # Get absolute path
71
- parent_path = File.absolute_path(parent_path, File.dirname(processed_paths.last))
72
+ parent_path = File.absolute_path(
73
+ parent_path,
74
+ File.dirname(processed_paths.last),
75
+ )
72
76
  unless File.file?(parent_path)
73
77
  raise NoParentConfigFileFoundError.new(parent_path)
74
78
  end
@@ -79,8 +83,14 @@ module Nanoc
79
83
  end
80
84
 
81
85
  # Load
82
- parent_config = Nanoc::Core::Configuration.new(hash: load_file(parent_path), dir: config.dir)
83
- full_parent_config = apply_parent_config(parent_config, processed_paths + [parent_path])
86
+ parent_config = Nanoc::Core::Configuration.new(
87
+ hash: load_file(parent_path),
88
+ dir: config.dir,
89
+ )
90
+ full_parent_config = apply_parent_config(
91
+ parent_config,
92
+ processed_paths + [parent_path],
93
+ )
84
94
  full_parent_config.merge(config.without(:parent_config_file))
85
95
  end
86
96
  end
@@ -17,13 +17,18 @@ module Nanoc
17
17
  }.freeze
18
18
 
19
19
  # The default configuration for a site. A site's configuration overrides
20
- # these options: when a {Nanoc::Core::Site} is created with a configuration
21
- # that lacks some options, the default value will be taken from
22
- # `DEFAULT_CONFIG`.
20
+ # these options: when a {Nanoc::Core::Site} is created with a
21
+ # configuration that lacks some options, the default value will be taken
22
+ # from `DEFAULT_CONFIG`.
23
23
  DEFAULT_CONFIG = {
24
- text_extensions: %w[adoc asciidoc atom css erb haml htm html js less markdown md org php rb sass scss tex txt xhtml xml coffee hb handlebars mustache ms slim rdoc].sort,
25
- lib_dirs: %w[lib],
26
- commands_dirs: %w[commands],
24
+ text_extensions: [
25
+ 'adoc', 'asciidoc', 'atom', 'css', 'erb', 'haml', 'htm', 'html', 'js',
26
+ 'less', 'markdown', 'md', 'org', 'php', 'rb', 'sass', 'scss', 'tex',
27
+ 'txt', 'xhtml', 'xml', 'coffee', 'hb', 'handlebars', 'mustache', 'ms',
28
+ 'slim', 'rdoc'
29
+ ].sort,
30
+ lib_dirs: ['lib'],
31
+ commands_dirs: ['commands'],
27
32
  output_dir: 'output',
28
33
  data_sources: [{}],
29
34
  index_filenames: ['index.html'],
@@ -44,7 +49,9 @@ module Nanoc
44
49
  NANOC_ENV = 'NANOC_ENV'
45
50
  NANOC_ENV_DEFAULT = 'default'
46
51
 
47
- contract C::KeywordArgs[hash: C::Optional[Hash], env_name: C::Maybe[String], dir: C::AbsolutePathString] => C::Any
52
+ contract C::KeywordArgs[
53
+ hash: C::Optional[Hash], env_name: C::Maybe[String],
54
+ dir: C::AbsolutePathString] => C::Any
48
55
  def initialize(dir:, hash: {}, env_name: nil)
49
56
  @env_name = env_name
50
57
  @wrapped = hash.__nanoc_symbolize_keys_recursively
@@ -70,7 +77,8 @@ module Nanoc
70
77
  env_name = @env_name || ENV.fetch(NANOC_ENV, NANOC_ENV_DEFAULT)
71
78
 
72
79
  # Load given environment configuration
73
- env_config = @wrapped[ENVIRONMENTS_CONFIG_KEY].fetch(env_name.to_sym, {})
80
+ env_config =
81
+ @wrapped[ENVIRONMENTS_CONFIG_KEY].fetch(env_name.to_sym, {})
74
82
 
75
83
  self.class.new(hash: @wrapped, dir: @dir, env_name:).merge(env_config)
76
84
  end
@@ -101,7 +109,9 @@ module Nanoc
101
109
  @wrapped.dig(*keys)
102
110
  end
103
111
 
104
- contract C::Any, C::Maybe[C::Any], C::Maybe[C::Func[C::None => C::Any]] => C::Any
112
+ contract C::Any,
113
+ C::Maybe[C::Any],
114
+ C::Maybe[C::Func[C::None => C::Any]] => C::Any
105
115
  def fetch(key, fallback = Nanoc::Core::UNDEFINED, &)
106
116
  @wrapped.fetch(key) do
107
117
  if !Nanoc::Core::UNDEFINED.equal?(fallback)
@@ -121,12 +131,20 @@ module Nanoc
121
131
 
122
132
  contract C::Or[Hash, self] => self
123
133
  def merge(hash)
124
- self.class.new(hash: merge_recursively(@wrapped, hash.to_h), dir: @dir, env_name: @env_name)
134
+ self.class.new(
135
+ hash: merge_recursively(@wrapped, hash.to_h),
136
+ dir: @dir,
137
+ env_name: @env_name,
138
+ )
125
139
  end
126
140
 
127
141
  contract C::Any => self
128
142
  def without(key)
129
- self.class.new(hash: @wrapped.reject { |k, _v| k == key }, dir: @dir, env_name: @env_name)
143
+ self.class.new(
144
+ hash: @wrapped.reject { |k, _v| k == key },
145
+ dir: @dir,
146
+ env_name: @env_name,
147
+ )
130
148
  end
131
149
 
132
150
  contract C::Any => self
@@ -161,7 +179,8 @@ module Nanoc
161
179
  contract C::None => C::IterOf[C::AbsolutePathString]
162
180
  def output_dirs
163
181
  envs = @wrapped.fetch(ENVIRONMENTS_CONFIG_KEY, {})
164
- res = [output_dir] + envs.values.map { |v| make_absolute(v[:output_dir]) }
182
+ res = [output_dir] +
183
+ envs.values.map { |v| make_absolute(v[:output_dir]) }
165
184
  res.uniq.compact
166
185
  end
167
186
 
@@ -169,7 +188,7 @@ module Nanoc
169
188
  #
170
189
  # @return [Object] An unique reference to this object
171
190
  def reference
172
- 'configuration'
191
+ :configuration
173
192
  end
174
193
 
175
194
  def inspect
@@ -188,7 +207,9 @@ module Nanoc
188
207
 
189
208
  contract C::Any => C::Bool
190
209
  def eql?(other)
191
- other.is_a?(self.class) && @dir == other.dir && @env_name == other.env_name
210
+ other.is_a?(self.class) &&
211
+ @dir == other.dir &&
212
+ @env_name == other.env_name
192
213
  end
193
214
 
194
215
  private
@@ -209,7 +230,7 @@ module Nanoc
209
230
 
210
231
  def validate
211
232
  dir = File.dirname(__FILE__)
212
- schema_data = JSON.parse(File.read(dir + '/configuration-schema.json'))
233
+ schema_data = JSON.parse(File.read("#{dir}/configuration-schema.json"))
213
234
  schema = JsonSchema.parse!(schema_data)
214
235
  schema.expand_references!
215
236
  schema.validate!(@wrapped.__nanoc_stringify_keys_recursively)
@@ -5,7 +5,11 @@ module Nanoc
5
5
  class Content
6
6
  include Nanoc::Core::ContractsSupport
7
7
 
8
- contract C::Or[self, String, Proc], C::KeywordArgs[binary: C::Optional[C::Bool], filename: C::Optional[C::Maybe[String]]] => self
8
+ contract C::Or[self, String, Proc],
9
+ C::KeywordArgs[
10
+ binary: C::Optional[C::Bool],
11
+ filename: C::Optional[C::Maybe[String]],
12
+ ] => self
9
13
  def self.create(content, binary: false, filename: nil)
10
14
  if content.nil?
11
15
  raise ArgumentError, 'Cannot create nil content'
@@ -26,21 +26,20 @@ module Nanoc
26
26
  # # => "I am Max Payne and I am hiding in a cheap motel."
27
27
  def initialize(hash)
28
28
  hash.each_pair do |key, value|
29
- instance_variable_set('@' + key.to_s, value)
29
+ instance_variable_set("@#{key}", value)
30
30
  end
31
31
  end
32
32
 
33
33
  # Returns a binding for this instance.
34
34
  #
35
35
  # @return [Binding] A binding for this instance
36
- # rubocop:disable Naming/AccessorMethodName
36
+ # rubocop:disable-next Naming/AccessorMethodName
37
37
  def get_binding
38
38
  binding
39
39
  end
40
- # rubocop:enable Naming/AccessorMethodName
41
40
 
42
41
  def method_missing(method, *args, &)
43
- ivar_name = '@' + method.to_s
42
+ ivar_name = "@#{method}"
44
43
  if instance_variable_defined?(ivar_name)
45
44
  instance_variable_get(ivar_name)
46
45
  else
@@ -49,7 +48,7 @@ module Nanoc
49
48
  end
50
49
 
51
50
  def respond_to_missing?(method, include_all)
52
- ivar_name = '@' + method.to_s
51
+ ivar_name = "@#{method}"
53
52
 
54
53
  valid_ivar_name =
55
54
  if defined?(Contracts)