nanoc 4.9.2 → 4.9.3

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: b913559b6a6971b80377035d086779ac7d799a7ffee38289778bec2e8a82cd7c
4
- data.tar.gz: 28bb11a9f2146ace9c6a018a69bc11c766bfe29ee08fbce18923f4686bda8379
3
+ metadata.gz: d01ae1a36cc8bd7ac120b0f9f26ec0017083ec01086d2c954a45f0e4814b0fa7
4
+ data.tar.gz: f2bb6242846d090fb321f1136a70f955dba3b43696a0266965c225fb0fb13d7a
5
5
  SHA512:
6
- metadata.gz: 9862f93c33f34a75792f371ff106bfe9119f61c0e052e648ef8caa66364e81adc91ec36d015b22f8f9faea4479839fe013edb388886785b7149089428bb57b69
7
- data.tar.gz: 75f1f8f4039bc15ba041861696b80ededbf7fb67ed18f57b2c1b4e0cd65efef46a331e5ea6e659de37eb1e8c5f05dfea39a097a2d5f4d25a493410fd77e2ec3b
6
+ metadata.gz: 2180c9c63d7d19d2e87aafa2ffe0094d9685e8b0b821b7bb171ad016009668850c3aab9860f5d78a0704b90f93602f34587c987bcff748aafce1910ca4b43782
7
+ data.tar.gz: 53285c7562eb828a349f3d2ba42a0c022f4dd83a0e801432e5cffdf7d659e8755e9d742b4bd253d8fe05bef2ea293886892f8d57e270f2109f4f352715ee79f5
data/NEWS.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.9.3 (2018-06-09)
4
+
5
+ Enhancements:
6
+
7
+ * Added an `:exclude` option to `relativize_paths`, to exclude certain paths from being relativized (#1340)
8
+
3
9
  ## 4.9.2 (2018-03-30)
4
10
 
5
11
  Fixes:
@@ -6,11 +6,9 @@ module Nanoc::Int
6
6
  class Ignorer
7
7
  include Singleton
8
8
 
9
- # rubocop:disable Style/MethodMissing
10
- def method_missing(*_args)
9
+ def method_missing(*_args) # rubocop:disable Style/MethodMissingSuper
11
10
  self
12
11
  end
13
- # rubocop:enable Style/MethodMissing
14
12
 
15
13
  def respond_to_missing?(*_args)
16
14
  true
@@ -159,7 +159,7 @@ module Nanoc::CLI
159
159
  when Nanoc::Int::Errors::GenericTrivial, Errno::EADDRINUSE
160
160
  true
161
161
  when LoadError
162
- GEM_NAMES.keys.include?(gem_name_from_load_error(error))
162
+ GEM_NAMES.key?(gem_name_from_load_error(error))
163
163
  else
164
164
  false
165
165
  end
@@ -38,7 +38,7 @@ module Nanoc::CLI
38
38
  @stream.puts " ... #{error.backtrace.size - count} lines omitted (see crash.log for details)"
39
39
  end
40
40
 
41
- backtrace.each_with_index.to_a.reverse.each do |(item, index)|
41
+ backtrace.each_with_index.to_a.reverse_each do |(item, index)|
42
42
  if index.zero?
43
43
  @stream.puts " #{item}"
44
44
  else
@@ -8,6 +8,8 @@ module Nanoc::Filters
8
8
  require 'nanoc/helpers/link_to'
9
9
  include Nanoc::Helpers::LinkTo
10
10
 
11
+ DDMemoize.activate(self)
12
+
11
13
  SELECTORS = ['*/@href', '*/@src', 'object/@data', 'param[@name="movie"]/@content', 'form/@action', 'comment()'].freeze
12
14
 
13
15
  GCSE_SEARCH_WORKAROUND = 'nanoc__gcse_search__f7ac3462f628a053f86fe6563c0ec98f1fe45cee'
@@ -41,7 +43,7 @@ module Nanoc::Filters
41
43
  # Filter
42
44
  case params[:type]
43
45
  when :css
44
- relativize_css(content)
46
+ relativize_css(content, params)
45
47
  when :html, :html5, :xml, :xhtml
46
48
  relativize_html_like(content, params)
47
49
  else
@@ -53,15 +55,37 @@ module Nanoc::Filters
53
55
 
54
56
  protected
55
57
 
56
- def relativize_css(content)
58
+ def relativize_css(content, params)
57
59
  # FIXME: parse CSS the proper way using csspool or something
58
60
  content.gsub(/url\((['"]?)(\/(?:[^\/].*?)?)\1\)/) do
59
61
  quote = Regexp.last_match[1]
60
62
  path = Regexp.last_match[2]
61
- 'url(' + quote + relative_path_to(path) + quote + ')'
63
+
64
+ if exclude?(path, params)
65
+ Regexp.last_match[0]
66
+ else
67
+ 'url(' + quote + relative_path_to(path) + quote + ')'
68
+ end
69
+ end
70
+ end
71
+
72
+ memoized def excludes(params)
73
+ raw = [params.fetch(:exclude, [])].flatten
74
+ raw.map do |exclusion|
75
+ case exclusion
76
+ when Regexp
77
+ exclusion
78
+ when String
79
+ /\A#{exclusion}(\z|\/)/
80
+ end
62
81
  end
63
82
  end
64
83
 
84
+ def exclude?(path, params)
85
+ # TODO: Use #match? on newer Ruby versions
86
+ excludes(params).any? { |ex| path =~ ex }
87
+ end
88
+
65
89
  def relativize_html_like(content, params)
66
90
  selectors = params.fetch(:select, SELECTORS)
67
91
  namespaces = params.fetch(:namespaces, {})
@@ -71,7 +95,7 @@ module Nanoc::Filters
71
95
  parser = parser_for(type)
72
96
  content = fix_content(content, type)
73
97
 
74
- nokogiri_process(content, selectors, namespaces, parser, type, nokogiri_save_options)
98
+ nokogiri_process(content, selectors, namespaces, parser, type, nokogiri_save_options, params)
75
99
  end
76
100
 
77
101
  def parser_for(type)
@@ -104,7 +128,7 @@ module Nanoc::Filters
104
128
  end
105
129
  end
106
130
 
107
- def nokogiri_process(content, selectors, namespaces, klass, type, nokogiri_save_options = nil)
131
+ def nokogiri_process(content, selectors, namespaces, klass, type, nokogiri_save_options, params)
108
132
  # Ensure that all prefixes are strings
109
133
  namespaces = namespaces.reduce({}) { |new, (prefix, uri)| new.merge(prefix.to_s => uri) }
110
134
 
@@ -114,8 +138,8 @@ module Nanoc::Filters
114
138
  selector = selectors.map { |sel| "descendant-or-self::#{sel}" }.join('|')
115
139
  doc.xpath(selector, namespaces).each do |node|
116
140
  if node.name == 'comment'
117
- nokogiri_process_comment(node, doc, selectors, namespaces, klass, type)
118
- elsif path_is_relativizable?(node.content)
141
+ nokogiri_process_comment(node, doc, selectors, namespaces, klass, type, params)
142
+ elsif path_is_relativizable?(node.content, params)
119
143
  node.content = relative_path_to(node.content)
120
144
  end
121
145
  end
@@ -139,20 +163,20 @@ module Nanoc::Filters
139
163
  content.gsub(GCSE_SEARCH_WORKAROUND, 'gcse:search')
140
164
  end
141
165
 
142
- def nokogiri_process_comment(node, doc, selectors, namespaces, klass, type)
166
+ def nokogiri_process_comment(node, doc, selectors, namespaces, klass, type, params)
143
167
  content = node.content.dup.sub(%r{^(\s*\[.+?\]>\s*)(.+?)(\s*<!\[endif\])}m) do |_m|
144
168
  beginning = Regexp.last_match[1]
145
169
  body = Regexp.last_match[2]
146
170
  ending = Regexp.last_match[3]
147
171
 
148
- beginning + nokogiri_process(body, selectors, namespaces, klass, type) + ending
172
+ beginning + nokogiri_process(body, selectors, namespaces, klass, type, nil, params) + ending
149
173
  end
150
174
 
151
175
  node.replace(Nokogiri::XML::Comment.new(doc, content))
152
176
  end
153
177
 
154
- def path_is_relativizable?(path)
155
- path.start_with?('/')
178
+ def path_is_relativizable?(path, params)
179
+ path.start_with?('/') && !exclude?(path, params)
156
180
  end
157
181
  end
158
182
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nanoc
4
4
  # The current Nanoc version.
5
- VERSION = '4.9.2'
5
+ VERSION = '4.9.3'
6
6
  end
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.9.2
4
+ version: 4.9.3
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-03-30 00:00:00.000000000 Z
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -437,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
437
  version: '0'
438
438
  requirements: []
439
439
  rubyforge_project:
440
- rubygems_version: 2.7.6
440
+ rubygems_version: 2.7.7
441
441
  signing_key:
442
442
  specification_version: 4
443
443
  summary: A static-site generator with a focus on flexibility.