nanoc3 3.2.0a3 → 3.2.0a4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/LICENSE +1 -1
- data/NEWS.md +23 -4
- data/README.md +7 -0
- data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
- data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
- data/lib/nanoc3/base/compilation/compiler.rb +112 -175
- data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
- data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
- data/lib/nanoc3/base/compilation/filter.rb +4 -3
- data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
- data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
- data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
- data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
- data/lib/nanoc3/base/compilation/rule.rb +3 -1
- data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
- data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
- data/lib/nanoc3/base/core_ext/array.rb +20 -0
- data/lib/nanoc3/base/core_ext/hash.rb +30 -0
- data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc3/base/core_ext/string.rb +12 -0
- data/lib/nanoc3/base/core_ext.rb +1 -0
- data/lib/nanoc3/base/directed_graph.rb +11 -3
- data/lib/nanoc3/base/errors.rb +0 -4
- data/lib/nanoc3/base/memoization.rb +72 -0
- data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
- data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
- data/lib/nanoc3/base/source_data/configuration.rb +20 -0
- data/lib/nanoc3/base/source_data/item.rb +29 -4
- data/lib/nanoc3/base/source_data/layout.rb +20 -1
- data/lib/nanoc3/base/source_data/site.rb +49 -26
- data/lib/nanoc3/base/store.rb +10 -1
- data/lib/nanoc3/base.rb +6 -1
- data/lib/nanoc3/cli/base.rb +20 -7
- data/lib/nanoc3/cli/commands/compile.rb +0 -2
- data/lib/nanoc3/cli/commands/create_site.rb +16 -7
- data/lib/nanoc3/cli/commands/debug.rb +3 -3
- data/lib/nanoc3/cli/commands/view.rb +1 -0
- data/lib/nanoc3/cli/commands/watch.rb +2 -1
- data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
- data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
- data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
- data/lib/nanoc3/data_sources/filesystem.rb +17 -3
- data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
- data/lib/nanoc3/extra/auto_compiler.rb +5 -1
- data/lib/nanoc3/extra/core_ext/time.rb +1 -1
- data/lib/nanoc3/extra/file_proxy.rb +11 -1
- data/lib/nanoc3/extra/validators/links.rb +1 -1
- data/lib/nanoc3/filters/asciidoc.rb +3 -3
- data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
- data/lib/nanoc3/filters/erb.rb +16 -6
- data/lib/nanoc3/filters/erubis.rb +5 -1
- data/lib/nanoc3/filters/haml.rb +2 -1
- data/lib/nanoc3/filters/less.rb +3 -6
- data/lib/nanoc3/filters/mustache.rb +3 -0
- data/lib/nanoc3/filters/redcarpet.rb +27 -0
- data/lib/nanoc3/filters/sass.rb +1 -5
- data/lib/nanoc3/filters/slim.rb +25 -0
- data/lib/nanoc3/filters/typogruby.rb +23 -0
- data/lib/nanoc3/filters.rb +6 -0
- data/lib/nanoc3/helpers/blogging.rb +22 -26
- data/lib/nanoc3/helpers/rendering.rb +1 -1
- data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
- data/lib/nanoc3.rb +24 -3
- data/nanoc3.gemspec +4 -3
- data/tasks/clean.rake +11 -0
- data/tasks/doc.rake +14 -0
- data/tasks/test.rake +38 -0
- data/test/base/core_ext/array_spec.rb +55 -0
- data/test/base/core_ext/hash_spec.rb +82 -0
- data/test/base/core_ext/pathname_spec.rb +29 -0
- data/test/base/core_ext/string_spec.rb +39 -0
- data/test/base/test_checksum_store.rb +37 -0
- data/test/base/test_code_snippet.rb +33 -0
- data/test/base/test_compiler.rb +303 -0
- data/test/base/test_compiler_dsl.rb +156 -0
- data/test/base/test_context.rb +33 -0
- data/test/base/test_data_source.rb +48 -0
- data/test/base/test_dependency_tracker.rb +264 -0
- data/test/base/test_directed_graph.rb +285 -0
- data/test/base/test_filter.rb +85 -0
- data/test/base/test_item.rb +164 -0
- data/test/base/test_item_rep.rb +555 -0
- data/test/base/test_layout.rb +44 -0
- data/test/base/test_memoization.rb +53 -0
- data/test/base/test_notification_center.rb +36 -0
- data/test/base/test_outdatedness_checker.rb +365 -0
- data/test/base/test_plugin.rb +32 -0
- data/test/base/test_rule.rb +21 -0
- data/test/base/test_rule_context.rb +67 -0
- data/test/base/test_site.rb +144 -0
- data/test/cli/commands/test_compile.rb +12 -0
- data/test/cli/commands/test_create_item.rb +12 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +12 -0
- data/test/cli/commands/test_update.rb +12 -0
- data/test/cli/test_logger.rb +12 -0
- data/test/data_sources/test_filesystem.rb +420 -0
- data/test/data_sources/test_filesystem_unified.rb +562 -0
- data/test/data_sources/test_filesystem_verbose.rb +359 -0
- data/test/extra/core_ext/test_enumerable.rb +32 -0
- data/test/extra/core_ext/test_time.rb +17 -0
- data/test/extra/deployers/test_rsync.rb +234 -0
- data/test/extra/test_auto_compiler.rb +417 -0
- data/test/extra/test_file_proxy.rb +21 -0
- data/test/extra/test_vcs.rb +24 -0
- data/test/extra/validators/test_links.rb +53 -0
- data/test/extra/validators/test_w3c.rb +49 -0
- data/test/filters/test_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +20 -0
- data/test/filters/test_coderay.rb +46 -0
- data/test/filters/test_colorize_syntax.rb +149 -0
- data/test/filters/test_erb.rb +101 -0
- data/test/filters/test_erubis.rb +72 -0
- data/test/filters/test_haml.rb +98 -0
- data/test/filters/test_kramdown.rb +20 -0
- data/test/filters/test_less.rb +59 -0
- data/test/filters/test_markaby.rb +26 -0
- data/test/filters/test_maruku.rb +20 -0
- data/test/filters/test_mustache.rb +27 -0
- data/test/filters/test_rainpress.rb +31 -0
- data/test/filters/test_rdiscount.rb +33 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcarpet.rb +63 -0
- data/test/filters/test_redcloth.rb +35 -0
- data/test/filters/test_relativize_paths.rb +231 -0
- data/test/filters/test_rubypants.rb +20 -0
- data/test/filters/test_sass.rb +103 -0
- data/test/filters/test_slim.rb +37 -0
- data/test/filters/test_typogruby.rb +23 -0
- data/test/helper.rb +161 -0
- data/test/helpers/test_blogging.rb +756 -0
- data/test/helpers/test_breadcrumbs.rb +83 -0
- data/test/helpers/test_capturing.rb +43 -0
- data/test/helpers/test_filtering.rb +108 -0
- data/test/helpers/test_html_escape.rb +34 -0
- data/test/helpers/test_link_to.rb +251 -0
- data/test/helpers/test_rendering.rb +90 -0
- data/test/helpers/test_tagging.rb +89 -0
- data/test/helpers/test_text.rb +26 -0
- data/test/helpers/test_xml_sitemap.rb +105 -0
- data/test/tasks/test_clean.rb +69 -0
- metadata +96 -27
- data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::LayoutTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_initialize
|
10
|
+
# Make sure attributes are cleaned
|
11
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
|
12
|
+
assert_equal({ :foo => 'bar' }, layout.attributes)
|
13
|
+
|
14
|
+
# Make sure identifier is cleaned
|
15
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, 'foo')
|
16
|
+
assert_equal('/foo/', layout.identifier)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_frozen_identifier
|
20
|
+
layout = Nanoc3::Layout.new("foo", {}, '/foo')
|
21
|
+
|
22
|
+
error = assert_raises(RuntimeError) do
|
23
|
+
layout.identifier.chop!
|
24
|
+
end
|
25
|
+
assert_equal "can't modify frozen string", error.message
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_lookup_with_known_attribute
|
29
|
+
# Create layout
|
30
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
|
31
|
+
|
32
|
+
# Check attributes
|
33
|
+
assert_equal('bar', layout[:foo])
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_lookup_with_unknown_attribute
|
37
|
+
# Create layout
|
38
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
|
39
|
+
|
40
|
+
# Check attributes
|
41
|
+
assert_equal(nil, layout[:filter])
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::MemoizationTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
class Sample1
|
10
|
+
|
11
|
+
extend Nanoc3::Memoization
|
12
|
+
|
13
|
+
def initialize(value)
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(n)
|
18
|
+
@value*10 + n
|
19
|
+
end
|
20
|
+
memoize :run
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
class Sample2
|
25
|
+
|
26
|
+
extend Nanoc3::Memoization
|
27
|
+
|
28
|
+
def initialize(value)
|
29
|
+
@value = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def run(n)
|
33
|
+
@value*100 + n
|
34
|
+
end
|
35
|
+
memoize :run
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def test
|
40
|
+
sample1a = Sample1.new(10)
|
41
|
+
sample1b = Sample1.new(15)
|
42
|
+
sample2a = Sample2.new(20)
|
43
|
+
sample2b = Sample2.new(25)
|
44
|
+
|
45
|
+
3.times do
|
46
|
+
assert_equal (10*10+5), sample1a.run(5)
|
47
|
+
assert_equal (10*15+7), sample1b.run(7)
|
48
|
+
assert_equal (100*20+5), sample2a.run(5)
|
49
|
+
assert_equal (100*25+7), sample2b.run(7)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::NotificationCenterTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_post
|
10
|
+
# Set up notification
|
11
|
+
Nanoc3::NotificationCenter.on :ping_received, :test do
|
12
|
+
@ping_received = true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Post
|
16
|
+
@ping_received = false
|
17
|
+
Nanoc3::NotificationCenter.post :ping_received
|
18
|
+
assert(@ping_received)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_remove
|
22
|
+
# Set up notification
|
23
|
+
Nanoc3::NotificationCenter.on :ping_received, :test do
|
24
|
+
@ping_received = true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Remove observer
|
28
|
+
Nanoc3::NotificationCenter.remove :ping_received, :test
|
29
|
+
|
30
|
+
# Post
|
31
|
+
@ping_received = false
|
32
|
+
Nanoc3::NotificationCenter.post :ping_received
|
33
|
+
assert(!@ping_received)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,365 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::OutdatednessCheckerTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_not_outdated
|
10
|
+
# Compile once
|
11
|
+
with_site(:name => 'foo') do |site|
|
12
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
13
|
+
File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
|
14
|
+
|
15
|
+
site.compile
|
16
|
+
end
|
17
|
+
|
18
|
+
# Check
|
19
|
+
with_site(:name => 'foo') do |site|
|
20
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
21
|
+
rep = site.items[0].reps[0]
|
22
|
+
assert_nil outdatedness_checker.outdatedness_reason_for(rep)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_outdated_if_item_checksum_nil
|
27
|
+
# Compile once
|
28
|
+
with_site(:name => 'foo') do |site|
|
29
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
30
|
+
File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
|
31
|
+
|
32
|
+
site.compile
|
33
|
+
end
|
34
|
+
|
35
|
+
# Delete checksums
|
36
|
+
with_site(:name => 'foo') do |site|
|
37
|
+
FileUtils.rm('tmp/checksums')
|
38
|
+
end
|
39
|
+
|
40
|
+
# Check
|
41
|
+
with_site(:name => 'foo') do |site|
|
42
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
43
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
44
|
+
assert_equal ::Nanoc3::OutdatednessReasons::NotEnoughData,
|
45
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_outdated_if_compiled_file_doesnt_exist
|
50
|
+
# Compile once
|
51
|
+
with_site(:name => 'foo') do |site|
|
52
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
53
|
+
File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
|
54
|
+
|
55
|
+
site.compile
|
56
|
+
end
|
57
|
+
|
58
|
+
# Delete old item
|
59
|
+
FileUtils.cd('foo') do
|
60
|
+
FileUtils.rm_rf('output/index.html')
|
61
|
+
end
|
62
|
+
|
63
|
+
# Check
|
64
|
+
with_site(:name => 'foo') do |site|
|
65
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
66
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
67
|
+
assert_equal ::Nanoc3::OutdatednessReasons::NotWritten,
|
68
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_outdated_if_item_checksum_is_different
|
73
|
+
# Compile once
|
74
|
+
with_site(:name => 'foo') do |site|
|
75
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
76
|
+
File.open('content/new.html', 'w') { |io| io.write('o hello too') }
|
77
|
+
File.open('lib/stuff.rb', 'w') { |io| io.write('$foo = 123') }
|
78
|
+
|
79
|
+
site.compile
|
80
|
+
end
|
81
|
+
|
82
|
+
# Create new item
|
83
|
+
FileUtils.cd('foo') do
|
84
|
+
File.open('content/new.html', 'w') { |io| io.write('o hello DIFFERENT!!!') }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Check
|
88
|
+
with_site(:name => 'foo') do |site|
|
89
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
90
|
+
rep = site.items.find { |i| i.identifier == '/new/' }.reps[0]
|
91
|
+
assert_equal ::Nanoc3::OutdatednessReasons::SourceModified,
|
92
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_outdated_if_dependent_layout_outdated
|
97
|
+
# Compile once
|
98
|
+
with_site(:name => 'foo', :compilation_rule_content => 'layout "/default/"', :has_layout => true) do |site|
|
99
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
100
|
+
File.open('layouts/default.html', 'w') { |io| io.write('!!! <%= yield %> !!!') }
|
101
|
+
|
102
|
+
site.compile
|
103
|
+
end
|
104
|
+
|
105
|
+
# Change layout
|
106
|
+
FileUtils.cd('foo') do
|
107
|
+
File.open('layouts/default.html', 'w') { |io| io.write('!!! <%= yield %> !!! different') }
|
108
|
+
end
|
109
|
+
|
110
|
+
# Check
|
111
|
+
with_site(:name => 'foo') do |site|
|
112
|
+
# FIXME ugly fugly hack
|
113
|
+
site.compiler.load
|
114
|
+
|
115
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
116
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
117
|
+
assert_equal ::Nanoc3::OutdatednessReasons::DependenciesOutdated,
|
118
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_outdated_if_dependent_item_outdated
|
123
|
+
# Compile once
|
124
|
+
with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
|
125
|
+
File.open('content/a.html', 'w') do |io|
|
126
|
+
io.write('<%= @items.find { |i| i.identifier == "/b/" }.compiled_content %>')
|
127
|
+
end
|
128
|
+
File.open('content/b.html', 'w') do |io|
|
129
|
+
io.write('stuff')
|
130
|
+
end
|
131
|
+
|
132
|
+
site.compile
|
133
|
+
end
|
134
|
+
|
135
|
+
# Change item
|
136
|
+
FileUtils.cd('foo') do
|
137
|
+
File.open('content/b.html', 'w') do |io|
|
138
|
+
io.write('stuff different!!!')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Check
|
143
|
+
with_site(:name => 'foo') do |site|
|
144
|
+
# FIXME ugly fugly hack
|
145
|
+
site.compiler.load
|
146
|
+
|
147
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
148
|
+
rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
|
149
|
+
assert_equal ::Nanoc3::OutdatednessReasons::DependenciesOutdated,
|
150
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_outdated_if_dependent_item_outdated_chained
|
155
|
+
# Compile once
|
156
|
+
with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
|
157
|
+
File.open('content/a.html', 'w') do |io|
|
158
|
+
io.write('<%= @items.find { |i| i.identifier == "/b/" }.compiled_content %> aaa')
|
159
|
+
end
|
160
|
+
File.open('content/b.html', 'w') do |io|
|
161
|
+
io.write('<%= @items.find { |i| i.identifier == "/c/" }.compiled_content %> bbb')
|
162
|
+
end
|
163
|
+
File.open('content/c.html', 'w') do |io|
|
164
|
+
io.write('stuff')
|
165
|
+
end
|
166
|
+
|
167
|
+
site.compile
|
168
|
+
end
|
169
|
+
|
170
|
+
# Change item
|
171
|
+
FileUtils.cd('foo') do
|
172
|
+
File.open('content/c.html', 'w') do |io|
|
173
|
+
io.write('stuff different!!!')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Check
|
178
|
+
with_site(:name => 'foo') do |site|
|
179
|
+
# FIXME ugly fugly hack
|
180
|
+
site.compiler.load
|
181
|
+
|
182
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
183
|
+
rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
|
184
|
+
assert_equal ::Nanoc3::OutdatednessReasons::DependenciesOutdated,
|
185
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_outdated_if_dependent_item_removed
|
190
|
+
# Compile once
|
191
|
+
with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
|
192
|
+
File.open('content/a.html', 'w') do |io|
|
193
|
+
io.write('<% @items.select { |i| i.identifier != @item.identifier }.each do |i| %>')
|
194
|
+
io.write(' <%= i.compiled_content %>')
|
195
|
+
io.write('<% end %>')
|
196
|
+
end
|
197
|
+
File.open('content/b.html', 'w') do |io|
|
198
|
+
io.write('stuff')
|
199
|
+
end
|
200
|
+
|
201
|
+
site.compile
|
202
|
+
end
|
203
|
+
|
204
|
+
# Delete item
|
205
|
+
FileUtils.cd('foo') do
|
206
|
+
FileUtils.rm_rf('content/b.html')
|
207
|
+
end
|
208
|
+
|
209
|
+
# Check
|
210
|
+
with_site(:name => 'foo') do |site|
|
211
|
+
# FIXME ugly fugly hack
|
212
|
+
site.compiler.load
|
213
|
+
|
214
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
215
|
+
rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
|
216
|
+
assert_equal ::Nanoc3::OutdatednessReasons::DependenciesOutdated,
|
217
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_outdated_if_dependent_item_added
|
222
|
+
# Compile once
|
223
|
+
with_site(:name => 'foo', :compilation_rule_content => 'filter :erb') do |site|
|
224
|
+
File.open('content/a.html', 'w') do |io|
|
225
|
+
io.write('<% @items.select { |i| i.identifier != @item.identifier }.each do |i| %>')
|
226
|
+
io.write(' <%= i.compiled_content %>')
|
227
|
+
io.write('<% end %>')
|
228
|
+
end
|
229
|
+
File.open('content/b.html', 'w') do |io|
|
230
|
+
io.write('stuff')
|
231
|
+
end
|
232
|
+
|
233
|
+
site.compile
|
234
|
+
end
|
235
|
+
|
236
|
+
# Add item
|
237
|
+
FileUtils.cd('foo') do
|
238
|
+
File.open('content/z.html', 'w') do |io|
|
239
|
+
io.write('moar stuff')
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Check
|
244
|
+
with_site(:name => 'foo') do |site|
|
245
|
+
# FIXME ugly fugly hack
|
246
|
+
site.compiler.load
|
247
|
+
|
248
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
249
|
+
rep = site.items.find { |i| i.identifier == '/a/' }.reps[0]
|
250
|
+
assert_equal ::Nanoc3::OutdatednessReasons::DependenciesOutdated,
|
251
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# TODO make sure outdatedness of non-outdated items is correct
|
256
|
+
|
257
|
+
def test_outdated_if_code_snippets_outdated
|
258
|
+
# Compile once
|
259
|
+
with_site(:name => 'foo') do |site|
|
260
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
261
|
+
|
262
|
+
site.compile
|
263
|
+
end
|
264
|
+
|
265
|
+
# Change code
|
266
|
+
FileUtils.cd('foo') do
|
267
|
+
File.open('lib/moo.rb', 'w') { |io| io.write('def moo ; puts "moo" ; end') }
|
268
|
+
end
|
269
|
+
|
270
|
+
# Check
|
271
|
+
with_site(:name => 'foo') do |site|
|
272
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
273
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
274
|
+
assert_equal ::Nanoc3::OutdatednessReasons::CodeSnippetsModified,
|
275
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_outdated_if_config_outdated
|
280
|
+
# Compile once
|
281
|
+
with_site(:name => 'foo') do |site|
|
282
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
283
|
+
|
284
|
+
site.compile
|
285
|
+
end
|
286
|
+
|
287
|
+
# Change code
|
288
|
+
FileUtils.cd('foo') do
|
289
|
+
File.open('config.yaml', 'w') { |io| io.write('awesome: true') }
|
290
|
+
end
|
291
|
+
|
292
|
+
# Check
|
293
|
+
with_site(:name => 'foo') do |site|
|
294
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
295
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
296
|
+
assert_equal ::Nanoc3::OutdatednessReasons::ConfigurationModified,
|
297
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_not_outdated_if_irrelevant_rule_modified
|
302
|
+
# Compile once
|
303
|
+
with_site(:name => 'foo') do |site|
|
304
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
305
|
+
|
306
|
+
site.compile
|
307
|
+
end
|
308
|
+
|
309
|
+
# Change code
|
310
|
+
FileUtils.cd('foo') do
|
311
|
+
File.open('Rules', 'a') { |io| io.write('layout "/moo/", :haml') }
|
312
|
+
end
|
313
|
+
|
314
|
+
# Check
|
315
|
+
with_site(:name => 'foo') do |site|
|
316
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
317
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
318
|
+
assert_nil outdatedness_checker.outdatedness_reason_for(rep)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_outdated_if_relevant_rule_modified
|
323
|
+
# Create site
|
324
|
+
with_site(:name => 'foo') do |site|
|
325
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
326
|
+
File.open('Rules', 'w') do |io|
|
327
|
+
io.write("compile '/' do\n")
|
328
|
+
io.write(" filter :erb\n")
|
329
|
+
io.write("end\n")
|
330
|
+
io.write("\n")
|
331
|
+
io.write("route '/' do\n")
|
332
|
+
io.write(" '/index.html'\n")
|
333
|
+
io.write("end\n")
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
# Compile once
|
338
|
+
FileUtils.cd('foo') do
|
339
|
+
site = Nanoc3::Site.new('.')
|
340
|
+
site.compile
|
341
|
+
end
|
342
|
+
|
343
|
+
# Modify rules
|
344
|
+
FileUtils.cd('foo') do
|
345
|
+
File.open('Rules', 'w') do |io|
|
346
|
+
io.write("compile '/' do\n")
|
347
|
+
io.write("end\n")
|
348
|
+
io.write("\n")
|
349
|
+
io.write("route '/' do\n")
|
350
|
+
io.write(" '/index.html'\n")
|
351
|
+
io.write("end\n")
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
# Check
|
356
|
+
FileUtils.cd('foo') do
|
357
|
+
site = Nanoc3::Site.new('.')
|
358
|
+
outdatedness_checker = site.compiler.send :outdatedness_checker
|
359
|
+
rep = site.items.find { |i| i.identifier == '/' }.reps[0]
|
360
|
+
assert_equal ::Nanoc3::OutdatednessReasons::RulesModified,
|
361
|
+
outdatedness_checker.outdatedness_reason_for(rep)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::PluginTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
class SampleFilter < Nanoc3::Filter
|
10
|
+
identifier :_plugin_test_sample_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_named
|
14
|
+
# Find existant filter
|
15
|
+
filter = Nanoc3::Filter.named(:erb)
|
16
|
+
assert(!filter.nil?)
|
17
|
+
|
18
|
+
# Find non-existant filter
|
19
|
+
filter = Nanoc3::Filter.named(:lksdaffhdlkashlgkskahf)
|
20
|
+
assert(filter.nil?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_register
|
24
|
+
SampleFilter.send(:identifier, :_plugin_test_sample_filter)
|
25
|
+
|
26
|
+
registry = Nanoc3::PluginRegistry.instance
|
27
|
+
filter = registry.find(Nanoc3::Filter, :_plugin_test_sample_filter)
|
28
|
+
|
29
|
+
refute_nil filter
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::RuleTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_initialize
|
10
|
+
# TODO implement
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_applicable_to
|
14
|
+
# TODO implement
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_apply_to
|
18
|
+
# TODO implement
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::RuleContextTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_objects
|
10
|
+
# Mock everything
|
11
|
+
config = mock
|
12
|
+
items = mock
|
13
|
+
layouts = mock
|
14
|
+
site = mock
|
15
|
+
site.stubs(:config).returns(config)
|
16
|
+
site.stubs(:items).returns(items)
|
17
|
+
site.stubs(:layouts).returns(layouts)
|
18
|
+
item = mock
|
19
|
+
item.stubs(:site).returns(site)
|
20
|
+
rep = mock
|
21
|
+
rep.stubs(:item).returns(item)
|
22
|
+
compiler = Nanoc3::Compiler.new(site)
|
23
|
+
|
24
|
+
# Create context
|
25
|
+
@rule_context = Nanoc3::RuleContext.new(:rep => rep, :compiler => compiler)
|
26
|
+
|
27
|
+
# Check
|
28
|
+
assert_equal rep, @rule_context.rep
|
29
|
+
assert_equal item, @rule_context.item
|
30
|
+
assert_equal site, @rule_context.site
|
31
|
+
assert_equal config, @rule_context.config
|
32
|
+
assert_equal layouts, @rule_context.layouts
|
33
|
+
assert_equal items, @rule_context.items
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_actions
|
37
|
+
# Mock everything
|
38
|
+
config = mock
|
39
|
+
items = mock
|
40
|
+
layouts = mock
|
41
|
+
site = mock
|
42
|
+
site.stubs(:config).returns(config)
|
43
|
+
site.stubs(:items).returns(items)
|
44
|
+
site.stubs(:layouts).returns(layouts)
|
45
|
+
item = mock
|
46
|
+
item.stubs(:site).returns(site)
|
47
|
+
|
48
|
+
# Mock rep
|
49
|
+
rep = mock
|
50
|
+
rep.stubs(:item).returns(item)
|
51
|
+
rep.expects(:filter).with(:foo, { :bar => 'baz' })
|
52
|
+
rep.expects(:layout).with('foo')
|
53
|
+
rep.expects(:snapshot).with('awesome')
|
54
|
+
|
55
|
+
# Mock compiler
|
56
|
+
compiler = Nanoc3::Compiler.new(site)
|
57
|
+
|
58
|
+
# Create context
|
59
|
+
@rule_context = Nanoc3::RuleContext.new(:rep => rep, :compiler => compiler)
|
60
|
+
|
61
|
+
# Check
|
62
|
+
rep.filter :foo, :bar => 'baz'
|
63
|
+
rep.layout 'foo'
|
64
|
+
rep.snapshot 'awesome'
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|