nanoc 4.7.5 → 4.7.6
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 +4 -4
- data/Gemfile +4 -3
- data/Gemfile.lock +18 -13
- data/NEWS.md +7 -1
- data/Rakefile +2 -2
- data/lib/nanoc/base/entities/action_sequence.rb +3 -12
- data/lib/nanoc/base/entities/configuration.rb +3 -3
- data/lib/nanoc/base/entities/identifiable_collection.rb +2 -4
- data/lib/nanoc/base/memoization.rb +1 -0
- data/lib/nanoc/base/repos/config_loader.rb +1 -1
- data/lib/nanoc/base/services/compilation_context.rb +3 -3
- data/lib/nanoc/base/services/compiler.rb +2 -3
- data/lib/nanoc/base/services/compiler/stages/cleanup.rb +1 -1
- data/lib/nanoc/base/services/filter.rb +4 -12
- data/lib/nanoc/base/services/item_rep_router.rb +3 -3
- data/lib/nanoc/base/services/outdatedness_checker.rb +1 -2
- data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +1 -2
- data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +1 -2
- data/lib/nanoc/base/services/outdatedness_rules/configuration_modified.rb +1 -2
- data/lib/nanoc/base/services/outdatedness_rules/paths_modified.rb +5 -5
- data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +3 -3
- data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +4 -4
- data/lib/nanoc/checking/checks/external_links.rb +0 -2
- data/lib/nanoc/cli.rb +1 -1
- data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +7 -5
- data/lib/nanoc/cli/commands/create-site.rb +1 -1
- data/lib/nanoc/cli/commands/nanoc.rb +1 -4
- data/lib/nanoc/cli/commands/show-plugins.rb +1 -1
- data/lib/nanoc/cli/error_handler.rb +2 -1
- data/lib/nanoc/deploying/deployers/git.rb +7 -7
- data/lib/nanoc/extra/link_collector.rb +2 -2
- data/lib/nanoc/filters/asciidoc.rb +1 -1
- data/lib/nanoc/filters/colorize_syntax.rb +46 -19
- data/lib/nanoc/filters/relativize_paths.rb +33 -9
- data/lib/nanoc/rule_dsl/action_sequence_calculator.rb +15 -7
- data/lib/nanoc/version.rb +1 -1
- data/nanoc.gemspec +1 -1
- data/spec/nanoc/base/checksummer_spec.rb +2 -2
- data/spec/nanoc/base/entities/action_sequence_spec.rb +0 -36
- data/spec/nanoc/base/entities/identifier_spec.rb +1 -1
- data/spec/nanoc/base/entities/outdatedness_status_spec.rb +1 -1
- data/spec/nanoc/base/entities/processing_actions/snapshot_spec.rb +1 -1
- data/spec/nanoc/base/entities/props_spec.rb +13 -13
- data/spec/nanoc/base/memoization_spec.rb +31 -0
- data/spec/nanoc/base/services/executor_spec.rb +2 -2
- data/spec/nanoc/base/services/item_rep_selector_spec.rb +12 -12
- data/spec/nanoc/base/services/outdatedness_checker_spec.rb +23 -23
- data/spec/nanoc/base/views/post_compile_item_view_spec.rb +1 -1
- data/spec/nanoc/cli/commands/deploy_spec.rb +8 -8
- data/spec/nanoc/filters/less_spec.rb +11 -11
- data/spec/nanoc/helpers/capturing_spec.rb +2 -2
- data/spec/nanoc/helpers/tagging_spec.rb +5 -5
- data/spec/nanoc/integration/outdatedness_integration_spec.rb +29 -29
- data/spec/nanoc/integration/partial_recompilation_spec.rb +8 -8
- data/spec/nanoc/regressions/gh_1015_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1022_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1031_spec.rb +3 -3
- data/spec/nanoc/regressions/gh_1035_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1037a_spec.rb +2 -2
- data/spec/nanoc/regressions/gh_1037b_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1040_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1045_spec.rb +3 -3
- data/spec/nanoc/regressions/gh_1047_spec.rb +3 -3
- data/spec/nanoc/regressions/gh_1064_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1067_spec.rb +3 -3
- data/spec/nanoc/regressions/gh_1082a_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1082b_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1082c_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1082d_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1093_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1094_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1097_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1100_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1102_spec.rb +3 -3
- data/spec/nanoc/regressions/gh_1107_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1130_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_1134_spec.rb +2 -2
- data/spec/nanoc/regressions/gh_1145_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_804_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_809_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_841_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_867_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_882_spec.rb +3 -3
- data/spec/nanoc/regressions/gh_885_spec.rb +2 -2
- data/spec/nanoc/regressions/gh_891_spec.rb +2 -2
- data/spec/nanoc/regressions/gh_913_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_924_spec.rb +2 -2
- data/spec/nanoc/regressions/gh_928_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_937_spec.rb +2 -2
- data/spec/nanoc/regressions/gh_942_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_947_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_948_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_951_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_954_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_970a_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_970b_spec.rb +7 -7
- data/spec/nanoc/regressions/gh_974_spec.rb +1 -1
- data/spec/nanoc/regressions/gh_981_spec.rb +3 -3
- data/spec/nanoc/rule_dsl/action_sequence_calculator_spec.rb +43 -4
- data/test/base/core_ext/array_spec.rb +2 -2
- data/test/base/test_compiler.rb +6 -6
- data/test/base/test_filter.rb +0 -8
- data/test/base/test_site.rb +1 -1
- data/test/checking/test_runner.rb +2 -2
- data/test/cli/commands/test_check.rb +2 -2
- data/test/cli/commands/test_compile.rb +6 -6
- data/test/cli/commands/test_create_site.rb +12 -12
- data/test/cli/commands/test_help.rb +2 -2
- data/test/cli/commands/test_info.rb +1 -1
- data/test/cli/commands/test_prune.rb +6 -6
- data/test/cli/test_cleaning_stream.rb +1 -1
- data/test/cli/test_cli.rb +9 -9
- data/test/data_sources/test_filesystem.rb +8 -8
- data/test/extra/core_ext/test_pathname.rb +1 -1
- data/test/extra/test_link_collector.rb +3 -3
- data/test/extra/test_piper.rb +3 -3
- data/test/filters/colorize_syntax/test_common.rb +25 -1
- data/test/filters/test_relativize_paths.rb +38 -0
- data/test/helper.rb +1 -1
- data/test/helpers/test_capturing.rb +8 -8
- data/test/rule_dsl/test_action_provider.rb +2 -2
- data/test/rule_dsl/test_rule.rb +1 -1
- data/test/test_gem.rb +1 -1
- metadata +4 -4
|
@@ -3,14 +3,14 @@ module Nanoc::Int::OutdatednessRules
|
|
|
3
3
|
affects_props :raw_content, :attributes, :path
|
|
4
4
|
|
|
5
5
|
def apply(obj, outdatedness_checker)
|
|
6
|
-
|
|
7
|
-
if any_always_outdated?(
|
|
6
|
+
seq = outdatedness_checker.action_sequence_for(obj)
|
|
7
|
+
if any_always_outdated?(seq)
|
|
8
8
|
Nanoc::Int::OutdatednessReasons::UsesAlwaysOutdatedFilter
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def any_always_outdated?(
|
|
13
|
-
|
|
12
|
+
def any_always_outdated?(seq)
|
|
13
|
+
seq
|
|
14
14
|
.select { |a| a.is_a?(Nanoc::Int::ProcessingActions::Filter) }
|
|
15
15
|
.map { |a| Nanoc::Filter.named(a.filter_name) }
|
|
16
16
|
.compact
|
|
@@ -11,8 +11,6 @@ module ::Nanoc::Checking::Checks
|
|
|
11
11
|
identifiers :external_links, :elinks
|
|
12
12
|
|
|
13
13
|
def run
|
|
14
|
-
require 'nokogiri'
|
|
15
|
-
|
|
16
14
|
# Find all broken external hrefs
|
|
17
15
|
# TODO: de-duplicate this (duplicated in internal links check)
|
|
18
16
|
filenames = output_filenames.select { |f| File.extname(f) == '.html' && !excluded_file?(f) }
|
data/lib/nanoc/cli.rb
CHANGED
|
@@ -214,7 +214,7 @@ module Nanoc::CLI
|
|
|
214
214
|
def self.enable_utf8?(io)
|
|
215
215
|
return true unless io.tty?
|
|
216
216
|
|
|
217
|
-
%w
|
|
217
|
+
%w[LC_ALL LC_CTYPE LANG].any? { |e| ENV[e] =~ /UTF/i }
|
|
218
218
|
end
|
|
219
219
|
|
|
220
220
|
# @return [Boolean] true if color support is present, false if not
|
|
@@ -17,13 +17,14 @@ module Nanoc::CLI::Commands::CompileListeners
|
|
|
17
17
|
def start
|
|
18
18
|
stage_stopwatch = Nanoc::Telemetry::Stopwatch.new
|
|
19
19
|
|
|
20
|
-
on(:stage_started) do |
|
|
20
|
+
on(:stage_started) do |_klass|
|
|
21
21
|
stage_stopwatch.start
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
on(:stage_ended) do |
|
|
24
|
+
on(:stage_ended) do |klass|
|
|
25
25
|
stage_stopwatch.stop
|
|
26
|
-
|
|
26
|
+
name = klass.to_s.sub(/.*::/, '')
|
|
27
|
+
@telemetry.summary(:stages).observe(stage_stopwatch.duration, name)
|
|
27
28
|
stage_stopwatch = Nanoc::Telemetry::Stopwatch.new
|
|
28
29
|
end
|
|
29
30
|
|
|
@@ -40,7 +41,8 @@ module Nanoc::CLI::Commands::CompileListeners
|
|
|
40
41
|
stopwatch = stopwatches.fetch(obj)
|
|
41
42
|
stopwatch.stop
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
name = klass.to_s.sub(/.*::/, '')
|
|
45
|
+
@telemetry.summary(:outdatedness_rules).observe(stopwatch.duration, name)
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
filter_stopwatches = {}
|
|
@@ -143,7 +145,7 @@ module Nanoc::CLI::Commands::CompileListeners
|
|
|
143
145
|
end
|
|
144
146
|
|
|
145
147
|
def table_for_memoization
|
|
146
|
-
headers = %w
|
|
148
|
+
headers = %w[memoization hit miss %]
|
|
147
149
|
|
|
148
150
|
rows_raw = @telemetry.counter(:memoization).map do |(name, type), counter|
|
|
149
151
|
{ name: name, type: type, count: counter.value }
|
|
@@ -300,7 +300,7 @@ EOS
|
|
|
300
300
|
path = arguments[0]
|
|
301
301
|
|
|
302
302
|
# Check whether site exists
|
|
303
|
-
if File.exist?(path) && (!File.directory?(path) || !(Dir.entries(path) - %w
|
|
303
|
+
if File.exist?(path) && (!File.directory?(path) || !(Dir.entries(path) - %w[. ..]).empty?) && !options[:force]
|
|
304
304
|
raise(
|
|
305
305
|
Nanoc::Int::Errors::GenericTrivial,
|
|
306
306
|
"The site was not created because '#{path}' already exists. " \
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
usage 'nanoc command [options] [arguments]'
|
|
2
2
|
summary 'Nanoc, a static site compiler written in Ruby'
|
|
3
|
+
default_subcommand 'compile'
|
|
3
4
|
|
|
4
5
|
opt :l, :color, 'enable color' do
|
|
5
6
|
$stdout.remove_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
|
|
@@ -37,7 +38,3 @@ end
|
|
|
37
38
|
opt :w, :warn, 'enable warnings' do
|
|
38
39
|
$-w = true
|
|
39
40
|
end
|
|
40
|
-
|
|
41
|
-
run do |_opts, _args, cmd|
|
|
42
|
-
cmd.command_named('compile').run([])
|
|
43
|
-
end
|
|
@@ -42,7 +42,7 @@ module Nanoc::CLI
|
|
|
42
42
|
# @return [void]
|
|
43
43
|
def handle_while(&_block)
|
|
44
44
|
# Set exit handler
|
|
45
|
-
%w
|
|
45
|
+
%w[INT TERM].each do |signal|
|
|
46
46
|
Signal.trap(signal) do
|
|
47
47
|
puts
|
|
48
48
|
exit!(0)
|
|
@@ -193,6 +193,7 @@ module Nanoc::CLI
|
|
|
193
193
|
'maruku' => 'maruku',
|
|
194
194
|
'mime/types' => 'mime-types',
|
|
195
195
|
'nokogiri' => 'nokogiri',
|
|
196
|
+
'nokogumbo' => 'nokogumbo',
|
|
196
197
|
'pry' => 'pry',
|
|
197
198
|
'rack' => 'rack',
|
|
198
199
|
'rack/cache' => 'rack-cache',
|
|
@@ -61,7 +61,7 @@ module Nanoc::Deploying::Deployers
|
|
|
61
61
|
# Verify existence of remote, if remote is not a URL
|
|
62
62
|
if remote_is_name?(remote)
|
|
63
63
|
begin
|
|
64
|
-
run_cmd(%W
|
|
64
|
+
run_cmd(%W[git config --get remote.#{remote}.url])
|
|
65
65
|
rescue Nanoc::Extra::Piper::Error
|
|
66
66
|
raise Errors::RemoteDoesNotExist.new(remote)
|
|
67
67
|
end
|
|
@@ -69,7 +69,7 @@ module Nanoc::Deploying::Deployers
|
|
|
69
69
|
|
|
70
70
|
# If the branch exists then switch to it, otherwise prompt the user to create one.
|
|
71
71
|
begin
|
|
72
|
-
run_cmd_unless_dry(%W
|
|
72
|
+
run_cmd_unless_dry(%W[git checkout #{branch}])
|
|
73
73
|
rescue Nanoc::Extra::Piper::Error
|
|
74
74
|
raise Errors::BranchDoesNotExist.new(branch)
|
|
75
75
|
end
|
|
@@ -78,13 +78,13 @@ module Nanoc::Deploying::Deployers
|
|
|
78
78
|
|
|
79
79
|
msg = "Automated commit at #{Time.now.utc} by Nanoc #{Nanoc::VERSION}"
|
|
80
80
|
author = 'Nanoc <>'
|
|
81
|
-
run_cmd_unless_dry(%w
|
|
82
|
-
run_cmd_unless_dry(%W
|
|
81
|
+
run_cmd_unless_dry(%w[git add -A])
|
|
82
|
+
run_cmd_unless_dry(%W[git commit -a --author #{author} -m #{msg}])
|
|
83
83
|
|
|
84
84
|
if forced
|
|
85
|
-
run_cmd_unless_dry(%W
|
|
85
|
+
run_cmd_unless_dry(%W[git push -f #{remote} #{branch}])
|
|
86
86
|
else
|
|
87
|
-
run_cmd_unless_dry(%W
|
|
87
|
+
run_cmd_unless_dry(%W[git push #{remote} #{branch}])
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
end
|
|
@@ -111,7 +111,7 @@ module Nanoc::Deploying::Deployers
|
|
|
111
111
|
def clean_repo?
|
|
112
112
|
stdout = StringIO.new
|
|
113
113
|
piper = Nanoc::Extra::Piper.new(stdout: stdout, stderr: $stderr)
|
|
114
|
-
piper.run(%w
|
|
114
|
+
piper.run(%w[git status --porcelain], nil)
|
|
115
115
|
stdout.string.empty?
|
|
116
116
|
end
|
|
117
117
|
end
|
|
@@ -44,11 +44,11 @@ module ::Nanoc::Extra
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def hrefs_in_file(filename)
|
|
47
|
-
uris_in_file filename, %w
|
|
47
|
+
uris_in_file filename, %w[a img]
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def resource_uris_in_file(filename)
|
|
51
|
-
uris_in_file filename, %w
|
|
51
|
+
uris_in_file filename, %w[audio form img iframe link script video]
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
private
|
|
@@ -92,19 +92,11 @@ module Nanoc::Filters
|
|
|
92
92
|
@colorizers[language] = colorizer
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
case syntax
|
|
98
|
-
when :html
|
|
99
|
-
klass = Nokogiri::HTML
|
|
100
|
-
when :xml, :xhtml
|
|
101
|
-
klass = Nokogiri::XML
|
|
102
|
-
else
|
|
103
|
-
raise "unknown syntax: #{syntax.inspect} (expected :html or :xml)"
|
|
104
|
-
end
|
|
95
|
+
syntax = params.fetch(:syntax, :html)
|
|
96
|
+
parser = parser_for(syntax)
|
|
105
97
|
|
|
106
98
|
# Colorize
|
|
107
|
-
doc = parse(content,
|
|
99
|
+
doc = parse(content, parser, params.fetch(:is_fullpage, false))
|
|
108
100
|
selector = params[:outside_pre] ? 'code' : 'pre > code'
|
|
109
101
|
doc.css(selector).each do |element|
|
|
110
102
|
# Get language
|
|
@@ -128,7 +120,7 @@ module Nanoc::Filters
|
|
|
128
120
|
# Highlight
|
|
129
121
|
raw = strip(element.inner_text)
|
|
130
122
|
highlighted_code = highlight(raw, language, params)
|
|
131
|
-
element.children =
|
|
123
|
+
element.children = parse_fragment(parser, strip(highlighted_code))
|
|
132
124
|
|
|
133
125
|
# Add language-something class
|
|
134
126
|
unless has_class
|
|
@@ -141,8 +133,44 @@ module Nanoc::Filters
|
|
|
141
133
|
highlight_postprocess(language, element.parent)
|
|
142
134
|
end
|
|
143
135
|
|
|
144
|
-
|
|
145
|
-
|
|
136
|
+
serialize(doc, syntax)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def parser_for(syntax)
|
|
140
|
+
case syntax
|
|
141
|
+
when :html
|
|
142
|
+
require 'nokogiri'
|
|
143
|
+
Nokogiri::HTML
|
|
144
|
+
when :html5
|
|
145
|
+
require 'nokogumbo'
|
|
146
|
+
Nokogiri::HTML5
|
|
147
|
+
when :xml, :xhtml
|
|
148
|
+
require 'nokogiri'
|
|
149
|
+
Nokogiri::XML
|
|
150
|
+
else
|
|
151
|
+
raise "unknown syntax: #{syntax.inspect} (expected :html, :html5, or :xml)"
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def serialize(doc, syntax)
|
|
156
|
+
case syntax
|
|
157
|
+
when :html5
|
|
158
|
+
doc.to_html
|
|
159
|
+
else
|
|
160
|
+
doc.send("to_#{syntax}", encoding: 'UTF-8')
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def parse_full(parser_class, content)
|
|
165
|
+
if parser_class.to_s == 'Nokogiri::HTML5'
|
|
166
|
+
parser_class.parse(content)
|
|
167
|
+
else
|
|
168
|
+
parser_class.parse(content, nil, 'UTF-8')
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def parse_fragment(parser_class, content)
|
|
173
|
+
parser_class.fragment(content)
|
|
146
174
|
end
|
|
147
175
|
|
|
148
176
|
# Parses the given content using the given class. This method also handles
|
|
@@ -151,16 +179,15 @@ module Nanoc::Filters
|
|
|
151
179
|
#
|
|
152
180
|
# @param [String] content The content to parse
|
|
153
181
|
#
|
|
154
|
-
# @param [Class] klass The Nokogiri parser class
|
|
155
|
-
# or Nokogiri::XML)
|
|
182
|
+
# @param [Class] klass The Nokogiri parser class
|
|
156
183
|
#
|
|
157
184
|
# @param [Boolean] is_fullpage true if the given content is a full page,
|
|
158
185
|
# false if it is a fragment
|
|
159
186
|
def parse(content, klass, is_fullpage)
|
|
160
187
|
if is_fullpage
|
|
161
|
-
klass
|
|
188
|
+
parse_full(klass, content)
|
|
162
189
|
else
|
|
163
|
-
klass
|
|
190
|
+
parse_fragment(klass, content)
|
|
164
191
|
end
|
|
165
192
|
rescue => e
|
|
166
193
|
if e.message =~ /can't modify frozen string/
|
|
@@ -358,7 +385,7 @@ module Nanoc::Filters
|
|
|
358
385
|
|
|
359
386
|
protected
|
|
360
387
|
|
|
361
|
-
KNOWN_COLORIZERS = %i
|
|
388
|
+
KNOWN_COLORIZERS = %i[coderay dummy pygmentize pygmentsrb simon_highlight rouge].freeze
|
|
362
389
|
|
|
363
390
|
# Removes the first blank lines and any whitespace at the end.
|
|
364
391
|
def strip(s)
|
|
@@ -38,7 +38,7 @@ module Nanoc::Filters
|
|
|
38
38
|
case params[:type]
|
|
39
39
|
when :css
|
|
40
40
|
relativize_css(content)
|
|
41
|
-
when :html, :xml, :xhtml
|
|
41
|
+
when :html, :html5, :xml, :xhtml
|
|
42
42
|
relativize_html_like(content, params)
|
|
43
43
|
else
|
|
44
44
|
raise 'The relativize_paths needs to know the type of content to ' \
|
|
@@ -63,22 +63,40 @@ module Nanoc::Filters
|
|
|
63
63
|
namespaces = params.fetch(:namespaces, {})
|
|
64
64
|
type = params.fetch(:type)
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
parser = parser_for(type)
|
|
67
|
+
content = fix_content(content, type)
|
|
68
|
+
|
|
69
|
+
nokogiri_process(content, selectors, namespaces, parser, type)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def parser_for(type)
|
|
67
73
|
case type
|
|
68
74
|
when :html
|
|
69
|
-
|
|
75
|
+
require 'nokogiri'
|
|
76
|
+
::Nokogiri::HTML
|
|
77
|
+
when :html5
|
|
78
|
+
require 'nokogumbo'
|
|
79
|
+
::Nokogiri::HTML5
|
|
70
80
|
when :xml
|
|
71
|
-
|
|
81
|
+
require 'nokogiri'
|
|
82
|
+
::Nokogiri::XML
|
|
83
|
+
when :xhtml
|
|
84
|
+
require 'nokogiri'
|
|
85
|
+
::Nokogiri::XML
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def fix_content(content, type)
|
|
90
|
+
case type
|
|
72
91
|
when :xhtml
|
|
73
|
-
klass = ::Nokogiri::XML
|
|
74
92
|
# FIXME: cleanup because it is ugly
|
|
75
93
|
# this cleans the XHTML namespace to process fragments and full
|
|
76
94
|
# documents in the same way. At least, Nokogiri adds this namespace
|
|
77
95
|
# if detects the `html` element.
|
|
78
|
-
content
|
|
96
|
+
content.sub(%r{(<html[^>]+)xmlns="http://www.w3.org/1999/xhtml"}, '\1')
|
|
97
|
+
else
|
|
98
|
+
content
|
|
79
99
|
end
|
|
80
|
-
|
|
81
|
-
nokogiri_process(content, selectors, namespaces, klass, type)
|
|
82
100
|
end
|
|
83
101
|
|
|
84
102
|
def nokogiri_process(content, selectors, namespaces, klass, type)
|
|
@@ -95,7 +113,13 @@ module Nanoc::Filters
|
|
|
95
113
|
end
|
|
96
114
|
end
|
|
97
115
|
end
|
|
98
|
-
|
|
116
|
+
|
|
117
|
+
case type
|
|
118
|
+
when :html5
|
|
119
|
+
doc.to_html
|
|
120
|
+
else
|
|
121
|
+
doc.send("to_#{type}")
|
|
122
|
+
end
|
|
99
123
|
end
|
|
100
124
|
|
|
101
125
|
def nokogiri_process_comment(node, doc, selectors, namespaces, klass, type)
|
|
@@ -54,10 +54,6 @@ module Nanoc::RuleDSL
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
# @param [Nanoc::Int::ItemRep] rep The item representation to get the rule
|
|
58
|
-
# memory for
|
|
59
|
-
#
|
|
60
|
-
# @return [Nanoc::Int::ActionSequence]
|
|
61
57
|
def new_action_sequence_for_rep(rep)
|
|
62
58
|
dependency_tracker = Nanoc::Int::DependencyTracker::Null.new
|
|
63
59
|
view_context = @site.compiler.compilation_context.create_view_context(dependency_tracker)
|
|
@@ -82,7 +78,7 @@ module Nanoc::RuleDSL
|
|
|
82
78
|
executor.snapshot(:pre)
|
|
83
79
|
end
|
|
84
80
|
|
|
85
|
-
copy_paths_from_routing_rules(action_sequence
|
|
81
|
+
copy_paths_from_routing_rules(compact_snapshots(action_sequence), rep: rep)
|
|
86
82
|
end
|
|
87
83
|
|
|
88
84
|
# @param [Nanoc::Int::Layout] layout
|
|
@@ -100,8 +96,20 @@ module Nanoc::RuleDSL
|
|
|
100
96
|
end
|
|
101
97
|
end
|
|
102
98
|
|
|
103
|
-
def
|
|
104
|
-
|
|
99
|
+
def compact_snapshots(seq)
|
|
100
|
+
actions = []
|
|
101
|
+
seq.actions.each do |action|
|
|
102
|
+
if [actions.last, action].all? { |a| a.is_a?(Nanoc::Int::ProcessingActions::Snapshot) }
|
|
103
|
+
actions[-1] = actions.last.update(snapshot_names: action.snapshot_names, paths: action.paths)
|
|
104
|
+
else
|
|
105
|
+
actions << action
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
Nanoc::Int::ActionSequence.new(seq.item_rep, actions: actions)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def copy_paths_from_routing_rules(seq, rep:)
|
|
112
|
+
seq.map do |action|
|
|
105
113
|
if action.is_a?(Nanoc::Int::ProcessingActions::Snapshot) && action.paths.empty?
|
|
106
114
|
copy_path_from_routing_rule(action, rep: rep)
|
|
107
115
|
else
|
data/lib/nanoc/version.rb
CHANGED
data/nanoc.gemspec
CHANGED
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
|
24
24
|
|
|
25
25
|
s.required_ruby_version = '>= 2.1.0'
|
|
26
26
|
|
|
27
|
-
s.add_runtime_dependency('cri', '~> 2.
|
|
27
|
+
s.add_runtime_dependency('cri', '~> 2.8')
|
|
28
28
|
s.add_runtime_dependency('hamster', '~> 3.0')
|
|
29
29
|
s.add_runtime_dependency('ref', '~> 2.0')
|
|
30
30
|
s.add_runtime_dependency('ddplugin', '~> 1.0')
|
|
@@ -69,11 +69,11 @@ describe Nanoc::Int::Checksummer do
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
context 'Array' do
|
|
72
|
-
let(:obj) { %w
|
|
72
|
+
let(:obj) { %w[hello goodbye] }
|
|
73
73
|
it { is_expected.to eql('Array<String<hello>,String<goodbye>,>') }
|
|
74
74
|
|
|
75
75
|
context 'different order' do
|
|
76
|
-
let(:obj) { %w
|
|
76
|
+
let(:obj) { %w[goodbye hello] }
|
|
77
77
|
it { is_expected.to eql('Array<String<goodbye>,String<hello>,>') }
|
|
78
78
|
end
|
|
79
79
|
|