nanoc 4.10.0 → 4.11.0

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: 046c9869b2f916776a4f0fe741916842cbbc68b584e11b606abac58b854a9f44
4
- data.tar.gz: aeb902ad7fca66c89b63d46e2e9e8508c08e1cc3cdeb8dcbf0c45698d8c6a905
3
+ metadata.gz: 24b2704181c12e6dc71bf46b7bb87dc14e31c18d7d4530a0420dd2c98ffb3e9b
4
+ data.tar.gz: 913ca912414ce823d274704ba45e06ace2a4e603081472a6815fe0b9076dd1b2
5
5
  SHA512:
6
- metadata.gz: 93124b5f9eab590c046853ef39aa1c58516a365f2f721e7f1de73a34c0c4916ea1c3331a6c5db5e218e5921b0ef77abb5b50f5caf832d832eb0cc328133d58a8
7
- data.tar.gz: f3c544d01d70da7ac4379311208fd57932ba26ca157b039fdda05d4c96f8c7f6fbe93a45376ad4bf4e2cf3c10e5c2e9a6157a8b729dd58006a675b9ffc3a48ce
6
+ metadata.gz: cb662339340e2682df52518b85d5295bab537b18014a9fcd001f65fe31cb62aae1ab9bccca0c877ba196025a1e839ac6cd6fd26538e4df00b6b250a06dff7b61
7
+ data.tar.gz: d1b82c96c958141bdeb7d82511fd06d4a9499c251f6b656e300ea9120041377fcfde2c6562758c733e0d5e4eef593ba36fff5b3d16d4f719cc81f451014e2edb
data/NEWS.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.11.0 (2018-12-01)
4
+
5
+ Features:
6
+
7
+ * Added support for generating inline source maps for Sass (#1376) [Gregory Pakosz]
8
+ * Added `:tiebreaker` option to the breadcrumbs helper, so that it can deal with ambiguity (#1368)
9
+
10
+ ## 4.10.4 (2018-12-01)
11
+
12
+ Fixes:
13
+
14
+ * Fixed an error when importing a Sass/SCSS file outside of Nanoc’s content directory (#1378, #1379)
15
+
16
+ ## 4.10.3 (2018-10-28)
17
+
18
+ Fixes:
19
+
20
+ * Fixed an issue which could cause `write nil` to still invoke the routing rule (#1374, #1375)
21
+
22
+ ## 4.10.2 (2018-10-21)
23
+
24
+ Fixes:
25
+
26
+ * Fixed an issue where changing a layout rule’s parameters would not recompile items that use the layout for this layout rule (#1372, #1373)
27
+
28
+ ## 4.10.1 (2018-10-16)
29
+
30
+ Fixes:
31
+
32
+ * Made Nanoc no longer crash when the Sass gem is not available (#1371)
33
+
3
34
  ## 4.10.0 (2018-10-14)
4
35
 
5
36
  Features:
@@ -970,11 +1001,11 @@ Enhancements:
970
1001
 
971
1002
  * Added several convenience methods to view classes (#570, #572)
972
1003
 
973
- See the [nanoc 4 upgrade guide](http://nanoc.ws/docs/nanoc-4-upgrade-guide/) for details.
1004
+ See the [nanoc 4 upgrade guide](http://nanoc.ws/doc/nanoc-4-upgrade-guide/) for details.
974
1005
 
975
1006
  ## 4.0.0a1 (2015-05-09)
976
1007
 
977
- This is a major upgrade. For details on upgrading, see the [nanoc 4 upgrade guide](http://nanoc.ws/docs/nanoc-4-upgrade-guide/).
1008
+ This is a major upgrade. For details on upgrading, see the [nanoc 4 upgrade guide](http://nanoc.ws/doc/nanoc-4-upgrade-guide/).
978
1009
 
979
1010
  This release provides no new features, but streamlines the API and functionality, in order to easen future development, both for features and for optimisations.
980
1011
 
@@ -23,7 +23,7 @@ module Nanoc::Int::ProcessingActions
23
23
 
24
24
  contract C::KeywordArgs[snapshot_names: C::Optional[C::IterOf[Symbol]], paths: C::Optional[C::IterOf[String]]] => self
25
25
  def update(snapshot_names: [], paths: [])
26
- self.class.new(@snapshot_names + snapshot_names, @paths + paths)
26
+ self.class.new(@snapshot_names + snapshot_names.to_a, @paths + paths.to_a)
27
27
  end
28
28
 
29
29
  contract C::None => String
@@ -93,8 +93,8 @@ end
93
93
 
94
94
  # Tracking issue:
95
95
  # https://github.com/nanoc/features/issues/24
96
- Nanoc::Feature.define('live_cmd', version: '4.10')
96
+ Nanoc::Feature.define('live_cmd', version: '4.11')
97
97
 
98
98
  # Tracking issue:
99
99
  # https://github.com/nanoc/features/issues/40
100
- Nanoc::Feature.define('toml', version: '4.10')
100
+ Nanoc::Feature.define('toml', version: '4.11')
@@ -77,7 +77,7 @@ module Nanoc::Int
77
77
  end
78
78
  end
79
79
 
80
- ENCODING_REGEX = /\A#\s+(-\*-\s+)?(en)?coding: (?<encoding>[^\s]+)(\s+-\*-\s*)?\n{0,2}/
80
+ ENCODING_REGEX = /\A#\s+(-\*-\s+)?(en)?coding: (?<encoding>[^\s]+)(\s+-\*-\s*)?\n{0,2}/.freeze
81
81
 
82
82
  def encoding_from_magic_comment(raw)
83
83
  match = ENCODING_REGEX.match(raw)
@@ -5,11 +5,37 @@ module Nanoc::Int::OutdatednessRules
5
5
  affects_props :compiled_content, :path
6
6
 
7
7
  def apply(obj, outdatedness_checker)
8
+ # Check rules of obj itself
9
+ if rules_modified?(obj, outdatedness_checker)
10
+ return Nanoc::Int::OutdatednessReasons::RulesModified
11
+ end
12
+
13
+ # Check rules of layouts used by obj
14
+ layouts = layouts_touched_by(obj, outdatedness_checker)
15
+ if layouts.any? { |layout| rules_modified?(layout, outdatedness_checker) }
16
+ return Nanoc::Int::OutdatednessReasons::RulesModified
17
+ end
18
+
19
+ nil
20
+ end
21
+
22
+ private
23
+
24
+ def rules_modified?(obj, outdatedness_checker)
8
25
  seq_old = outdatedness_checker.action_sequence_store[obj]
9
26
  seq_new = outdatedness_checker.action_sequence_for(obj).serialize
10
- unless seq_old.eql?(seq_new)
11
- Nanoc::Int::OutdatednessReasons::RulesModified
12
- end
27
+
28
+ !seq_old.eql?(seq_new)
29
+ end
30
+
31
+ def layouts_touched_by(obj, outdatedness_checker)
32
+ actions = outdatedness_checker.action_sequence_store[obj]
33
+ layout_actions = actions.select { |a| a.first == :layout }
34
+
35
+ layout_actions.map do |layout_action|
36
+ layout_pattern = layout_action[1]
37
+ outdatedness_checker.site.layouts[layout_pattern]
38
+ end.compact
13
39
  end
14
40
  end
15
41
  end
@@ -8,7 +8,7 @@ module Nanoc::Checking::Checks
8
8
  class MixedContent < ::Nanoc::Checking::Check
9
9
  identifier :mixed_content
10
10
 
11
- PROTOCOL_PATTERN = /^(\w+):\/\//
11
+ PROTOCOL_PATTERN = /^(\w+):\/\//.freeze
12
12
 
13
13
  def run
14
14
  filenames = output_html_filenames
@@ -75,8 +75,8 @@ module Nanoc::CLI::Commands
75
75
  ].freeze
76
76
 
77
77
  PLUGIN_CLASSES = {
78
- Nanoc::Filter => 'Filters',
79
- Nanoc::DataSource => 'Data Sources',
78
+ Nanoc::Filter => 'Filters',
79
+ Nanoc::DataSource => 'Data Sources',
80
80
  Nanoc::Deploying::Deployer => 'Deployers',
81
81
  }.freeze
82
82
 
@@ -180,45 +180,45 @@ module Nanoc::CLI
180
180
  # A hash that contains the name of the gem for a given required file. If a
181
181
  # `#require` fails, the gem name is looked up in this hash.
182
182
  GEM_NAMES = {
183
- 'adsf' => 'adsf',
184
- 'asciidoctor' => 'asciidoctor',
185
- 'bluecloth' => 'bluecloth',
186
- 'builder' => 'builder',
187
- 'coderay' => 'coderay',
188
- 'coffee-script' => 'coffee-script',
189
- 'cri' => 'cri',
190
- 'erubi' => 'erubi',
191
- 'erubis' => 'erubis',
192
- 'escape' => 'escape',
193
- 'fog' => 'fog',
194
- 'haml' => 'haml',
195
- 'handlebars' => 'hbs',
196
- 'json' => 'json',
197
- 'kramdown' => 'kramdown',
198
- 'less' => 'less',
199
- 'listen' => 'listen',
200
- 'markaby' => 'markaby',
201
- 'maruku' => 'maruku',
202
- 'mime/types' => 'mime-types',
203
- 'mustache' => 'mustache',
204
- 'nanoc/live' => 'nanoc-live',
205
- 'nokogiri' => 'nokogiri',
206
- 'nokogumbo' => 'nokogumbo',
207
- 'pandoc-ruby' => 'pandoc-ruby',
208
- 'pry' => 'pry',
209
- 'rack' => 'rack',
210
- 'rack/cache' => 'rack-cache',
211
- 'rainpress' => 'rainpress',
212
- 'rdiscount' => 'rdiscount',
213
- 'redcarpet' => 'redcarpet',
214
- 'redcloth' => 'RedCloth',
215
- 'rubypants' => 'rubypants',
216
- 'sass' => 'sass',
217
- 'slim' => 'slim',
218
- 'typogruby' => 'typogruby',
219
- 'uglifier' => 'uglifier',
183
+ 'adsf' => 'adsf',
184
+ 'asciidoctor' => 'asciidoctor',
185
+ 'bluecloth' => 'bluecloth',
186
+ 'builder' => 'builder',
187
+ 'coderay' => 'coderay',
188
+ 'coffee-script' => 'coffee-script',
189
+ 'cri' => 'cri',
190
+ 'erubi' => 'erubi',
191
+ 'erubis' => 'erubis',
192
+ 'escape' => 'escape',
193
+ 'fog' => 'fog',
194
+ 'haml' => 'haml',
195
+ 'handlebars' => 'hbs',
196
+ 'json' => 'json',
197
+ 'kramdown' => 'kramdown',
198
+ 'less' => 'less',
199
+ 'listen' => 'listen',
200
+ 'markaby' => 'markaby',
201
+ 'maruku' => 'maruku',
202
+ 'mime/types' => 'mime-types',
203
+ 'mustache' => 'mustache',
204
+ 'nanoc/live' => 'nanoc-live',
205
+ 'nokogiri' => 'nokogiri',
206
+ 'nokogumbo' => 'nokogumbo',
207
+ 'pandoc-ruby' => 'pandoc-ruby',
208
+ 'pry' => 'pry',
209
+ 'rack' => 'rack',
210
+ 'rack/cache' => 'rack-cache',
211
+ 'rainpress' => 'rainpress',
212
+ 'rdiscount' => 'rdiscount',
213
+ 'redcarpet' => 'redcarpet',
214
+ 'redcloth' => 'RedCloth',
215
+ 'rubypants' => 'rubypants',
216
+ 'sass' => 'sass',
217
+ 'slim' => 'slim',
218
+ 'typogruby' => 'typogruby',
219
+ 'uglifier' => 'uglifier',
220
220
  'w3c_validators' => 'w3c_validators',
221
- 'yuicompressor' => 'yuicompressor',
221
+ 'yuicompressor' => 'yuicompressor',
222
222
  }.freeze
223
223
 
224
224
  # Attempts to find a resolution for the given error, or nil if no
@@ -4,7 +4,7 @@ module Nanoc::CLI
4
4
  # @api private
5
5
  module Transform
6
6
  module Port
7
- RANGE = 0x0001..0xffff
7
+ RANGE = (0x0001..0xffff).freeze
8
8
 
9
9
  def self.call(data)
10
10
  Integer(data).tap do |int|
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::Sass::Script::Functions
4
+ def nanoc(string, params)
5
+ assert_type string, :String
6
+ assert_type params, :Hash
7
+ result = options[:importer].filter.instance_eval(string.value)
8
+ case result
9
+ when TrueClass, FalseClass
10
+ bool(result)
11
+ when Array
12
+ list(result, :comma)
13
+ when Hash
14
+ map(result)
15
+ when nil
16
+ null
17
+ when Numeric
18
+ number(result)
19
+ else
20
+ params['unquote'] ? unquoted_string(result) : quoted_string(result)
21
+ end
22
+ end
23
+ declare :nanoc, [:string], var_kwargs: true
24
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc::Filters::SassCommon
4
+ # @api private
5
+ class Importer < ::Sass::Importers::Filesystem
6
+ attr_reader :filter
7
+
8
+ def initialize(filter)
9
+ @filter = filter
10
+ super('.')
11
+ end
12
+
13
+ def find_relative(name, base_identifier, options)
14
+ base_raw_filename = filter.items[base_identifier].raw_filename
15
+
16
+ # we can't resolve a relative filename from an in-memory item
17
+ return unless base_raw_filename
18
+
19
+ raw_filename, syntax = ::Sass::Util.destructure(find_real_file(File.dirname(base_raw_filename), name, options))
20
+ return unless raw_filename
21
+
22
+ item = raw_filename_to_item(raw_filename)
23
+
24
+ content = item ? item.raw_content : File.read(raw_filename)
25
+ filename = item ? item.identifier.to_s : raw_filename
26
+
27
+ filter.depend_on([item]) if item
28
+
29
+ options[:syntax] = syntax
30
+ options[:filename] = filename
31
+ options[:importer] = self
32
+ ::Sass::Engine.new(content, options)
33
+ end
34
+
35
+ def find(identifier, options)
36
+ items = filter.items.find_all(identifier)
37
+ return if items.empty?
38
+
39
+ content = if items.size == 1
40
+ items.first.compiled_content
41
+ else
42
+ items.map { |item| %(@import "#{item.identifier}";) }.join("\n")
43
+ end
44
+
45
+ options[:syntax] = :scss
46
+ options[:filename] = identifier.to_s
47
+ options[:importer] = self
48
+ ::Sass::Engine.new(content, options)
49
+ end
50
+
51
+ def key(identifier, _options)
52
+ [self.class.name + ':' + root, identifier.to_s]
53
+ end
54
+
55
+ def public_url(identifier, _sourcemap_directory)
56
+ path = filter.items[identifier].path
57
+ return path unless path.nil?
58
+
59
+ raw_filename = filter.items[identifier].raw_filename
60
+ return if raw_filename.nil?
61
+
62
+ ::Sass::Util.file_uri_from_path(raw_filename)
63
+ end
64
+
65
+ def to_s
66
+ 'Nanoc Sass Importer'
67
+ end
68
+
69
+ def self.raw_filename_to_item_map_for_config(config, items)
70
+ @raw_filename_to_item_map ||= {}
71
+ @raw_filename_to_item_map[config.object_id] ||=
72
+ {}.tap do |map|
73
+ items.each do |item|
74
+ if item.raw_filename
75
+ path = Pathname.new(item.raw_filename).realpath.to_s
76
+ map[path] = item
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ def raw_filename_to_item(filename)
83
+ realpath = Pathname.new(filename).realpath.to_s
84
+
85
+ map = self.class.raw_filename_to_item_map_for_config(filter.config, filter.items)
86
+ map[realpath]
87
+ end
88
+ end
89
+ end
@@ -1,19 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nanoc::Filters
4
- Nanoc::Filter.define(:sass) do |content, params = {}|
5
- include Sass
6
- css(self, @item_rep, content, params)
7
- end
8
-
9
- Nanoc::Filter.define(:sass_sourcemap) do |content, params = {}|
10
- include Sass
11
- sourcemap(self, @item_rep, content, params)
12
- end
4
+ module SassCommon
5
+ REQUIRES = %w[sass nanoc/filters/sass/importer nanoc/filters/sass/functions].freeze
13
6
 
14
- require 'sass'
15
-
16
- module Sass
17
7
  def css(filter, rep, content, params)
18
8
  css, = render(filter, rep, content, params)
19
9
  css
@@ -27,7 +17,7 @@ module Nanoc::Filters
27
17
  private
28
18
 
29
19
  def render(filter, rep, content, params = {})
30
- importer = NanocSassImporter.new(filter)
20
+ importer = Nanoc::Filters::SassCommon::Importer.new(filter)
31
21
 
32
22
  options = params.merge(
33
23
  load_paths: [importer, *params[:load_paths]&.reject { |p| p.is_a?(String) && %r{^content/} =~ p }],
@@ -35,119 +25,47 @@ module Nanoc::Filters
35
25
  filename: rep.item.identifier.to_s,
36
26
  cache: false,
37
27
  )
28
+ css_path = options.delete(:css_path) || filter.object_id.to_s
38
29
  sourcemap_path = options.delete(:sourcemap_path)
30
+ if sourcemap_path == :inline
31
+ sourcemap_path = Nanoc::Int::TempFilenameFactory.instance.create('sass_sourcemap')
32
+ inline = true
33
+ end
39
34
 
40
35
  engine = ::Sass::Engine.new(content, options)
41
36
  css, sourcemap = sourcemap_path ? engine.render_with_sourcemap(sourcemap_path) : engine.render
42
- [css, sourcemap&.to_json(css_uri: rep.path, type: rep.path.nil? ? :inline : :auto)]
43
- end
44
-
45
- # @api private
46
- class NanocSassImporter < ::Sass::Importers::Filesystem
47
- attr_reader :filter
48
-
49
- def initialize(filter)
50
- @filter = filter
51
- super('.')
52
- end
53
-
54
- def find_relative(name, base_identifier, options)
55
- base_raw_filename = filter.items[base_identifier].raw_filename
56
-
57
- # we can't resolve a relative filename from an in-memory item
58
- return unless base_raw_filename
59
-
60
- raw_filename, syntax = ::Sass::Util.destructure(find_real_file(File.dirname(base_raw_filename), name, options))
61
- return unless raw_filename
62
-
63
- item = raw_filename_to_item(raw_filename)
64
- # it doesn't make sense to import a file, from Nanoc's content if the corresponding item has been deleted
65
- raise "unable to map #{raw_filename} to any item" if item.nil?
66
-
67
- filter.depend_on([item])
68
-
69
- options[:syntax] = syntax
70
- options[:filename] = item.identifier.to_s
71
- options[:importer] = self
72
- ::Sass::Engine.new(item.raw_content, options)
73
- end
74
-
75
- def find(identifier, options)
76
- items = filter.items.find_all(identifier)
77
- return if items.empty?
78
-
79
- content = if items.size == 1
80
- items.first.compiled_content
81
- else
82
- items.map { |item| %(@import "#{item.identifier}";) }.join("\n")
83
- end
84
37
 
85
- options[:syntax] = :scss
86
- options[:filename] = identifier.to_s
87
- options[:importer] = self
88
- ::Sass::Engine.new(content, options)
89
- end
90
-
91
- def key(identifier, _options)
92
- [self.class.name + ':' + root, identifier.to_s]
93
- end
94
-
95
- def public_url(identifier, _sourcemap_directory)
96
- path = filter.items[identifier].path
97
- return path unless path.nil?
98
-
99
- raw_filename = filter.items[identifier].raw_filename
100
- return if raw_filename.nil?
101
-
102
- ::Sass::Util.file_uri_from_path(raw_filename)
103
- end
104
-
105
- def to_s
106
- 'Nanoc Sass Importer'
38
+ if inline
39
+ sourcemap = sourcemap&.to_json(css_uri: css_path)
40
+ encoded = "data:application/json;base64,#{Base64.urlsafe_encode64(sourcemap)}"
41
+ [css.gsub(%r{^/\*#\s+sourceMappingURL=\s*#{sourcemap_path}\s*\*/$}, "/*# sourceMappingURL=#{encoded} */")]
42
+ else
43
+ sourcemap = sourcemap&.to_json(css_path: css_path, sourcemap_path: sourcemap_path, type: params[:sources_content] ? :inline : :auto)
44
+ sourcemap = sourcemap&.split("\n")&.reject { |l| l =~ /^\s*"file":\s*"#{filter.object_id.to_s}"\s*$/ }&.join("\n")
45
+ [css, sourcemap]
107
46
  end
47
+ end
48
+ end
108
49
 
109
- def self.raw_filename_to_item_map_for_config(config, items)
110
- @raw_filename_to_item_map ||= {}
111
- @raw_filename_to_item_map[config.object_id] ||=
112
- {}.tap do |map|
113
- items.each do |item|
114
- if item.raw_filename
115
- path = Pathname.new(item.raw_filename).realpath.to_s
116
- map[path] = item
117
- end
118
- end
119
- end
120
- end
50
+ class SassFilter < Nanoc::Filter
51
+ identifier :sass
121
52
 
122
- def raw_filename_to_item(filename)
123
- realpath = Pathname.new(filename).realpath.to_s
53
+ include SassCommon
54
+ requires(*SassCommon::REQUIRES)
124
55
 
125
- map = self.class.raw_filename_to_item_map_for_config(filter.config, filter.items)
126
- map[realpath]
127
- end
56
+ def run(content, params = {})
57
+ css(self, @item_rep, content, params)
128
58
  end
129
59
  end
130
60
 
131
- module ::Sass::Script::Functions
132
- def nanoc(string, params)
133
- assert_type string, :String
134
- assert_type params, :Hash
135
- result = options[:importer].filter.instance_eval(string.value)
136
- case result
137
- when TrueClass, FalseClass
138
- bool(result)
139
- when Array
140
- list(result, :comma)
141
- when Hash
142
- map(result)
143
- when nil
144
- null
145
- when Numeric
146
- number(result)
147
- else
148
- params['unquote'] ? unquoted_string(result) : quoted_string(result)
149
- end
61
+ class SassSourcemapFilter < Nanoc::Filter
62
+ identifier :sass_sourcemap
63
+
64
+ include SassCommon
65
+ requires(*SassCommon::REQUIRES)
66
+
67
+ def run(content, params = {})
68
+ sourcemap(self, @item_rep, content, params)
150
69
  end
151
- declare :nanoc, [:string], var_kwargs: true
152
70
  end
153
71
  end
@@ -3,8 +3,34 @@
3
3
  module Nanoc::Helpers
4
4
  # @see http://nanoc.ws/doc/reference/helpers/#breadcrumbs
5
5
  module Breadcrumbs
6
+ class AmbiguousAncestorError < Nanoc::Int::Errors::Generic
7
+ def initialize(pattern, items)
8
+ @pattern = pattern
9
+ @items = items
10
+ end
11
+
12
+ def message
13
+ "expected only one item to match #{@pattern}, but found #{@items.size}"
14
+ end
15
+ end
16
+
6
17
  # @api private
7
18
  module Int
19
+ DEFAULT_TIEBREAKER =
20
+ lambda do |items, pattern|
21
+ identifiers = items.map(&:identifier).sort
22
+ $stderr.puts <<~WARNING
23
+ Warning: The breadcrumbs trail (generated by #breadcrumbs_trail) found more than one potential parent item at #{pattern} (found #{identifiers.join(', ')}). Nanoc will pick the first item as the parent. Consider eliminating the ambiguity by making only one item match #{pattern}, or by passing a `:tiebreaker` option to `#breadcrumbs_trail`. (This situation will be an error in the next major version of Nanoc.)
24
+ WARNING
25
+
26
+ items.min_by(&:identifier)
27
+ end
28
+
29
+ ERROR_TIEBREAKER =
30
+ lambda do |items, pattern|
31
+ raise AmbiguousAncestorError.new(pattern, items)
32
+ end
33
+
8
34
  # e.g. unfold(10.class, &:superclass)
9
35
  # => [Integer, Numeric, Object, BasicObject]
10
36
  def self.unfold(obj, &blk)
@@ -29,10 +55,26 @@ module Nanoc::Helpers
29
55
 
30
56
  prefixes.map { |pr| pr + '.*' }
31
57
  end
58
+
59
+ def self.find_one(items, pat, tiebreaker)
60
+ res = items.find_all(pat)
61
+ case res.size
62
+ when 0
63
+ nil
64
+ when 1
65
+ res.first
66
+ else
67
+ if tiebreaker.arity == 1
68
+ tiebreaker.call(res)
69
+ else
70
+ tiebreaker.call(res, pat)
71
+ end
72
+ end
73
+ end
32
74
  end
33
75
 
34
76
  # @return [Array]
35
- def breadcrumbs_trail
77
+ def breadcrumbs_trail(tiebreaker: Int::DEFAULT_TIEBREAKER)
36
78
  # The design of this function is a little complicated.
37
79
  #
38
80
  # We can’t use #parent_of from the ChildParent helper, because the
@@ -65,6 +107,8 @@ module Nanoc::Helpers
65
107
  components = item.identifier.components
66
108
  prefixes = components.inject(['']) { |acc, elem| acc + [acc.last + '/' + elem] }
67
109
 
110
+ tiebreaker = Int::ERROR_TIEBREAKER if tiebreaker == :error
111
+
68
112
  if @item.identifier.legacy?
69
113
  prefixes.map { |pr| @items[Nanoc::Identifier.new('/' + pr, type: :legacy)] }
70
114
  else
@@ -75,7 +119,7 @@ module Nanoc::Helpers
75
119
  @items['/index.*']
76
120
  else
77
121
  prefix_patterns = Int.patterns_for_prefix(pr)
78
- prefix_patterns.lazy.map { |pat| @items[pat] }.find(&:itself)
122
+ prefix_patterns.lazy.map { |pat| Int.find_one(@items, pat, tiebreaker) }.find(&:itself)
79
123
  end
80
124
  end
81
125
  ancestral_items + [item]
@@ -12,7 +12,7 @@ module Nanoc
12
12
  @any_layouts = false
13
13
  @last_snapshot = false
14
14
  @pre_snapshot = false
15
- @skip_routing_rule = false
15
+ @snapshots_for_which_to_skip_routing_rule = Set.new
16
16
  end
17
17
 
18
18
  def inspect
@@ -40,7 +40,9 @@ module Nanoc
40
40
  MaybePathlike = C::Or[nil, Nanoc::UNDEFINED, String, Nanoc::Identifier]
41
41
  contract Symbol, C::KeywordArgs[path: C::Optional[MaybePathlike]] => nil
42
42
  def snapshot(snapshot_name, path: Nanoc::UNDEFINED)
43
- @skip_routing_rule = path.nil?
43
+ unless Nanoc::UNDEFINED.equal?(path)
44
+ @snapshots_for_which_to_skip_routing_rule << snapshot_name
45
+ end
44
46
 
45
47
  path =
46
48
  if Nanoc::UNDEFINED.equal?(path) || path.nil?
@@ -69,9 +71,9 @@ module Nanoc
69
71
  @any_layouts
70
72
  end
71
73
 
72
- contract C::None => C::Bool
73
- def skip_routing_rule?
74
- @skip_routing_rule
74
+ contract C::None => Set
75
+ def snapshots_for_which_to_skip_routing_rule
76
+ @snapshots_for_which_to_skip_routing_rule
75
77
  end
76
78
 
77
79
  contract C::None => C::Bool
@@ -69,7 +69,11 @@ module Nanoc::RuleDSL
69
69
  recorder.snapshot(:last) unless recorder.last_snapshot?
70
70
  recorder.snapshot(:pre) unless recorder.pre_snapshot?
71
71
 
72
- copy_paths_from_routing_rules(compact_snapshots(recorder.action_sequence), rep: rep)
72
+ copy_paths_from_routing_rules(
73
+ compact_snapshots(recorder.action_sequence),
74
+ recorder.snapshots_for_which_to_skip_routing_rule,
75
+ rep: rep,
76
+ )
73
77
  end
74
78
 
75
79
  # @param [Nanoc::Int::Layout] layout
@@ -99,26 +103,25 @@ module Nanoc::RuleDSL
99
103
  Nanoc::Int::ActionSequence.new(seq.item_rep, actions: actions)
100
104
  end
101
105
 
102
- def copy_paths_from_routing_rules(seq, rep:)
106
+ def copy_paths_from_routing_rules(seq, snapshots_for_which_to_skip_routing_rule, rep:)
107
+ # NOTE: This assumes that `seq` is compacted, i.e. there are no two consecutive snapshot actions.
108
+
103
109
  seq.map do |action|
104
- if action.is_a?(Nanoc::Int::ProcessingActions::Snapshot) && action.paths.empty?
105
- copy_path_from_routing_rule(action, rep: rep)
106
- else
107
- action
108
- end
109
- end
110
- end
110
+ # Only potentially modify snapshot actions
111
+ next action unless action.is_a?(Nanoc::Int::ProcessingActions::Snapshot)
111
112
 
112
- def copy_path_from_routing_rule(action, rep:)
113
- paths_from_rules =
114
- action.snapshot_names.map do |snapshot_name|
115
- basic_path_from_rules_for(rep, snapshot_name)
116
- end.compact
113
+ # If any of the action’s snapshot are explicitly marked as excluded from
114
+ # getting a path from a routing rule, then ignore routing rules.
115
+ next action if snapshots_for_which_to_skip_routing_rule.intersect?(Set.new(action.snapshot_names))
117
116
 
118
- if paths_from_rules.any?
119
- action.update(paths: paths_from_rules.map(&:to_s))
120
- else
121
- action
117
+ # If this action already has paths that don’t come from routing rules,
118
+ # then don’t add more to them.
119
+ next action unless action.paths.empty?
120
+
121
+ # For each snapshot name, find a path from a routing rule. The routing
122
+ # rule might return nil, so we need #compact.
123
+ paths = action.snapshot_names.map { |sn| basic_path_from_rules_for(rep, sn) }.compact
124
+ action.update(snapshot_names: [], paths: paths)
122
125
  end
123
126
  end
124
127
 
data/lib/nanoc/spec.rb CHANGED
@@ -167,19 +167,19 @@ module Nanoc
167
167
  def view_context
168
168
  compilation_context =
169
169
  Nanoc::Int::CompilationContext.new(
170
- action_provider: @action_provider,
171
- reps: @reps,
172
- site: @site,
170
+ action_provider: @action_provider,
171
+ reps: @reps,
172
+ site: @site,
173
173
  compiled_content_cache: :__compiled_content_cache,
174
- snapshot_repo: @snapshot_repo,
174
+ snapshot_repo: @snapshot_repo,
175
175
  )
176
176
 
177
177
  Nanoc::ViewContextForCompilation.new(
178
- reps: @reps,
179
- items: @items,
180
- dependency_tracker: @dependency_tracker,
178
+ reps: @reps,
179
+ items: @items,
180
+ dependency_tracker: @dependency_tracker,
181
181
  compilation_context: compilation_context,
182
- snapshot_repo: @snapshot_repo,
182
+ snapshot_repo: @snapshot_repo,
183
183
  )
184
184
  end
185
185
 
data/lib/nanoc/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nanoc
4
4
  # The current Nanoc version.
5
- VERSION = '4.10.0'
5
+ VERSION = '4.11.0'
6
6
  end
data/lib/nanoc.rb CHANGED
@@ -38,6 +38,7 @@ module Nanoc
38
38
  end
39
39
 
40
40
  # Load general requirements
41
+ require 'base64'
41
42
  require 'cgi'
42
43
  require 'digest'
43
44
  require 'English'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.0
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-14 00:00:00.000000000 Z
11
+ date: 2018-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -401,6 +401,8 @@ files:
401
401
  - lib/nanoc/filters/relativize_paths.rb
402
402
  - lib/nanoc/filters/rubypants.rb
403
403
  - lib/nanoc/filters/sass.rb
404
+ - lib/nanoc/filters/sass/functions.rb
405
+ - lib/nanoc/filters/sass/importer.rb
404
406
  - lib/nanoc/filters/slim.rb
405
407
  - lib/nanoc/filters/typogruby.rb
406
408
  - lib/nanoc/filters/uglify_js.rb
@@ -453,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
455
  version: '0'
454
456
  requirements: []
455
457
  rubyforge_project:
456
- rubygems_version: 2.7.7
458
+ rubygems_version: 2.7.8
457
459
  signing_key:
458
460
  specification_version: 4
459
461
  summary: A static-site generator with a focus on flexibility.