nanoc-filesystem-i18n 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,260 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test/helper'
4
-
5
- class Nanoc3::DataSources::FilesystemVerboseTest < MiniTest::Unit::TestCase
6
-
7
- include Nanoc3::TestHelpers
8
-
9
- def new_data_source(params=nil)
10
- # Mock site
11
- site = Nanoc3::Site.new({})
12
-
13
- # Create data source
14
- # I18n: call `up` to setup locale config
15
- data_source = Nanoc3::DataSources::FilesystemI18n.new(site, nil, nil, params)
16
- data_source.up
17
-
18
- # Done
19
- data_source
20
- end
21
-
22
- def test_items
23
- # Create data source
24
- data_source = new_data_source
25
-
26
- # Create foo item
27
- FileUtils.mkdir_p('content/foo')
28
- File.open('content/foo/foo.yaml', 'w') do |io|
29
- io.write("---\n")
30
- io.write("title: Foo\n")
31
- end
32
- File.open('content/foo/foo.html', 'w') do |io|
33
- io.write('Lorem ipsum dolor sit amet...')
34
- end
35
-
36
- # Create bar item
37
- FileUtils.mkdir_p('content/bar')
38
- File.open('content/bar/bar.yaml', 'w') do |io|
39
- io.write("---\n")
40
- io.write("title: Bar\n")
41
- end
42
- File.open('content/bar/bar.xml', 'w') do |io|
43
- io.write("Lorem ipsum dolor sit amet...")
44
- end
45
-
46
- # Load items
47
- items = data_source.items
48
-
49
- # Check items
50
- assert_equal(2, items.size)
51
- assert(items.any? { |a|
52
- a[:title] == 'Foo' &&
53
- a[:extension] == 'html' &&
54
- a[:content_filename] == 'content/foo/foo.html' &&
55
- a[:meta_filename] == 'content/foo/foo.yaml'
56
- })
57
- assert(items.any? { |a|
58
- a[:title] == 'Bar' &&
59
- a[:extension] == 'xml' &&
60
- a[:content_filename] == 'content/bar/bar.xml' &&
61
- a[:meta_filename] == 'content/bar/bar.yaml'
62
- })
63
- end
64
-
65
- def test_items_with_period_in_name
66
- data_source = new_data_source(:allow_periods_in_identifiers => true)
67
-
68
- # Create foo.css
69
- FileUtils.mkdir_p('content/foo')
70
- File.open('content/foo/foo.yaml', 'w') do |io|
71
- io.write(YAML.dump({ 'title' => 'Foo' }))
72
- end
73
- File.open('content/foo/foo.css', 'w') do |io|
74
- io.write('body.foo {}')
75
- end
76
-
77
- # Create foo.bar.css
78
- FileUtils.mkdir_p('content/foo.bar')
79
- File.open('content/foo.bar/foo.bar.yaml', 'w') do |io|
80
- io.write(YAML.dump({ 'title' => 'Foo Bar' }))
81
- end
82
- File.open('content/foo.bar/foo.bar.css', 'w') do |io|
83
- io.write('body.foobar {}')
84
- end
85
-
86
- # Load
87
- items = data_source.items
88
-
89
- # Check
90
- assert_equal 2, items.size
91
- assert_equal '/foo/', items[0].identifier
92
- assert_equal 'Foo', items[0][:title]
93
- assert_equal 'content/foo/foo.css', items[0][:content_filename]
94
- assert_equal 'content/foo/foo.yaml', items[0][:meta_filename]
95
- assert_equal '/foo.bar/', items[1].identifier
96
- assert_equal 'Foo Bar', items[1][:title]
97
- assert_equal 'content/foo.bar/foo.bar.css', items[1][:content_filename]
98
- assert_equal 'content/foo.bar/foo.bar.yaml', items[1][:meta_filename]
99
- end
100
-
101
- def test_items_with_optional_meta_file
102
- # Create data source
103
- data_source = new_data_source
104
-
105
- # Create foo item
106
- FileUtils.mkdir_p('content/foo')
107
- File.open('content/foo/foo.html', 'w') do |io|
108
- io.write('Lorem ipsum dolor sit amet...')
109
- end
110
-
111
- # Create bar item
112
- FileUtils.mkdir_p('content/bar')
113
- File.open('content/bar/bar.yaml', 'w') do |io|
114
- io.write("---\n")
115
- io.write("title: Bar\n")
116
- end
117
-
118
- # Load items
119
- items = data_source.items
120
-
121
- # Check items
122
- assert_equal(2, items.size)
123
- assert(items.any? { |a|
124
- a[:title] == nil &&
125
- a[:extension] == 'html' &&
126
- a[:content_filename] == 'content/foo/foo.html' &&
127
- a[:meta_filename] == nil
128
- })
129
- assert(items.any? { |a|
130
- a[:title] == 'Bar' &&
131
- a[:extension] == nil &&
132
- a[:content_filename] == nil &&
133
- a[:meta_filename] == 'content/bar/bar.yaml'
134
- })
135
- end
136
-
137
- def test_layouts
138
- # Create data source
139
- data_source = new_data_source
140
-
141
- # Create layout
142
- FileUtils.mkdir_p('layouts/foo')
143
- File.open('layouts/foo/foo.yaml', 'w') do |io|
144
- io.write("---\n")
145
- io.write("filter: erb\n")
146
- end
147
- File.open('layouts/foo/foo.rhtml', 'w') do |io|
148
- io.write('Lorem ipsum dolor sit amet...')
149
- end
150
-
151
- # Load layouts
152
- layouts = data_source.layouts
153
-
154
- # Check layouts
155
- assert_equal(1, layouts.size)
156
- assert_equal('erb', layouts[0][:filter])
157
- assert_equal('rhtml', layouts[0][:extension])
158
- assert_equal('layouts/foo/foo.rhtml', layouts[0][:content_filename])
159
- assert_equal('layouts/foo/foo.yaml', layouts[0][:meta_filename])
160
- end
161
-
162
- def test_layouts_with_period_in_name_disallowing_periods_in_identifiers
163
- data_source = new_data_source
164
-
165
- # Create foo.html
166
- FileUtils.mkdir_p('layouts/foo')
167
- File.open('layouts/foo/foo.yaml', 'w') do |io|
168
- io.write(YAML.dump({ 'dog' => 'woof' }))
169
- end
170
- File.open('layouts/foo/foo.html', 'w') do |io|
171
- io.write('body.foo {}')
172
- end
173
-
174
- # Create bar.html.erb
175
- FileUtils.mkdir_p('layouts/bar')
176
- File.open('layouts/bar/bar.yaml', 'w') do |io|
177
- io.write(YAML.dump({ 'cat' => 'meow' }))
178
- end
179
- File.open('layouts/bar/bar.html.erb', 'w') do |io|
180
- io.write('body.foobar {}')
181
- end
182
-
183
- # Load
184
- layouts = data_source.layouts.sort_by { |i| i.identifier }
185
-
186
- # Check
187
- assert_equal 2, layouts.size
188
- assert_equal '/bar/', layouts[0].identifier
189
- assert_equal 'meow', layouts[0][:cat]
190
- assert_equal '/foo/', layouts[1].identifier
191
- assert_equal 'woof', layouts[1][:dog]
192
- end
193
-
194
- def test_layouts_with_period_in_name_allowing_periods_in_identifiers
195
- data_source = new_data_source(:allow_periods_in_identifiers => true)
196
-
197
- # Create foo.html
198
- FileUtils.mkdir_p('layouts/foo')
199
- File.open('layouts/foo/foo.yaml', 'w') do |io|
200
- io.write(YAML.dump({ 'dog' => 'woof' }))
201
- end
202
- File.open('layouts/foo/foo.html', 'w') do |io|
203
- io.write('body.foo {}')
204
- end
205
-
206
- # Create bar.html.erb
207
- FileUtils.mkdir_p('layouts/bar.xyz')
208
- File.open('layouts/bar.xyz/bar.xyz.yaml', 'w') do |io|
209
- io.write(YAML.dump({ 'cat' => 'meow' }))
210
- end
211
- File.open('layouts/bar.xyz/bar.xyz.html', 'w') do |io|
212
- io.write('body.foobar {}')
213
- end
214
-
215
- # Load
216
- layouts = data_source.layouts.sort_by { |i| i.identifier }
217
-
218
- # Check
219
- assert_equal 2, layouts.size
220
- assert_equal '/bar.xyz/', layouts[0].identifier
221
- assert_equal 'meow', layouts[0][:cat]
222
- assert_equal '/foo/', layouts[1].identifier
223
- assert_equal 'woof', layouts[1][:dog]
224
- end
225
-
226
- def test_load_binary_objects
227
- # Create data source
228
- data_source = new_data_source
229
-
230
- # Create sample files
231
- FileUtils.mkdir_p('foo')
232
- File.open('foo/stuff.dat', 'w') { |io| io.write("random binary data") }
233
-
234
- # Load
235
- items = data_source.send(:load_objects, 'foo', 'item', Nanoc3::Item)
236
-
237
- # Check
238
- assert_equal 1, items.size
239
- assert items[0].binary?
240
- assert_equal 'foo/stuff.dat', items[0].raw_filename
241
- assert_nil items[0].raw_content
242
- end
243
-
244
- def test_compile_huge_site
245
- # Create data source
246
- data_source = new_data_source
247
-
248
- # Create a lot of items
249
- count = Process.getrlimit(Process::RLIMIT_NOFILE)[0] + 5
250
- count.times do |i|
251
- FileUtils.mkdir_p("content/#{i}")
252
- File.open("content/#{i}/#{i}.html", 'w') { |io| io << "This is item #{i}." }
253
- File.open("content/#{i}/#{i}.yaml", 'w') { |io| io << "title: Item #{i}" }
254
- end
255
-
256
- # Read all items
257
- data_source.items
258
- end
259
-
260
- end