nanoc 4.10.4 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49248486c259abaff30695129879e162907c8c2d4dd7d732b4fdcc2da85d2b3f
4
- data.tar.gz: f3ffb726ca647c372279f04063e44001a834e7a2fae0640a72bf216f7fcc950c
3
+ metadata.gz: 24b2704181c12e6dc71bf46b7bb87dc14e31c18d7d4530a0420dd2c98ffb3e9b
4
+ data.tar.gz: 913ca912414ce823d274704ba45e06ace2a4e603081472a6815fe0b9076dd1b2
5
5
  SHA512:
6
- metadata.gz: 6be653b479fc1ac3d883ce735c956315331569e4851e5bef853094df8549a479c41a42cc266defbf9fbd881cc7e0ea8847a04ce726c5489d7e0531bcb938ee26
7
- data.tar.gz: 417abf05a59af571b5402d8e0869308012ed04abd4e070c1c633170c5b66904d0931f80b1a6f670f5743f0fdf6f71fde425481806aaf0a3e144015cc464b7756
6
+ metadata.gz: cb662339340e2682df52518b85d5295bab537b18014a9fcd001f65fe31cb62aae1ab9bccca0c877ba196025a1e839ac6cd6fd26538e4df00b6b250a06dff7b61
7
+ data.tar.gz: d1b82c96c958141bdeb7d82511fd06d4a9499c251f6b656e300ea9120041377fcfde2c6562758c733e0d5e4eef593ba36fff5b3d16d4f719cc81f451014e2edb
data/NEWS.md CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## 4.10.4 (2018-12-01)
4
11
 
5
12
  Fixes:
@@ -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'
@@ -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')
@@ -25,11 +25,25 @@ module Nanoc::Filters
25
25
  filename: rep.item.identifier.to_s,
26
26
  cache: false,
27
27
  )
28
+ css_path = options.delete(:css_path) || filter.object_id.to_s
28
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
29
34
 
30
35
  engine = ::Sass::Engine.new(content, options)
31
36
  css, sourcemap = sourcemap_path ? engine.render_with_sourcemap(sourcemap_path) : engine.render
32
- [css, sourcemap&.to_json(css_uri: rep.path, type: rep.path.nil? ? :inline : :auto)]
37
+
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]
46
+ end
33
47
  end
34
48
  end
35
49
 
@@ -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]
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nanoc
4
4
  # The current Nanoc version.
5
- VERSION = '4.10.4'
5
+ VERSION = '4.11.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.4
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne