nanoc-core 4.11.11 → 4.11.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d054faa7611049b1815255844cb5514e8225684890551acec517db27512ade1
4
- data.tar.gz: e0e17509d2745fec12f7ecfb04abf863ad0713f7171c272c99bb84a4e0aa8474
3
+ metadata.gz: bf201905e79de9d9711910668d228863a48b53e13a78694a50122932960d6189
4
+ data.tar.gz: ffae70af266ec5c189b0d09976bfb9ebada587f5ea1eeb73b12dfeaebeb07d36
5
5
  SHA512:
6
- metadata.gz: 1c378a5a778cdcec8cdda0fefe6e9fc94ab1c72a843ffc9c7da05f7bb85cc5f8592cd6a84f554ea74695903f51d821edde5621ee9b28e7ed581ae6009cf4ea6c
7
- data.tar.gz: 87c8ec712d58e5b1c3c8206011f5177a71865df1abeff9985659968dc96fbe6a4e4235c8de66de843c5b4e23dc94564969cde11826968936206700889baa9b45
6
+ metadata.gz: bf812e2fc282b019b2d907ee39a84fe7999b2b2f8565139cc442e3ca38cb75949ea70f27b07058ef4bd52af9a1291c0ca73e6db53790e431976a729f6a4dd3c8
7
+ data.tar.gz: ef670404975dfde21013d6878afbf272e7bd41d7dee120e124cb2c61e37e1ad1f5ac64ccc1f4554f57dcde1d1303cac32ef6e088853d569c24f1c070c72abc7c
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ class CompilationContext
6
+ class FilterNameAndArgs
7
+ include Nanoc::Core::ContractsSupport
8
+
9
+ attr_reader :name
10
+ attr_reader :args
11
+
12
+ contract C::KeywordArgs[name: C::Maybe[Symbol], args: Hash] => C::Any
13
+ def initialize(name:, args:)
14
+ @name = name
15
+ @args = args
16
+ end
17
+ end
18
+
19
+ class UndefinedFilterForLayoutError < ::Nanoc::Core::Error
20
+ def initialize(layout)
21
+ super("There is no filter defined for the layout #{layout.identifier}")
22
+ end
23
+ end
24
+
25
+ include Nanoc::Core::ContractsSupport
26
+
27
+ attr_reader :site
28
+ attr_reader :reps
29
+ attr_reader :compiled_content_cache
30
+ attr_reader :compiled_content_store
31
+
32
+ C_COMPILED_CONTENT_CACHE =
33
+ C::Or[
34
+ Nanoc::Core::CompiledContentCache,
35
+ Nanoc::Core::TextualCompiledContentCache,
36
+ Nanoc::Core::BinaryCompiledContentCache,
37
+ ]
38
+
39
+ contract C::KeywordArgs[
40
+ action_provider: Nanoc::Core::ActionProvider,
41
+ reps: Nanoc::Core::ItemRepRepo,
42
+ site: Nanoc::Core::Site,
43
+ compiled_content_cache: C_COMPILED_CONTENT_CACHE,
44
+ compiled_content_store: Nanoc::Core::CompiledContentStore,
45
+ ] => C::Any
46
+ def initialize(action_provider:, reps:, site:, compiled_content_cache:, compiled_content_store:)
47
+ @action_provider = action_provider
48
+ @reps = reps
49
+ @site = site
50
+ @compiled_content_cache = compiled_content_cache
51
+ @compiled_content_store = compiled_content_store
52
+ end
53
+
54
+ contract Nanoc::Core::Layout => FilterNameAndArgs
55
+ def filter_name_and_args_for_layout(layout)
56
+ seq = @action_provider.action_sequence_for(layout)
57
+ if seq.nil? || seq.size != 1 || !seq[0].is_a?(Nanoc::Core::ProcessingActions::Filter)
58
+ raise UndefinedFilterForLayoutError.new(layout)
59
+ end
60
+
61
+ FilterNameAndArgs.new(name: seq[0].filter_name, args: seq[0].params)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -6,10 +6,33 @@ module Nanoc
6
6
  class DependencyTracker
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
- C_OBJ = C::Or[Nanoc::Core::Item, Nanoc::Core::Layout, Nanoc::Core::Configuration, Nanoc::Core::IdentifiableCollection]
10
- C_RAW_CONTENT = C::Or[C::IterOf[C::Or[String, Regexp]], C::Bool]
11
- C_ATTR = C::Or[C::IterOf[Symbol], C::Bool]
12
- C_ARGS = C::KeywordArgs[raw_content: C::Optional[C_RAW_CONTENT], attributes: C::Optional[C_ATTR], compiled_content: C::Optional[C::Bool], path: C::Optional[C::Bool]]
9
+ C_OBJ =
10
+ C::Or[
11
+ Nanoc::Core::Item,
12
+ Nanoc::Core::Layout,
13
+ Nanoc::Core::Configuration,
14
+ Nanoc::Core::IdentifiableCollection
15
+ ]
16
+
17
+ C_RAW_CONTENT =
18
+ C::Or[
19
+ C::IterOf[C::Or[String, Regexp]],
20
+ C::Bool
21
+ ]
22
+
23
+ C_ATTR =
24
+ C::Or[
25
+ C::IterOf[Symbol],
26
+ C::Bool
27
+ ]
28
+
29
+ C_ARGS =
30
+ C::KeywordArgs[
31
+ raw_content: C::Optional[C_RAW_CONTENT],
32
+ attributes: C::Optional[C_ATTR],
33
+ compiled_content: C::Optional[C::Bool],
34
+ path: C::Optional[C::Bool]
35
+ ]
13
36
 
14
37
  attr_reader :dependency_store
15
38
 
@@ -3,9 +3,12 @@
3
3
  module Nanoc
4
4
  module Core
5
5
  class InMemoryDataSource < Nanoc::Core::DataSource
6
+ include Nanoc::Core::ContractsSupport
7
+
6
8
  attr_reader :items
7
9
  attr_reader :layouts
8
10
 
11
+ contract Nanoc::Core::ItemCollection, Nanoc::Core::LayoutCollection, C::Maybe[Nanoc::Core::DataSource] => C::Any
9
12
  def initialize(items, layouts, orig_data_source = nil)
10
13
  super({}, '/', '/', {})
11
14
 
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ # Assigns paths to reps.
6
+ #
7
+ # @api private
8
+ class ItemRepRouter
9
+ include Nanoc::Core::ContractsSupport
10
+
11
+ class IdenticalRoutesError < ::Nanoc::Core::Error
12
+ def initialize(output_path, rep_a, rep_b)
13
+ super("The item representations #{rep_a} and #{rep_b} are both routed to #{output_path}.")
14
+ end
15
+ end
16
+
17
+ class RouteWithoutSlashError < ::Nanoc::Core::Error
18
+ def initialize(output_path, rep)
19
+ super("The item representation #{rep} is routed to #{output_path}, which does not start with a slash, as required.")
20
+ end
21
+ end
22
+
23
+ contract Nanoc::Core::ItemRepRepo, Nanoc::Core::ActionProvider, Nanoc::Core::Site => C::Any
24
+ def initialize(reps, action_provider, site)
25
+ @reps = reps
26
+ @action_provider = action_provider
27
+ @site = site
28
+ end
29
+
30
+ def run
31
+ action_sequences = {}
32
+ assigned_paths = {}
33
+ @reps.each do |rep|
34
+ # Sigh. We route reps twice, because the first time, the paths might not have converged
35
+ # yet. This isn’t ideal, but it’s the only way to work around the divergence issues that
36
+ # I can think of. For details, see
37
+ # https://github.com/nanoc/nanoc/pull/1085#issuecomment-280628426.
38
+
39
+ @action_provider.action_sequence_for(rep).paths.each do |(snapshot_names, paths)|
40
+ route_rep(rep, paths, snapshot_names, {})
41
+ end
42
+
43
+ seq = @action_provider.action_sequence_for(rep)
44
+ action_sequences[rep] = seq
45
+ seq.paths.each do |(snapshot_names, paths)|
46
+ route_rep(rep, paths, snapshot_names, assigned_paths)
47
+ end
48
+
49
+ # TODO: verify that paths converge
50
+ end
51
+
52
+ action_sequences
53
+ end
54
+
55
+ contract Nanoc::Core::ItemRep, C::IterOf[String], C::IterOf[Symbol], C::HashOf[String => Nanoc::Core::ItemRep] => C::Any
56
+ def route_rep(rep, paths, snapshot_names, assigned_paths)
57
+ # Encode
58
+ paths = paths.map { |path| path.encode('UTF-8') }
59
+
60
+ # Validate format
61
+ paths.each do |path|
62
+ unless path.start_with?('/')
63
+ raise RouteWithoutSlashError.new(path, rep)
64
+ end
65
+ end
66
+
67
+ # Validate uniqueness
68
+ paths.each do |path|
69
+ if assigned_paths.include?(path)
70
+ # TODO: Include snapshot names in error message
71
+ reps = [assigned_paths[path], rep].sort_by { |r| [r.item.identifier, r.name] }
72
+ raise IdenticalRoutesError.new(path, *reps)
73
+ end
74
+ end
75
+ paths.each do |path|
76
+ assigned_paths[path] = rep
77
+ end
78
+
79
+ # Assign
80
+ snapshot_names.each do |snapshot_name|
81
+ rep.raw_paths[snapshot_name] = paths.map { |path| @site.config.output_dir + path }
82
+ rep.paths[snapshot_name] = paths.map { |path| strip_index_filename(path) }
83
+ end
84
+ end
85
+
86
+ contract String => String
87
+ def strip_index_filename(basic_path)
88
+ @site.config[:index_filenames].each do |index_filename|
89
+ slashed_index_filename = '/' + index_filename
90
+ if basic_path.end_with?(slashed_index_filename)
91
+ return basic_path[0..-index_filename.length - 1]
92
+ end
93
+ end
94
+
95
+ basic_path
96
+ end
97
+ end
98
+ end
99
+ end
@@ -4,6 +4,8 @@ module Nanoc
4
4
  module Core
5
5
  module ProcessingActions
6
6
  class Filter < Nanoc::Core::ProcessingAction
7
+ # TODO: rename params to args
8
+
7
9
  # filter :foo
8
10
  # filter :foo, params
9
11
 
@@ -49,6 +49,7 @@ module Nanoc
49
49
  )
50
50
  end
51
51
 
52
+ contract String => String
52
53
  def self.tmp_path_prefix(output_dir)
53
54
  dir = Digest::SHA1.hexdigest(output_dir)[0..12]
54
55
  File.join('tmp', 'nanoc', dir)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- VERSION = '4.11.11'
5
+ VERSION = '4.11.12'
6
6
  end
7
7
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ class ViewContextForCompilation
6
+ include Nanoc::Core::ContractsSupport
7
+
8
+ attr_reader :reps
9
+ attr_reader :items
10
+ attr_reader :dependency_tracker
11
+ attr_reader :compilation_context
12
+ attr_reader :compiled_content_store
13
+
14
+ contract C::KeywordArgs[
15
+ reps: Nanoc::Core::ItemRepRepo,
16
+ items: Nanoc::Core::IdentifiableCollection,
17
+ dependency_tracker: Nanoc::Core::DependencyTracker,
18
+ compilation_context: Nanoc::Core::CompilationContext,
19
+ compiled_content_store: Nanoc::Core::CompiledContentStore,
20
+ ] => C::Any
21
+ def initialize(reps:, items:, dependency_tracker:, compilation_context:, compiled_content_store:)
22
+ @reps = reps
23
+ @items = items
24
+ @dependency_tracker = dependency_tracker
25
+ @compilation_context = compilation_context
26
+ @compiled_content_store = compiled_content_store
27
+ end
28
+
29
+ contract Nanoc::Core::ItemRep, C::KeywordArgs[site: Nanoc::Core::Site] => Hash
30
+ def assigns_for(rep, site:)
31
+ last_content = @compiled_content_store.get_current(rep)
32
+ content_or_filename_assigns =
33
+ if last_content.binary?
34
+ { filename: last_content.filename }
35
+ else
36
+ { content: last_content.string }
37
+ end
38
+
39
+ content_or_filename_assigns.merge(
40
+ item: Nanoc::CompilationItemView.new(rep.item, self),
41
+ rep: Nanoc::CompilationItemRepView.new(rep, self),
42
+ item_rep: Nanoc::CompilationItemRepView.new(rep, self),
43
+ items: Nanoc::ItemCollectionWithRepsView.new(site.items, self),
44
+ layouts: Nanoc::LayoutCollectionView.new(site.layouts, self),
45
+ config: Nanoc::ConfigView.new(site.config, self),
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ class ViewContextForPreCompilation
6
+ include Nanoc::Core::ContractsSupport
7
+
8
+ attr_reader :items
9
+ attr_reader :dependency_tracker
10
+
11
+ contract C::KeywordArgs[items: Nanoc::Core::IdentifiableCollection] => C::Any
12
+ def initialize(items:)
13
+ @items = items
14
+
15
+ @dependency_tracker = Nanoc::Core::DependencyTracker::Null.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ class ViewContextForShell
6
+ include Nanoc::Core::ContractsSupport
7
+
8
+ attr_reader :items
9
+ attr_reader :reps
10
+ attr_reader :dependency_tracker
11
+
12
+ contract C::KeywordArgs[
13
+ items: Nanoc::Core::IdentifiableCollection,
14
+ reps: Nanoc::Core::ItemRepRepo,
15
+ ] => C::Any
16
+ def initialize(items:, reps:)
17
+ @items = items
18
+ @reps = reps
19
+
20
+ @dependency_tracker = Nanoc::Core::DependencyTracker::Null.new
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.11
4
+ version: 4.11.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-07 00:00:00.000000000 Z
11
+ date: 2019-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ddmemoize
@@ -130,6 +130,7 @@ files:
130
130
  - lib/nanoc/core/checksum_store.rb
131
131
  - lib/nanoc/core/checksummer.rb
132
132
  - lib/nanoc/core/code_snippet.rb
133
+ - lib/nanoc/core/compilation_context.rb
133
134
  - lib/nanoc/core/compilation_stage.rb
134
135
  - lib/nanoc/core/compiled_content_cache.rb
135
136
  - lib/nanoc/core/compiled_content_store.rb
@@ -158,6 +159,7 @@ files:
158
159
  - lib/nanoc/core/item_collection.rb
159
160
  - lib/nanoc/core/item_rep.rb
160
161
  - lib/nanoc/core/item_rep_repo.rb
162
+ - lib/nanoc/core/item_rep_router.rb
161
163
  - lib/nanoc/core/layout.rb
162
164
  - lib/nanoc/core/layout_collection.rb
163
165
  - lib/nanoc/core/lazy_value.rb
@@ -182,6 +184,9 @@ files:
182
184
  - lib/nanoc/core/textual_compiled_content_cache.rb
183
185
  - lib/nanoc/core/textual_content.rb
184
186
  - lib/nanoc/core/version.rb
187
+ - lib/nanoc/core/view_context_for_compilation.rb
188
+ - lib/nanoc/core/view_context_for_pre_compilation.rb
189
+ - lib/nanoc/core/view_context_for_shell.rb
185
190
  homepage: https://nanoc.ws/
186
191
  licenses:
187
192
  - MIT