nanoc 4.0.2 → 4.1.0a1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +17 -0
- data/Gemfile +50 -46
- data/Gemfile.lock +365 -0
- data/Guardfile +3 -0
- data/NEWS.md +21 -0
- data/README.md +1 -1
- data/lib/nanoc/base.rb +3 -15
- data/lib/nanoc/base/checksummer.rb +3 -14
- data/lib/nanoc/base/compilation/compiler.rb +112 -283
- data/lib/nanoc/base/compilation/compiler_dsl.rb +29 -37
- data/lib/nanoc/base/compilation/dependency_tracker.rb +25 -170
- data/lib/nanoc/base/compilation/filter.rb +3 -4
- data/lib/nanoc/base/compilation/item_rep_repo.rb +33 -0
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +39 -53
- data/lib/nanoc/base/compilation/rule.rb +13 -24
- data/lib/nanoc/base/compilation/rule_context.rb +29 -15
- data/lib/nanoc/base/entities.rb +10 -0
- data/lib/nanoc/base/{source_data → entities}/code_snippet.rb +1 -4
- data/lib/nanoc/base/{source_data → entities}/configuration.rb +1 -1
- data/lib/nanoc/base/entities/content.rb +8 -9
- data/lib/nanoc/base/{identifiable_collection.rb → entities/identifiable_collection.rb} +0 -0
- data/lib/nanoc/base/entities/identifier.rb +11 -2
- data/lib/nanoc/base/{source_data → entities}/item.rb +0 -18
- data/lib/nanoc/base/{result_data → entities}/item_rep.rb +15 -13
- data/lib/nanoc/base/entities/rule_memory.rb +54 -0
- data/lib/nanoc/base/entities/rule_memory_action.rb +19 -0
- data/lib/nanoc/base/entities/rule_memory_actions.rb +3 -0
- data/lib/nanoc/base/entities/rule_memory_actions/filter.rb +22 -0
- data/lib/nanoc/base/entities/rule_memory_actions/layout.rb +22 -0
- data/lib/nanoc/base/entities/rule_memory_actions/snapshot.rb +26 -0
- data/lib/nanoc/base/entities/rules_collection.rb +120 -0
- data/lib/nanoc/base/{source_data → entities}/site.rb +11 -10
- data/lib/nanoc/base/repos.rb +2 -0
- data/lib/nanoc/base/repos/checksum_store.rb +3 -9
- data/lib/nanoc/base/repos/compiled_content_cache.rb +0 -5
- data/lib/nanoc/base/{source_data → repos}/data_source.rb +3 -6
- data/lib/nanoc/base/repos/dependency_store.rb +118 -0
- data/lib/nanoc/base/repos/rule_memory_store.rb +1 -5
- data/lib/nanoc/base/repos/site_loader.rb +0 -28
- data/lib/nanoc/base/repos/store.rb +0 -12
- data/lib/nanoc/base/services.rb +8 -0
- data/lib/nanoc/base/services/compiler_loader.rb +49 -0
- data/lib/nanoc/base/services/executor.rb +4 -4
- data/lib/nanoc/base/services/item_rep_builder.rb +30 -0
- data/lib/nanoc/base/services/item_rep_router.rb +55 -0
- data/lib/nanoc/base/services/item_rep_selector.rb +39 -0
- data/lib/nanoc/base/services/item_rep_writer.rb +2 -0
- data/lib/nanoc/base/services/postprocessor.rb +26 -0
- data/lib/nanoc/base/services/preprocessor.rb +26 -0
- data/lib/nanoc/base/services/recording_executor.rb +36 -22
- data/lib/nanoc/base/services/rule_memory_calculator.rb +84 -0
- data/lib/nanoc/base/services/rules_loader.rb +29 -0
- data/lib/nanoc/base/views.rb +6 -0
- data/lib/nanoc/base/views/config_view.rb +8 -2
- data/lib/nanoc/base/views/identifiable_collection_view.rb +5 -4
- data/lib/nanoc/base/views/item_rep_collection_view.rb +7 -6
- data/lib/nanoc/base/views/item_rep_view.rb +13 -12
- data/lib/nanoc/base/views/item_view.rb +18 -12
- data/lib/nanoc/base/views/layout_view.rb +1 -1
- data/lib/nanoc/base/views/mixins/document_view_mixin.rb +2 -1
- data/lib/nanoc/base/views/mutable_identifiable_collection_view.rb +1 -1
- data/lib/nanoc/base/views/mutable_item_collection_view.rb +4 -7
- data/lib/nanoc/base/views/post_compile_item_collection_view.rb +8 -0
- data/lib/nanoc/base/views/post_compile_item_view.rb +7 -0
- data/lib/nanoc/base/views/site_view.rb +3 -2
- data/lib/nanoc/base/views/view.rb +12 -0
- data/lib/nanoc/base/views/view_context.rb +12 -0
- data/lib/nanoc/cli/commands/compile.rb +13 -15
- data/lib/nanoc/cli/commands/create-site.rb +15 -0
- data/lib/nanoc/cli/commands/prune.rb +1 -1
- data/lib/nanoc/cli/commands/shell.rb +3 -3
- data/lib/nanoc/cli/commands/show-data.rb +5 -5
- data/lib/nanoc/cli/commands/show-rules.rb +2 -1
- data/lib/nanoc/cli/error_handler.rb +28 -30
- data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +1 -1
- data/lib/nanoc/data_sources/filesystem.rb +1 -1
- data/lib/nanoc/extra/checking/check.rb +8 -7
- data/lib/nanoc/extra/checking/checks/external_links.rb +14 -1
- data/lib/nanoc/extra/checking/runner.rb +1 -1
- data/lib/nanoc/extra/deployer.rb +3 -3
- data/lib/nanoc/extra/piper.rb +5 -5
- data/lib/nanoc/extra/pruner.rb +8 -7
- data/lib/nanoc/filters/relativize_paths.rb +48 -32
- data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +0 -1
- data/lib/nanoc/helpers/blogging.rb +15 -7
- data/lib/nanoc/helpers/capturing.rb +56 -13
- data/lib/nanoc/helpers/link_to.rb +2 -2
- data/lib/nanoc/helpers/tagging.rb +5 -10
- data/lib/nanoc/helpers/text.rb +9 -11
- data/lib/nanoc/version.rb +1 -1
- data/nanoc-4.0.2.gem +0 -0
- data/tags +1175 -0
- data/test/base/test_compiler.rb +48 -98
- data/test/base/test_compiler_dsl.rb +113 -39
- data/test/base/test_dependency_tracker.rb +80 -79
- data/test/base/test_outdatedness_checker.rb +39 -26
- data/test/base/test_site.rb +0 -97
- data/test/cli/commands/test_compile.rb +2 -3
- data/test/extra/checking/checks/test_external_links.rb +25 -0
- data/test/extra/deployers/test_fog.rb +12 -6
- data/test/filters/test_erb.rb +1 -1
- data/test/filters/test_erubis.rb +1 -1
- data/test/filters/test_haml.rb +1 -1
- data/test/filters/test_less.rb +4 -4
- data/test/filters/test_sass.rb +1 -0
- data/test/filters/test_xsl.rb +7 -8
- data/test/helper.rb +0 -2
- data/test/helpers/test_blogging.rb +26 -23
- data/test/helpers/test_capturing.rb +131 -12
- data/test/helpers/test_filtering.rb +6 -6
- data/test/helpers/test_link_to.rb +1 -1
- data/test/helpers/test_rendering.rb +16 -24
- data/test/helpers/test_tagging.rb +13 -10
- data/test/helpers/test_xml_sitemap.rb +25 -21
- metadata +36 -14
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +0 -35
- data/lib/nanoc/base/compilation/rules_collection.rb +0 -245
- data/test/base/test_rule_context.rb +0 -78
data/test/base/test_compiler.rb
CHANGED
@@ -1,28 +1,44 @@
|
|
1
1
|
class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
2
|
+
def new_compiler(site = nil)
|
3
|
+
site ||= Nanoc::Int::Site.new(
|
4
|
+
config: nil,
|
5
|
+
code_snippets: [],
|
6
|
+
items: [],
|
7
|
+
layouts: [],
|
8
|
+
)
|
9
|
+
|
10
|
+
rules_collection = Nanoc::Int::RulesCollection.new
|
11
|
+
|
12
|
+
reps = Nanoc::Int::ItemRepRepo.new
|
13
|
+
|
14
|
+
params = {
|
15
|
+
compiled_content_cache: Nanoc::Int::CompiledContentCache.new,
|
16
|
+
checksum_store: Nanoc::Int::ChecksumStore.new(site: site),
|
17
|
+
rule_memory_store: Nanoc::Int::RuleMemoryStore.new,
|
18
|
+
rule_memory_calculator: Nanoc::Int::RuleMemoryCalculator.new(
|
19
|
+
rules_collection: rules_collection,
|
20
|
+
site: site,
|
21
|
+
),
|
22
|
+
dependency_store: Nanoc::Int::DependencyStore.new(
|
23
|
+
site.items.to_a + site.layouts.to_a),
|
24
|
+
reps: reps,
|
25
|
+
}
|
20
26
|
|
21
|
-
|
22
|
-
|
27
|
+
params[:outdatedness_checker] =
|
28
|
+
Nanoc::Int::OutdatednessChecker.new(
|
29
|
+
site: site,
|
30
|
+
checksum_store: params[:checksum_store],
|
31
|
+
dependency_store: params[:dependency_store],
|
32
|
+
rules_collection: params[:rules_collection],
|
33
|
+
rule_memory_store: params[:rule_memory_store],
|
34
|
+
rule_memory_calculator: params[:rule_memory_calculator],
|
35
|
+
reps: reps,
|
36
|
+
)
|
37
|
+
|
38
|
+
Nanoc::Int::Compiler.new(site, rules_collection, params)
|
23
39
|
end
|
24
40
|
|
25
|
-
def
|
41
|
+
def test_compilation_rule_for
|
26
42
|
# Mock rules
|
27
43
|
rules = [mock, mock, mock]
|
28
44
|
rules[0].expects(:applicable_to?).returns(false)
|
@@ -32,8 +48,8 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
32
48
|
rules[2].expects(:rep_name).returns('right')
|
33
49
|
|
34
50
|
# Create compiler
|
35
|
-
compiler =
|
36
|
-
compiler.rules_collection.instance_eval { @
|
51
|
+
compiler = new_compiler
|
52
|
+
compiler.rules_collection.instance_eval { @item_compilation_rules = rules }
|
37
53
|
|
38
54
|
# Mock rep
|
39
55
|
rep = mock
|
@@ -42,15 +58,12 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
42
58
|
rep.stubs(:item).returns(item)
|
43
59
|
|
44
60
|
# Test
|
45
|
-
assert_equal rules[2], compiler.rules_collection.
|
61
|
+
assert_equal rules[2], compiler.rules_collection.compilation_rule_for(rep)
|
46
62
|
end
|
47
63
|
|
48
64
|
def test_filter_for_layout_with_existant_layout
|
49
|
-
# Mock site
|
50
|
-
site = mock
|
51
|
-
|
52
65
|
# Create compiler
|
53
|
-
compiler =
|
66
|
+
compiler = new_compiler
|
54
67
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(/.*/)] = [:erb, { foo: 'bar' }]
|
55
68
|
|
56
69
|
# Mock layout
|
@@ -62,11 +75,8 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
62
75
|
end
|
63
76
|
|
64
77
|
def test_filter_for_layout_with_existant_layout_and_unknown_filter
|
65
|
-
# Mock site
|
66
|
-
site = mock
|
67
|
-
|
68
78
|
# Create compiler
|
69
|
-
compiler =
|
79
|
+
compiler = new_compiler
|
70
80
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(/.*/)] = [:some_unknown_filter, { foo: 'bar' }]
|
71
81
|
|
72
82
|
# Mock layout
|
@@ -78,11 +88,8 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
78
88
|
end
|
79
89
|
|
80
90
|
def test_filter_for_layout_with_nonexistant_layout
|
81
|
-
# Mock site
|
82
|
-
site = mock
|
83
|
-
|
84
91
|
# Create compiler
|
85
|
-
compiler =
|
92
|
+
compiler = new_compiler
|
86
93
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/foo/$})] = [:erb, { foo: 'bar' }]
|
87
94
|
|
88
95
|
# Mock layout
|
@@ -94,11 +101,8 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
94
101
|
end
|
95
102
|
|
96
103
|
def test_filter_for_layout_with_many_layouts
|
97
|
-
# Mock site
|
98
|
-
site = mock
|
99
|
-
|
100
104
|
# Create compiler
|
101
|
-
compiler =
|
105
|
+
compiler = new_compiler
|
102
106
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/b/c/.*/$})] = [:erb, { char: 'd' }]
|
103
107
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/.*/$})] = [:erb, { char: 'b' }]
|
104
108
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/b/.*/$})] = [:erb, { char: 'c' }] # never used!
|
@@ -159,7 +163,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
159
163
|
site.stubs(:layouts).returns([layout])
|
160
164
|
|
161
165
|
# Create compiler
|
162
|
-
compiler =
|
166
|
+
compiler = new_compiler(site)
|
163
167
|
compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule)
|
164
168
|
compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/blah/$})] = [:erb, {}]
|
165
169
|
site.stubs(:compiler).returns(compiler)
|
@@ -271,7 +275,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
271
275
|
|
272
276
|
# Create site
|
273
277
|
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
274
|
-
error = assert_raises(
|
278
|
+
error = assert_raises(Nanoc::Error) do
|
275
279
|
site.compile
|
276
280
|
end
|
277
281
|
assert_match(/^The path returned for the.*does not start with a slash. Please ensure that all routing rules return a path that starts with a slash./, error.message)
|
@@ -299,31 +303,12 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
299
303
|
|
300
304
|
# Create site
|
301
305
|
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
302
|
-
assert_raises(Nanoc::Int::
|
306
|
+
assert_raises(Nanoc::Int::ItemRepRouter::IdenticalRoutesError) do
|
303
307
|
site.compile
|
304
308
|
end
|
305
309
|
end
|
306
310
|
end
|
307
311
|
|
308
|
-
def test_load_should_be_idempotent
|
309
|
-
# Create site
|
310
|
-
Nanoc::CLI.run %w( create_site bar)
|
311
|
-
|
312
|
-
FileUtils.cd('bar') do
|
313
|
-
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
314
|
-
|
315
|
-
compiler = Nanoc::Int::Compiler.new(site)
|
316
|
-
def compiler.route_reps
|
317
|
-
raise 'oh my gosh it is borken'
|
318
|
-
end
|
319
|
-
|
320
|
-
assert site.instance_eval { !@loaded }
|
321
|
-
assert_raises(RuntimeError) { compiler.load }
|
322
|
-
assert site.instance_eval { !@loaded }
|
323
|
-
assert_raises(RuntimeError) { compiler.load }
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
312
|
def test_compile_should_recompile_all_reps
|
328
313
|
Nanoc::CLI.run %w( create_site bar )
|
329
314
|
|
@@ -335,7 +320,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
335
320
|
|
336
321
|
# At this point, even the already compiled items in the previous pass
|
337
322
|
# should have their compiled content assigned, so this should work:
|
338
|
-
site.items['/index.*']
|
323
|
+
site.compiler.reps[site.items['/index.*']][0].compiled_content
|
339
324
|
end
|
340
325
|
end
|
341
326
|
|
@@ -584,41 +569,6 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
|
|
584
569
|
end
|
585
570
|
end
|
586
571
|
|
587
|
-
def test_compiler_dependency_on_unmet_dependency
|
588
|
-
with_site do
|
589
|
-
File.open('content/a.html', 'w') do |io|
|
590
|
-
io.write('<% @items["/b/"].compiled_content %>')
|
591
|
-
end
|
592
|
-
File.open('content/b.html', 'w') do |io|
|
593
|
-
io.write('I am feeling so dependent!')
|
594
|
-
end
|
595
|
-
File.open('Rules', 'w') do |io|
|
596
|
-
io.write "compile '*' do\n"
|
597
|
-
io.write " filter :erb\n"
|
598
|
-
io.write "end\n"
|
599
|
-
io.write "\n"
|
600
|
-
io.write "route '*' do\n"
|
601
|
-
io.write " item.identifier.chop + '.' + item[:extension]\n"
|
602
|
-
io.write "end\n"
|
603
|
-
io.write "\n"
|
604
|
-
io.write "layout '*', :erb\n"
|
605
|
-
end
|
606
|
-
|
607
|
-
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
608
|
-
site.compiler.load
|
609
|
-
rep = site.items['/a/'].reps[0]
|
610
|
-
dt = site.compiler.dependency_tracker
|
611
|
-
dt.start
|
612
|
-
assert_raises Nanoc::Int::Errors::UnmetDependency do
|
613
|
-
site.compiler.send :compile_rep, rep
|
614
|
-
end
|
615
|
-
dt.stop
|
616
|
-
|
617
|
-
stack = dt.instance_eval { @stack }
|
618
|
-
assert_empty stack
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
572
|
def test_find_layouts_by_glob
|
623
573
|
Nanoc::CLI.run %w( create_site bar )
|
624
574
|
FileUtils.cd('bar') do
|
@@ -12,7 +12,7 @@ class Nanoc::Int::CompilerDSLTest < Nanoc::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_preprocess_twice
|
15
|
-
rules_collection = Nanoc::Int::RulesCollection.new
|
15
|
+
rules_collection = Nanoc::Int::RulesCollection.new
|
16
16
|
compiler_dsl = Nanoc::Int::CompilerDSL.new(rules_collection, {})
|
17
17
|
|
18
18
|
# first time
|
@@ -30,61 +30,135 @@ class Nanoc::Int::CompilerDSLTest < Nanoc::TestCase
|
|
30
30
|
assert_match(/WARNING: A preprocess block is already defined./, io[:stderr])
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_postprocess_twice
|
34
|
+
rules_collection = Nanoc::Int::RulesCollection.new
|
35
|
+
compiler_dsl = Nanoc::Int::CompilerDSL.new(rules_collection, {})
|
36
|
+
|
37
|
+
# first time
|
38
|
+
io = capturing_stdio do
|
39
|
+
compiler_dsl.postprocess {}
|
40
|
+
end
|
41
|
+
assert_empty io[:stdout]
|
42
|
+
assert_empty io[:stderr]
|
43
|
+
|
44
|
+
# second time
|
45
|
+
io = capturing_stdio do
|
46
|
+
compiler_dsl.postprocess {}
|
47
|
+
end
|
48
|
+
assert_empty io[:stdout]
|
49
|
+
assert_match(/WARNING: A postprocess block is already defined./, io[:stderr])
|
50
|
+
end
|
51
|
+
|
33
52
|
def test_per_rules_file_preprocessor
|
34
53
|
# Create site
|
35
|
-
Nanoc::CLI.run %w( create_site
|
36
|
-
FileUtils.cd('
|
37
|
-
# Create rep
|
38
|
-
item = Nanoc::Int::Item.new('foo', { extension: 'bar' }, '/foo/')
|
39
|
-
|
54
|
+
Nanoc::CLI.run %w( create_site foo )
|
55
|
+
FileUtils.cd('foo') do
|
40
56
|
# Create a bonus rules file
|
41
|
-
File.
|
57
|
+
File.write(
|
58
|
+
'more_rules.rb',
|
59
|
+
"preprocess { @items['/index.*'][:preprocessed] = true }")
|
42
60
|
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
io = capturing_stdio do
|
48
|
-
dsl.preprocess {}
|
49
|
-
end
|
50
|
-
assert_empty io[:stdout]
|
51
|
-
assert_empty io[:stderr]
|
61
|
+
# Adjust normal rules file
|
62
|
+
File.write(
|
63
|
+
'Rules',
|
64
|
+
"include_rules 'more_rules'\n\npreprocess {}\n\n" + File.read('Rules'))
|
52
65
|
|
53
|
-
#
|
54
|
-
|
66
|
+
# Create site and compiler
|
67
|
+
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
68
|
+
compiler = Nanoc::Int::CompilerLoader.new.load(site)
|
55
69
|
|
56
70
|
# Check that the two preprocess blocks have been added
|
57
|
-
assert_equal 2,
|
58
|
-
refute_nil
|
59
|
-
refute_nil
|
71
|
+
assert_equal 2, compiler.rules_collection.preprocessors.size
|
72
|
+
refute_nil compiler.rules_collection.preprocessors.first
|
73
|
+
refute_nil compiler.rules_collection.preprocessors.to_a.last
|
60
74
|
|
61
75
|
# Apply preprocess blocks
|
62
|
-
|
63
|
-
|
76
|
+
Nanoc::Int::Preprocessor
|
77
|
+
.new(site: site, rules_collection: compiler.rules_collection)
|
78
|
+
.run
|
79
|
+
assert site.items['/index.*'].attributes[:preprocessed]
|
64
80
|
end
|
65
81
|
end
|
66
82
|
|
67
|
-
def
|
83
|
+
def test_per_rules_file_postprocessor
|
68
84
|
# Create site
|
69
|
-
Nanoc::CLI.run %w( create_site
|
70
|
-
FileUtils.cd('
|
71
|
-
# Create rep
|
72
|
-
item = Nanoc::Int::Item.new('foo', { extension: 'bar' }, '/foo/')
|
73
|
-
rep = Nanoc::Int::ItemRep.new(item, :default)
|
74
|
-
|
85
|
+
Nanoc::CLI.run %w( create_site foo )
|
86
|
+
FileUtils.cd('foo') do
|
75
87
|
# Create a bonus rules file
|
76
|
-
File.
|
88
|
+
File.write(
|
89
|
+
'more_rules.rb',
|
90
|
+
'postprocess {}')
|
77
91
|
|
78
|
-
#
|
92
|
+
# Adjust normal rules file
|
93
|
+
File.write(
|
94
|
+
'Rules',
|
95
|
+
"include_rules 'more_rules'\n\npostprocess {}\n\n" + File.read('Rules'))
|
96
|
+
|
97
|
+
# Create site and compiler
|
79
98
|
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
80
|
-
|
81
|
-
dsl = site.compiler.rules_collection.dsl
|
99
|
+
compiler = Nanoc::Int::CompilerLoader.new.load(site)
|
82
100
|
|
83
|
-
#
|
84
|
-
|
101
|
+
# Check that the two postprocess blocks have been added
|
102
|
+
assert_equal 2, compiler.rules_collection.postprocessors.size
|
103
|
+
refute_nil compiler.rules_collection.postprocessors.first
|
104
|
+
refute_nil compiler.rules_collection.postprocessors.to_a.last
|
105
|
+
end
|
106
|
+
end
|
85
107
|
|
86
|
-
|
87
|
-
|
108
|
+
def test_postprocessor_modified_method
|
109
|
+
with_site do |site|
|
110
|
+
# Create rules
|
111
|
+
File.open('Rules', 'w') do |io|
|
112
|
+
io.write <<EOS
|
113
|
+
compile '*' do
|
114
|
+
end
|
115
|
+
route '*' do
|
116
|
+
end
|
117
|
+
postprocess do
|
118
|
+
puts @items.select(&:modified).length
|
119
|
+
end
|
120
|
+
EOS
|
121
|
+
end
|
122
|
+
|
123
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
124
|
+
|
125
|
+
io = capturing_stdio do
|
126
|
+
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
127
|
+
site.compile
|
128
|
+
end
|
129
|
+
|
130
|
+
assert_match(/1/, io[:stdout])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_include_rules
|
135
|
+
# Create site
|
136
|
+
Nanoc::CLI.run %w( create_site foo )
|
137
|
+
FileUtils.cd('foo') do
|
138
|
+
# Create a bonus rules file
|
139
|
+
File.write(
|
140
|
+
'more_rules.rb',
|
141
|
+
"passthrough '/index.*'")
|
142
|
+
|
143
|
+
# Adjust normal rules file
|
144
|
+
File.write(
|
145
|
+
'Rules',
|
146
|
+
"include_rules 'more_rules'\n\n" \
|
147
|
+
"route '/**/*' do ; nil ; end\n\n" \
|
148
|
+
"compile '/**/*' do ; end\n")
|
149
|
+
|
150
|
+
# Create site and compiler
|
151
|
+
site = Nanoc::Int::SiteLoader.new.new_from_cwd
|
152
|
+
compiler = Nanoc::Int::CompilerLoader.new.load(site)
|
153
|
+
compiler.build_reps
|
154
|
+
|
155
|
+
# Check
|
156
|
+
rep = compiler.reps[site.items['/index.*']][0]
|
157
|
+
routing_rules = site.compiler.rules_collection.routing_rules_for(rep)
|
158
|
+
routing_rule = routing_rules[:last]
|
159
|
+
refute_nil routing_rule
|
160
|
+
assert_equal Nanoc::Int::StringPattern, routing_rule.pattern.class
|
161
|
+
assert_equal '/index.*', routing_rule.pattern.to_s
|
88
162
|
end
|
89
163
|
end
|
90
164
|
|
@@ -92,7 +166,7 @@ class Nanoc::Int::CompilerDSLTest < Nanoc::TestCase
|
|
92
166
|
with_site do
|
93
167
|
# Create rules
|
94
168
|
File.open('Rules', 'w') do |io|
|
95
|
-
io.write
|
169
|
+
io.write <<-EOS
|
96
170
|
passthrough "/robots/"
|
97
171
|
|
98
172
|
compile '*' do ; end
|
@@ -4,11 +4,11 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
4
4
|
items = [mock, mock]
|
5
5
|
|
6
6
|
# Create
|
7
|
-
|
7
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
8
8
|
|
9
9
|
# Verify no dependencies yet
|
10
|
-
assert_empty
|
11
|
-
assert_empty
|
10
|
+
assert_empty store.objects_causing_outdatedness_of(items[0])
|
11
|
+
assert_empty store.objects_causing_outdatedness_of(items[1])
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_record_dependency
|
@@ -16,13 +16,13 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
16
16
|
items = [mock, mock]
|
17
17
|
|
18
18
|
# Create
|
19
|
-
|
19
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
20
20
|
|
21
21
|
# Record some dependencies
|
22
|
-
|
22
|
+
store.record_dependency(items[0], items[1])
|
23
23
|
|
24
24
|
# Verify dependencies
|
25
|
-
assert_contains_exactly [items[1]],
|
25
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_record_dependency_no_self
|
@@ -30,14 +30,14 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
30
30
|
items = [mock, mock]
|
31
31
|
|
32
32
|
# Create
|
33
|
-
|
33
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
34
34
|
|
35
35
|
# Record some dependencies
|
36
|
-
|
37
|
-
|
36
|
+
store.record_dependency(items[0], items[0])
|
37
|
+
store.record_dependency(items[0], items[1])
|
38
38
|
|
39
39
|
# Verify dependencies
|
40
|
-
assert_contains_exactly [items[1]],
|
40
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_record_dependency_no_doubles
|
@@ -45,15 +45,15 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
45
45
|
items = [mock, mock]
|
46
46
|
|
47
47
|
# Create
|
48
|
-
|
48
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
49
49
|
|
50
50
|
# Record some dependencies
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
store.record_dependency(items[0], items[1])
|
52
|
+
store.record_dependency(items[0], items[1])
|
53
|
+
store.record_dependency(items[0], items[1])
|
54
54
|
|
55
55
|
# Verify dependencies
|
56
|
-
assert_contains_exactly [items[1]],
|
56
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_objects_causing_outdatedness_of
|
@@ -61,14 +61,14 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
61
61
|
items = [mock, mock, mock]
|
62
62
|
|
63
63
|
# Create
|
64
|
-
|
64
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
65
65
|
|
66
66
|
# Record some dependencies
|
67
|
-
|
68
|
-
|
67
|
+
store.record_dependency(items[0], items[1])
|
68
|
+
store.record_dependency(items[1], items[2])
|
69
69
|
|
70
70
|
# Verify dependencies
|
71
|
-
assert_contains_exactly [items[1]],
|
71
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_objects_outdated_due_to
|
@@ -76,14 +76,14 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
76
76
|
items = [mock, mock, mock]
|
77
77
|
|
78
78
|
# Create
|
79
|
-
|
79
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
80
80
|
|
81
81
|
# Record some dependencies
|
82
|
-
|
83
|
-
|
82
|
+
store.record_dependency(items[0], items[1])
|
83
|
+
store.record_dependency(items[1], items[2])
|
84
84
|
|
85
85
|
# Verify dependencies
|
86
|
-
assert_contains_exactly [items[0]],
|
86
|
+
assert_contains_exactly [items[0]], store.objects_outdated_due_to(items[1])
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_start_and_stop
|
@@ -91,19 +91,20 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
91
91
|
items = [mock, mock]
|
92
92
|
|
93
93
|
# Create
|
94
|
-
|
94
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
95
|
+
tracker = Nanoc::Int::DependencyTracker.new(store)
|
95
96
|
|
96
97
|
# Start, do something and stop
|
97
|
-
tracker.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
tracker.run do
|
99
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, items[0])
|
100
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, items[1])
|
101
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, items[1])
|
102
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, items[0])
|
103
|
+
end
|
103
104
|
|
104
105
|
# Verify dependencies
|
105
|
-
assert_contains_exactly [items[1]],
|
106
|
-
assert_empty
|
106
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
107
|
+
assert_empty store.objects_causing_outdatedness_of(items[1])
|
107
108
|
end
|
108
109
|
|
109
110
|
def test_store_graph_and_load_graph_simple
|
@@ -116,28 +117,28 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
116
117
|
items[3].stubs(:reference).returns([:item, '/ddd/'])
|
117
118
|
|
118
119
|
# Create
|
119
|
-
|
120
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
120
121
|
|
121
122
|
# Record some dependencies
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
store.record_dependency(items[0], items[1])
|
124
|
+
store.record_dependency(items[1], items[2])
|
125
|
+
store.record_dependency(items[1], items[3])
|
125
126
|
|
126
127
|
# Store
|
127
|
-
|
128
|
-
assert File.file?(
|
128
|
+
store.store
|
129
|
+
assert File.file?(store.filename)
|
129
130
|
|
130
131
|
# Re-create
|
131
|
-
|
132
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
132
133
|
|
133
134
|
# Load
|
134
|
-
|
135
|
+
store.load
|
135
136
|
|
136
137
|
# Check loaded graph
|
137
|
-
assert_contains_exactly [items[1]],
|
138
|
-
assert_contains_exactly [items[2], items[3]],
|
139
|
-
assert_empty
|
140
|
-
assert_empty
|
138
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
139
|
+
assert_contains_exactly [items[2], items[3]], store.objects_causing_outdatedness_of(items[1])
|
140
|
+
assert_empty store.objects_causing_outdatedness_of(items[2])
|
141
|
+
assert_empty store.objects_causing_outdatedness_of(items[3])
|
141
142
|
end
|
142
143
|
|
143
144
|
def test_store_graph_and_load_graph_with_removed_items
|
@@ -154,27 +155,27 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
154
155
|
new_items = [items[0], items[1], items[2]]
|
155
156
|
|
156
157
|
# Create
|
157
|
-
|
158
|
+
store = Nanoc::Int::DependencyStore.new(old_items)
|
158
159
|
|
159
160
|
# Record some dependencies
|
160
|
-
|
161
|
-
|
162
|
-
|
161
|
+
store.record_dependency(old_items[0], old_items[1])
|
162
|
+
store.record_dependency(old_items[1], old_items[2])
|
163
|
+
store.record_dependency(old_items[1], old_items[3])
|
163
164
|
|
164
165
|
# Store
|
165
|
-
|
166
|
-
assert File.file?(
|
166
|
+
store.store
|
167
|
+
assert File.file?(store.filename)
|
167
168
|
|
168
169
|
# Re-create
|
169
|
-
|
170
|
+
store = Nanoc::Int::DependencyStore.new(new_items)
|
170
171
|
|
171
172
|
# Load
|
172
|
-
|
173
|
+
store.load
|
173
174
|
|
174
175
|
# Check loaded graph
|
175
|
-
assert_contains_exactly [items[1]],
|
176
|
-
assert_contains_exactly [items[2], nil],
|
177
|
-
assert_empty
|
176
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
177
|
+
assert_contains_exactly [items[2], nil], store.objects_causing_outdatedness_of(items[1])
|
178
|
+
assert_empty store.objects_causing_outdatedness_of(items[2])
|
178
179
|
end
|
179
180
|
|
180
181
|
def test_store_graph_with_nils_in_dst
|
@@ -186,25 +187,25 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
186
187
|
items[2].stubs(:reference).returns([:item, '/ccc/'])
|
187
188
|
|
188
189
|
# Create
|
189
|
-
|
190
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
190
191
|
|
191
192
|
# Record some dependencies
|
192
|
-
|
193
|
-
|
193
|
+
store.record_dependency(items[0], items[1])
|
194
|
+
store.record_dependency(items[1], nil)
|
194
195
|
|
195
196
|
# Store
|
196
|
-
|
197
|
-
assert File.file?(
|
197
|
+
store.store
|
198
|
+
assert File.file?(store.filename)
|
198
199
|
|
199
200
|
# Re-create
|
200
|
-
|
201
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
201
202
|
|
202
203
|
# Load
|
203
|
-
|
204
|
+
store.load
|
204
205
|
|
205
206
|
# Check loaded graph
|
206
|
-
assert_contains_exactly [items[1]],
|
207
|
-
assert_contains_exactly [nil],
|
207
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
208
|
+
assert_contains_exactly [nil], store.objects_causing_outdatedness_of(items[1])
|
208
209
|
end
|
209
210
|
|
210
211
|
def test_store_graph_with_nils_in_src
|
@@ -216,25 +217,25 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
216
217
|
items[2].stubs(:reference).returns([:item, '/ccc/'])
|
217
218
|
|
218
219
|
# Create
|
219
|
-
|
220
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
220
221
|
|
221
222
|
# Record some dependencies
|
222
|
-
|
223
|
-
|
223
|
+
store.record_dependency(items[0], items[1])
|
224
|
+
store.record_dependency(nil, items[2])
|
224
225
|
|
225
226
|
# Store
|
226
|
-
|
227
|
-
assert File.file?(
|
227
|
+
store.store
|
228
|
+
assert File.file?(store.filename)
|
228
229
|
|
229
230
|
# Re-create
|
230
|
-
|
231
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
231
232
|
|
232
233
|
# Load
|
233
|
-
|
234
|
+
store.load
|
234
235
|
|
235
236
|
# Check loaded graph
|
236
|
-
assert_contains_exactly [items[1]],
|
237
|
-
assert_empty
|
237
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
238
|
+
assert_empty store.objects_causing_outdatedness_of(items[1])
|
238
239
|
end
|
239
240
|
|
240
241
|
def test_forget_dependencies_for
|
@@ -242,15 +243,15 @@ class Nanoc::Int::DependencyTrackerTest < Nanoc::TestCase
|
|
242
243
|
items = [mock, mock, mock]
|
243
244
|
|
244
245
|
# Create
|
245
|
-
|
246
|
+
store = Nanoc::Int::DependencyStore.new(items)
|
246
247
|
|
247
248
|
# Record some dependencies
|
248
|
-
|
249
|
-
|
250
|
-
assert_contains_exactly [items[1]],
|
249
|
+
store.record_dependency(items[0], items[1])
|
250
|
+
store.record_dependency(items[1], items[2])
|
251
|
+
assert_contains_exactly [items[1]], store.objects_causing_outdatedness_of(items[0])
|
251
252
|
|
252
253
|
# Forget dependencies
|
253
|
-
|
254
|
-
assert_empty
|
254
|
+
store.forget_dependencies_for(items[0])
|
255
|
+
assert_empty store.objects_causing_outdatedness_of(items[0])
|
255
256
|
end
|
256
257
|
end
|