nanoc-filesystem-i18n 0.1.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +25 -0
- data/README.rdoc +109 -0
- data/Rakefile +59 -0
- data/lib/nanoc3/data_sources/filesystem_i18n.rb +399 -0
- data/lib/nanoc3/data_sources/filesystem_i18n/version.rb +12 -0
- data/lib/nanoc3/extra/i18n.rb +50 -0
- data/test/helper.rb +90 -0
- data/test/test_filesystem.rb +347 -0
- data/test/test_filesystem_i18n.rb +61 -0
- data/test/test_filesystem_unified.rb +461 -0
- data/test/test_filesystem_verbose.rb +260 -0
- metadata +129 -0
@@ -0,0 +1,260 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanoc-filesystem-i18n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- pre1
|
10
|
+
version: 0.1.0.pre1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Yann Lugrin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-04-08 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nanoc
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 1
|
31
|
+
- 2
|
32
|
+
version: 3.1.2
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: i18n
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: minitest
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: yard
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id004
|
71
|
+
description: I18n filesystem based data source for nanoc. Compatible with nanoc 3 and default filesystem based data source.
|
72
|
+
email: yann.lugrin@sans-savoir.net
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files:
|
78
|
+
- LICENSE
|
79
|
+
- README.rdoc
|
80
|
+
files:
|
81
|
+
- LICENSE
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- lib/nanoc3/data_sources/filesystem_i18n.rb
|
85
|
+
- lib/nanoc3/data_sources/filesystem_i18n/version.rb
|
86
|
+
- lib/nanoc3/extra/i18n.rb
|
87
|
+
- test/helper.rb
|
88
|
+
- test/test_filesystem.rb
|
89
|
+
- test/test_filesystem_i18n.rb
|
90
|
+
- test/test_filesystem_unified.rb
|
91
|
+
- test/test_filesystem_verbose.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/yannlugrin/nanoc-filesystem-i18n
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- --charset=UTF-8
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 1
|
114
|
+
- 3
|
115
|
+
- 1
|
116
|
+
version: 1.3.1
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.6
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: I18n filesystem based data source for nanoc
|
124
|
+
test_files:
|
125
|
+
- test/helper.rb
|
126
|
+
- test/test_filesystem_unified.rb
|
127
|
+
- test/test_filesystem_i18n.rb
|
128
|
+
- test/test_filesystem.rb
|
129
|
+
- test/test_filesystem_verbose.rb
|