nanoc 4.1.6 → 4.2.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -1
- data/NEWS.md +11 -4
- data/lib/nanoc/base/checksummer.rb +135 -46
- data/lib/nanoc/base/compilation/compiler.rb +18 -28
- data/lib/nanoc/base/compilation/dependency_tracker.rb +22 -32
- data/lib/nanoc/base/compilation/filter.rb +2 -4
- data/lib/nanoc/base/entities.rb +1 -0
- data/lib/nanoc/base/entities/content.rb +14 -3
- data/lib/nanoc/base/entities/document.rb +14 -6
- data/lib/nanoc/base/entities/item.rb +0 -31
- data/lib/nanoc/base/entities/item_rep.rb +1 -1
- data/lib/nanoc/base/entities/lazy_value.rb +36 -0
- data/lib/nanoc/base/entities/pattern.rb +3 -2
- data/lib/nanoc/base/entities/site.rb +2 -0
- data/lib/nanoc/base/memoization.rb +17 -10
- data/lib/nanoc/base/repos/compiled_content_cache.rb +1 -1
- data/lib/nanoc/base/repos/data_source.rb +10 -6
- data/lib/nanoc/base/services/executor.rb +22 -22
- data/lib/nanoc/base/services/item_rep_router.rb +4 -5
- data/lib/nanoc/base/views.rb +0 -1
- data/lib/nanoc/base/views/item_rep_view.rb +3 -9
- data/lib/nanoc/base/views/mixins/document_view_mixin.rb +4 -11
- data/lib/nanoc/base/views/view.rb +1 -0
- data/lib/nanoc/base/views/view_context.rb +5 -1
- data/lib/nanoc/cli/commands/compile.rb +0 -6
- data/lib/nanoc/data_sources.rb +5 -5
- data/lib/nanoc/data_sources/filesystem.rb +219 -90
- data/lib/nanoc/extra/checking/check.rb +1 -2
- data/lib/nanoc/extra/checking/checks.rb +2 -0
- data/lib/nanoc/extra/checking/checks/css.rb +6 -14
- data/lib/nanoc/extra/checking/checks/html.rb +6 -14
- data/lib/nanoc/extra/checking/checks/internal_links.rb +14 -3
- data/lib/nanoc/extra/checking/checks/w3c_validator.rb +28 -0
- data/lib/nanoc/extra/deployers/fog.rb +134 -78
- data/lib/nanoc/extra/link_collector.rb +14 -18
- data/lib/nanoc/filters/sass.rb +3 -3
- data/lib/nanoc/helpers.rb +1 -0
- data/lib/nanoc/helpers/capturing.rb +16 -58
- data/lib/nanoc/helpers/child_parent.rb +51 -0
- data/lib/nanoc/helpers/filtering.rb +0 -1
- data/lib/nanoc/helpers/html_escape.rb +5 -0
- data/lib/nanoc/helpers/link_to.rb +2 -0
- data/lib/nanoc/helpers/rendering.rb +3 -4
- data/lib/nanoc/rule_dsl/action_provider.rb +20 -4
- data/lib/nanoc/rule_dsl/recording_executor.rb +3 -1
- data/lib/nanoc/rule_dsl/rule_context.rb +0 -1
- data/lib/nanoc/rule_dsl/rule_memory_calculator.rb +4 -1
- data/lib/nanoc/spec.rb +217 -0
- data/lib/nanoc/version.rb +1 -1
- data/test/base/test_data_source.rb +4 -2
- data/test/base/test_dependency_tracker.rb +5 -11
- data/test/data_sources/test_filesystem.rb +605 -69
- data/test/extra/checking/checks/test_internal_links.rb +25 -0
- data/test/extra/deployers/test_fog.rb +0 -177
- data/test/filters/test_less.rb +9 -4
- data/test/helpers/test_capturing.rb +38 -212
- data/test/helpers/test_link_to.rb +0 -205
- data/test/helpers/test_xml_sitemap.rb +2 -1
- metadata +7 -12
- data/lib/nanoc/base/views/site_view.rb +0 -14
- data/lib/nanoc/data_sources/filesystem_unified.rb +0 -101
- data/test/data_sources/test_filesystem_unified.rb +0 -559
- data/test/helpers/test_breadcrumbs.rb +0 -60
- data/test/helpers/test_filtering.rb +0 -112
- data/test/helpers/test_html_escape.rb +0 -26
- data/test/helpers/test_rendering.rb +0 -147
- data/test/helpers/test_tagging.rb +0 -92
- data/test/helpers/test_text.rb +0 -18
@@ -63,6 +63,31 @@ class Nanoc::Extra::Checking::Checks::InternalLinksTest < Nanoc::TestCase
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
def test_exclude_targets
|
67
|
+
with_site do |site|
|
68
|
+
# Create check
|
69
|
+
check = Nanoc::Extra::Checking::Checks::InternalLinks.create(site)
|
70
|
+
site.config.update({ checks: { internal_links: { exclude_targets: ['^/excluded\d+'] } } })
|
71
|
+
|
72
|
+
# Test
|
73
|
+
assert check.send(:valid?, '/excluded1', 'output/origin')
|
74
|
+
assert check.send(:valid?, '/excluded2', 'output/origin')
|
75
|
+
assert !check.send(:valid?, '/excluded_not', 'output/origin')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_exclude_origins
|
80
|
+
with_site do |site|
|
81
|
+
# Create check
|
82
|
+
check = Nanoc::Extra::Checking::Checks::InternalLinks.create(site)
|
83
|
+
site.config.update({ checks: { internal_links: { exclude_origins: ['^/excluded'] } } })
|
84
|
+
|
85
|
+
# Test
|
86
|
+
assert check.send(:valid?, '/foo', 'output/excluded')
|
87
|
+
assert !check.send(:valid?, '/foo', 'output/not_excluded')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
66
91
|
def test_unescape_url
|
67
92
|
with_site do |site|
|
68
93
|
FileUtils.mkdir_p('output/stuff')
|
@@ -1,181 +1,4 @@
|
|
1
1
|
class Nanoc::Extra::Deployers::FogTest < Nanoc::TestCase
|
2
|
-
def test_run
|
3
|
-
if_have 'fog' do
|
4
|
-
# Create deployer
|
5
|
-
fog = Nanoc::Extra::Deployers::Fog.new(
|
6
|
-
'output/',
|
7
|
-
{
|
8
|
-
bucket: 'mybucket',
|
9
|
-
provider: 'local',
|
10
|
-
local_root: 'mylocalcloud' })
|
11
|
-
|
12
|
-
# Create site
|
13
|
-
FileUtils.mkdir_p('output')
|
14
|
-
File.open('output/meow', 'w') { |io| io.write 'I am a cat!' }
|
15
|
-
File.open('output/bark', 'w') { |io| io.write 'I am a dog!' }
|
16
|
-
|
17
|
-
# Create local cloud (but not bucket)
|
18
|
-
FileUtils.mkdir_p('mylocalcloud')
|
19
|
-
|
20
|
-
# Run
|
21
|
-
fog.run
|
22
|
-
|
23
|
-
# Check
|
24
|
-
assert File.file?('mylocalcloud/mybucket/meow')
|
25
|
-
assert File.file?('mylocalcloud/mybucket/bark')
|
26
|
-
assert_equal 'I am a cat!', File.read('mylocalcloud/mybucket/meow')
|
27
|
-
assert_equal 'I am a dog!', File.read('mylocalcloud/mybucket/bark')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_run_with_dry_run
|
32
|
-
if_have 'fog' do
|
33
|
-
begin
|
34
|
-
# Create deployer
|
35
|
-
fog = Nanoc::Extra::Deployers::Fog.new(
|
36
|
-
'output/',
|
37
|
-
{
|
38
|
-
provider: 'aws',
|
39
|
-
# FIXME: bucket is necessary for deployer but fog doesn't like it
|
40
|
-
bucket_name: 'doesntmatter',
|
41
|
-
aws_access_key_id: 'meh',
|
42
|
-
aws_secret_access_key: 'dontcare',
|
43
|
-
},
|
44
|
-
dry_run: true,
|
45
|
-
)
|
46
|
-
|
47
|
-
# Create site
|
48
|
-
FileUtils.mkdir_p('output')
|
49
|
-
File.open('output/meow', 'w') { |io| io.write 'I am a cat!' }
|
50
|
-
File.open('output/bark', 'w') { |io| io.write 'I am a dog!' }
|
51
|
-
|
52
|
-
# Create local cloud (but not bucket)
|
53
|
-
FileUtils.mkdir_p('mylocalcloud')
|
54
|
-
|
55
|
-
# Run
|
56
|
-
fog.run
|
57
|
-
ensure
|
58
|
-
# FIXME: ugly hack
|
59
|
-
::Fog.instance_eval { @mocking = false }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_run_cdn_with_dry_run
|
65
|
-
if_have 'fog' do
|
66
|
-
begin
|
67
|
-
# Create deployer
|
68
|
-
fog = Nanoc::Extra::Deployers::Fog.new(
|
69
|
-
'output/',
|
70
|
-
{
|
71
|
-
provider: 'aws',
|
72
|
-
cdn_id: 'id-cdn',
|
73
|
-
# FIXME: bucket is necessary for deployer but fog doesn't like it
|
74
|
-
bucket_name: 'doesntmatter',
|
75
|
-
aws_access_key_id: 'meh',
|
76
|
-
aws_secret_access_key: 'dontcare',
|
77
|
-
},
|
78
|
-
dry_run: true,
|
79
|
-
)
|
80
|
-
|
81
|
-
# Create site
|
82
|
-
FileUtils.mkdir_p('output')
|
83
|
-
File.open('output/meow', 'w') { |io| io.write 'I am a cat!' }
|
84
|
-
File.open('output/bark', 'w') { |io| io.write 'I am a dog!' }
|
85
|
-
|
86
|
-
# Create local cloud (but not bucket)
|
87
|
-
FileUtils.mkdir_p('mylocalcloud')
|
88
|
-
|
89
|
-
# Run
|
90
|
-
fog.run
|
91
|
-
ensure
|
92
|
-
# HACK: (
|
93
|
-
::Fog.instance_eval { @mocking = false }
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_run_delete_stray
|
99
|
-
if_have 'fog' do
|
100
|
-
# Create deployer
|
101
|
-
fog = Nanoc::Extra::Deployers::Fog.new(
|
102
|
-
'output/',
|
103
|
-
{
|
104
|
-
bucket: 'mybucket',
|
105
|
-
provider: 'local',
|
106
|
-
local_root: 'mylocalcloud',
|
107
|
-
},
|
108
|
-
)
|
109
|
-
|
110
|
-
# Setup fake local cloud
|
111
|
-
FileUtils.mkdir_p('mylocalcloud/mybucket')
|
112
|
-
File.open('mylocalcloud/mybucket/etc', 'w') { |io| io.write('meh-etc') }
|
113
|
-
File.open('mylocalcloud/mybucket/meow', 'w') { |io| io.write('meh-meow') }
|
114
|
-
File.open('mylocalcloud/mybucket/bark', 'w') { |io| io.write('meh-bark') }
|
115
|
-
|
116
|
-
# Create site
|
117
|
-
FileUtils.mkdir_p('output')
|
118
|
-
File.open('output/meow', 'w') { |io| io.write 'I am a cat!' }
|
119
|
-
File.open('output/bark', 'w') { |io| io.write 'I am a dog!' }
|
120
|
-
|
121
|
-
# Create local cloud (but not bucket)
|
122
|
-
FileUtils.mkdir_p('mylocalcloud')
|
123
|
-
|
124
|
-
# Run
|
125
|
-
fog.run
|
126
|
-
|
127
|
-
# Check
|
128
|
-
refute File.file?('mylocalcloud/mybucket/etc')
|
129
|
-
assert File.file?('mylocalcloud/mybucket/meow')
|
130
|
-
assert File.file?('mylocalcloud/mybucket/bark')
|
131
|
-
assert_equal 'I am a cat!', File.read('mylocalcloud/mybucket/meow')
|
132
|
-
assert_equal 'I am a dog!', File.read('mylocalcloud/mybucket/bark')
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_upload
|
137
|
-
if_have 'fog' do
|
138
|
-
fog = Nanoc::Extra::Deployers::Fog.new(
|
139
|
-
'output/', provider: 'aws')
|
140
|
-
|
141
|
-
key_old = '__old'
|
142
|
-
key_same = '__same'
|
143
|
-
key_new = '__new'
|
144
|
-
|
145
|
-
File.write(key_same, 'hallo')
|
146
|
-
File.write(key_new, 'hallo new')
|
147
|
-
|
148
|
-
etags = {
|
149
|
-
key_same => '598d4c200461b81522a3328565c25f7c',
|
150
|
-
key_new => '598d4c200461b81522a3328565c25f7c',
|
151
|
-
}
|
152
|
-
|
153
|
-
keys_to_destroy = [key_old, key_same, key_new]
|
154
|
-
keys_to_invalidate = []
|
155
|
-
|
156
|
-
s3_files = mock
|
157
|
-
s3_files.stubs(:create)
|
158
|
-
s3_directory = mock
|
159
|
-
s3_directory.stubs(:files).returns(s3_files)
|
160
|
-
|
161
|
-
# key_same
|
162
|
-
refute fog.send(:needs_upload?, key_same, key_same, etags)
|
163
|
-
fog.send(
|
164
|
-
:upload, key_same, key_same, etags, keys_to_destroy, keys_to_invalidate, s3_directory)
|
165
|
-
|
166
|
-
assert_equal([key_old, key_new], keys_to_destroy)
|
167
|
-
assert_equal([], keys_to_invalidate)
|
168
|
-
|
169
|
-
# key_new
|
170
|
-
assert fog.send(:needs_upload?, key_new, key_new, etags)
|
171
|
-
fog.send(
|
172
|
-
:upload, key_new, key_new, etags, keys_to_destroy, keys_to_invalidate, s3_directory)
|
173
|
-
|
174
|
-
assert_equal([key_old], keys_to_destroy)
|
175
|
-
assert_equal([key_new], keys_to_invalidate)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
2
|
def test_read_etags_with_local_provider
|
180
3
|
if_have 'fog' do
|
181
4
|
fog = Nanoc::Extra::Deployers::Fog.new(
|
data/test/filters/test_less.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
class Nanoc::Filters::LessTest < Nanoc::TestCase
|
2
|
+
def view_context
|
3
|
+
dependency_tracker = Nanoc::Int::DependencyTracker.new(nil)
|
4
|
+
Nanoc::ViewContext.new(reps: nil, items: nil, dependency_tracker: dependency_tracker, compiler: nil)
|
5
|
+
end
|
6
|
+
|
2
7
|
def test_filter
|
3
8
|
if_have 'less' do
|
4
9
|
# Create item
|
5
|
-
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'),
|
10
|
+
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'), view_context)
|
6
11
|
|
7
12
|
# Create filter
|
8
13
|
filter = ::Nanoc::Filters::Less.new(item: @item, items: [@item])
|
@@ -20,7 +25,7 @@ class Nanoc::Filters::LessTest < Nanoc::TestCase
|
|
20
25
|
File.open('content/foo/bar/imported_file.less', 'w') { |io| io.write('p { color: red; }') }
|
21
26
|
|
22
27
|
# Create item
|
23
|
-
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'),
|
28
|
+
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'), view_context)
|
24
29
|
|
25
30
|
# Create filter
|
26
31
|
filter = ::Nanoc::Filters::Less.new(item: @item, items: [@item])
|
@@ -39,7 +44,7 @@ class Nanoc::Filters::LessTest < Nanoc::TestCase
|
|
39
44
|
|
40
45
|
# Create item
|
41
46
|
File.open('content/foo/bar.txt', 'w') { |io| io.write('meh') }
|
42
|
-
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'),
|
47
|
+
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'), view_context)
|
43
48
|
|
44
49
|
# Create filter
|
45
50
|
filter = ::Nanoc::Filters::Less.new(item: @item, items: [@item])
|
@@ -108,7 +113,7 @@ class Nanoc::Filters::LessTest < Nanoc::TestCase
|
|
108
113
|
def test_compression
|
109
114
|
if_have 'less' do
|
110
115
|
# Create item
|
111
|
-
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'),
|
116
|
+
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('blah', { content_filename: 'content/foo/bar.txt' }, '/foo/bar/'), view_context)
|
112
117
|
|
113
118
|
# Create filter
|
114
119
|
filter = ::Nanoc::Filters::Less.new(item: @item, items: [@item])
|
@@ -1,49 +1,49 @@
|
|
1
1
|
class Nanoc::Helpers::CapturingTest < Nanoc::TestCase
|
2
2
|
include Nanoc::Helpers::Capturing
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
File.open('Rules', 'w') do |io|
|
8
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
9
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
4
|
+
def item_rep_repo_for(item)
|
5
|
+
Nanoc::Int::ItemRepRepo.new.tap do |repo|
|
6
|
+
repo << Nanoc::Int::ItemRep.new(item, :default)
|
10
7
|
end
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
item = Nanoc::Int::Item.new('moo', {}, '/blah/')
|
20
|
-
@site = Nanoc::SiteView.new(Nanoc::Int::SiteLoader.new.new_empty, nil)
|
21
|
-
@item = Nanoc::ItemWithRepsView.new(item, nil)
|
22
|
-
|
23
|
-
# Evaluate content
|
24
|
-
result = ::ERB.new(content).result(binding)
|
25
|
-
|
26
|
-
# Check
|
27
|
-
assert_equal '3', content_for(@item, :sidebar).strip
|
28
|
-
assert_match(/^head\s+foot$/, result)
|
10
|
+
def view_context_for(item)
|
11
|
+
Nanoc::ViewContext.new(
|
12
|
+
reps: item_rep_repo_for(item),
|
13
|
+
items: :__irrelevant__,
|
14
|
+
dependency_tracker: :__irrelevant__,
|
15
|
+
compiler: :__irrelevant__,
|
16
|
+
)
|
29
17
|
end
|
30
18
|
|
31
|
-
def
|
32
|
-
|
19
|
+
def test_dependencies
|
20
|
+
with_site do |_site|
|
21
|
+
# Prepare
|
22
|
+
File.open('lib/helpers.rb', 'w') do |io|
|
23
|
+
io.write 'include Nanoc::Helpers::Capturing'
|
24
|
+
end
|
25
|
+
File.open('content/includer.erb', 'w') do |io|
|
26
|
+
io.write '[<%= content_for(@items.find { |i| i.identifier == \'/includee/\' }, :blah) %>]'
|
27
|
+
end
|
28
|
+
File.open('Rules', 'w') do |io|
|
29
|
+
io.write "compile '*' do ; filter :erb ; end\n"
|
30
|
+
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# Compile once
|
34
|
+
File.open('content/includee.erb', 'w') do |io|
|
35
|
+
io.write '{<% content_for :blah do %>Old content<% end %>}'
|
36
|
+
end
|
37
|
+
Nanoc::CLI.run(%w(compile))
|
38
|
+
assert_equal '[Old content]', File.read('output/includer/index.html')
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
# Compile again
|
41
|
+
File.open('content/includee.erb', 'w') do |io|
|
42
|
+
io.write '{<% content_for :blah do %>New content<% end %>}'
|
43
|
+
end
|
44
|
+
Nanoc::CLI.run(%w(compile))
|
45
|
+
assert_equal '[New content]', File.read('output/includer/index.html')
|
42
46
|
end
|
43
|
-
|
44
|
-
# Check
|
45
|
-
assert_equal 'foo', _erbout
|
46
|
-
assert_equal 'bar', captured_content
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_content_for_recursively
|
@@ -66,8 +66,8 @@ head
|
|
66
66
|
foot
|
67
67
|
EOS
|
68
68
|
|
69
|
-
|
70
|
-
@item = Nanoc::ItemWithRepsView.new(
|
69
|
+
item = Nanoc::Int::Item.new('content', {}, '/')
|
70
|
+
@item = Nanoc::ItemWithRepsView.new(item, view_context_for(item))
|
71
71
|
|
72
72
|
result = ::ERB.new(content).result(binding)
|
73
73
|
|
@@ -76,180 +76,6 @@ EOS
|
|
76
76
|
assert_equal expected, actual
|
77
77
|
end
|
78
78
|
|
79
|
-
def test_different_sites
|
80
|
-
require 'erb'
|
81
|
-
|
82
|
-
File.open('Rules', 'w') do |io|
|
83
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
84
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
85
|
-
end
|
86
|
-
|
87
|
-
@site = Nanoc::SiteView.new(Nanoc::Int::SiteLoader.new.new_empty, nil)
|
88
|
-
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('content', {}, '/'), nil)
|
89
|
-
content = '<% content_for :a do %>Content One<% end %>'
|
90
|
-
::ERB.new(content).result(binding)
|
91
|
-
|
92
|
-
assert_equal 'Content One', content_for(@item, :a)
|
93
|
-
assert_equal nil, content_for(@item, :b)
|
94
|
-
|
95
|
-
@site = Nanoc::SiteView.new(Nanoc::Int::SiteLoader.new.new_empty, nil)
|
96
|
-
@item = Nanoc::ItemWithRepsView.new(Nanoc::Int::Item.new('content', {}, '/'), nil)
|
97
|
-
content = '<% content_for :b do %>Content Two<% end %>'
|
98
|
-
::ERB.new(content).result(binding)
|
99
|
-
|
100
|
-
assert_equal nil, content_for(@item, :a)
|
101
|
-
assert_equal 'Content Two', content_for(@item, :b)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_content_for_with_existing_symbol
|
105
|
-
with_site do |_site|
|
106
|
-
# Prepare
|
107
|
-
File.open('lib/helpers.rb', 'w') do |io|
|
108
|
-
io.write 'include Nanoc::Helpers::Capturing'
|
109
|
-
end
|
110
|
-
File.open('content/includer.erb', 'w') do |io|
|
111
|
-
io.write '[<%= content_for(@items["/includee/"], :blah) %>]'
|
112
|
-
end
|
113
|
-
File.open('Rules', 'w') do |io|
|
114
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
115
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
116
|
-
end
|
117
|
-
|
118
|
-
File.open('content/includee.erb', 'w') do |io|
|
119
|
-
io.write '{<% content_for :blah do %>First content<% end %><% content_for :blah do %>Second content<% end %>}'
|
120
|
-
end
|
121
|
-
|
122
|
-
# Using the same symbols twice now raises an error, to be changed to concatenating in a future version
|
123
|
-
assert_raises do
|
124
|
-
Nanoc::CLI.run(%w(compile))
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_content_for_with_existing_symbol_with_error_option
|
130
|
-
with_site do |_site|
|
131
|
-
# Prepare
|
132
|
-
File.open('lib/helpers.rb', 'w') do |io|
|
133
|
-
io.write 'include Nanoc::Helpers::Capturing'
|
134
|
-
end
|
135
|
-
File.open('content/includer.erb', 'w') do |io|
|
136
|
-
io.write '[<%= content_for(@items["/includee/"], :blah) %>]'
|
137
|
-
end
|
138
|
-
File.open('Rules', 'w') do |io|
|
139
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
140
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
141
|
-
end
|
142
|
-
|
143
|
-
File.open('content/includee.erb', 'w') do |io|
|
144
|
-
io.write '{<% content_for :blah do %>First content<% end %><% content_for :blah, existing: :error do %>Second content<% end %>}'
|
145
|
-
end
|
146
|
-
|
147
|
-
assert_raises do
|
148
|
-
Nanoc::CLI.run(%w(compile))
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_content_for_with_existing_symbol_with_overwrite_option
|
154
|
-
with_site do |_site|
|
155
|
-
# Prepare
|
156
|
-
File.open('lib/helpers.rb', 'w') do |io|
|
157
|
-
io.write 'include Nanoc::Helpers::Capturing'
|
158
|
-
end
|
159
|
-
File.open('content/includer.erb', 'w') do |io|
|
160
|
-
io.write '[<%= content_for(@items["/includee/"], :blah) %>]'
|
161
|
-
end
|
162
|
-
File.open('Rules', 'w') do |io|
|
163
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
164
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
165
|
-
end
|
166
|
-
|
167
|
-
File.open('content/includee.erb', 'w') do |io|
|
168
|
-
io.write '{<% content_for :blah do %>First content<% end %><% content_for :blah, existing: :overwrite do %>Second content<% end %>}'
|
169
|
-
end
|
170
|
-
|
171
|
-
Nanoc::CLI.run(%w(compile))
|
172
|
-
assert_equal '[Second content]', File.read('output/includer/index.html')
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_content_for_with_existing_symbol_with_append_option
|
177
|
-
with_site do |_site|
|
178
|
-
# Prepare
|
179
|
-
File.open('lib/helpers.rb', 'w') do |io|
|
180
|
-
io.write 'include Nanoc::Helpers::Capturing'
|
181
|
-
end
|
182
|
-
File.open('content/includer.erb', 'w') do |io|
|
183
|
-
io.write '[<%= content_for(@items["/includee/"], :blah) %>]'
|
184
|
-
end
|
185
|
-
File.open('Rules', 'w') do |io|
|
186
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
187
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
188
|
-
end
|
189
|
-
|
190
|
-
File.open('content/includee.erb', 'w') do |io|
|
191
|
-
io.write '{<% content_for :blah do %>First content<% end %><% content_for :blah, existing: :append do %>Second content<% end %>}'
|
192
|
-
end
|
193
|
-
|
194
|
-
Nanoc::CLI.run(%w(compile))
|
195
|
-
assert_equal '[First contentSecond content]', File.read('output/includer/index.html')
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_content_for_with_existing_symbol_with_unrecognised_option
|
200
|
-
with_site do |_site|
|
201
|
-
# Prepare
|
202
|
-
File.open('lib/helpers.rb', 'w') do |io|
|
203
|
-
io.write 'include Nanoc::Helpers::Capturing'
|
204
|
-
end
|
205
|
-
File.open('content/includer.erb', 'w') do |io|
|
206
|
-
io.write '[<%= content_for(@items["/includee/"], :blah) %>]'
|
207
|
-
end
|
208
|
-
File.open('Rules', 'w') do |io|
|
209
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
210
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
211
|
-
end
|
212
|
-
|
213
|
-
File.open('content/includee.erb', 'w') do |io|
|
214
|
-
io.write '{<% content_for :blah, existing: :donkey do %>First content<% end %>}'
|
215
|
-
end
|
216
|
-
|
217
|
-
assert_raises(ArgumentError) do
|
218
|
-
Nanoc::CLI.run(%w(compile))
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_dependencies
|
224
|
-
with_site do |_site|
|
225
|
-
# Prepare
|
226
|
-
File.open('lib/helpers.rb', 'w') do |io|
|
227
|
-
io.write 'include Nanoc::Helpers::Capturing'
|
228
|
-
end
|
229
|
-
File.open('content/includer.erb', 'w') do |io|
|
230
|
-
io.write '[<%= content_for(@items.find { |i| i.identifier == \'/includee/\' }, :blah) %>]'
|
231
|
-
end
|
232
|
-
File.open('Rules', 'w') do |io|
|
233
|
-
io.write "compile '*' do ; filter :erb ; end\n"
|
234
|
-
io.write "route '*' do ; item.identifier + 'index.html' ; end\n"
|
235
|
-
end
|
236
|
-
|
237
|
-
# Compile once
|
238
|
-
File.open('content/includee.erb', 'w') do |io|
|
239
|
-
io.write '{<% content_for :blah do %>Old content<% end %>}'
|
240
|
-
end
|
241
|
-
Nanoc::CLI.run(%w(compile))
|
242
|
-
assert_equal '[Old content]', File.read('output/includer/index.html')
|
243
|
-
|
244
|
-
# Compile again
|
245
|
-
File.open('content/includee.erb', 'w') do |io|
|
246
|
-
io.write '{<% content_for :blah do %>New content<% end %>}'
|
247
|
-
end
|
248
|
-
Nanoc::CLI.run(%w(compile))
|
249
|
-
assert_equal '[New content]', File.read('output/includer/index.html')
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
79
|
def test_dependency_without_item_variable
|
254
80
|
with_site do |_site|
|
255
81
|
# Prepare
|