@@ -24,7 +24,7 @@ import vibe.core.stream;
24
24
import vibe.data.json;
25
25
import vibe.inet.path;
26
26
import vibe.http.server;
27
- import vibe.stream.wrapper : StreamOutputRange ;
27
+ import vibe.stream.wrapper : streamOutputRange ;
28
28
import diet.html;
29
29
import diet.traits : dietTraits;
30
30
@@ -40,7 +40,7 @@ import diet.traits : dietTraits;
40
40
version (Windows ) version = CaseInsensitiveFS;
41
41
else version (OSX ) version = CaseInsensitiveFS;
42
42
43
- void generateHtmlDocs (Path dst_path, Package root, GeneratorSettings settings = null )
43
+ void generateHtmlDocs (NativePath dst_path, Package root, GeneratorSettings settings = null )
44
44
{
45
45
import std.algorithm : splitter;
46
46
import vibe.web.common : adjustMethodStyle;
@@ -151,15 +151,20 @@ void generateHtmlDocs(Path dst_path, Package root, GeneratorSettings settings =
151
151
}
152
152
}
153
153
154
- void writeHashedFile (Path filename, scope void delegate (OutputStream ) del)
154
+ void writeHashedFile (NativePath filename, scope void delegate (OutputStream ) del)
155
155
{
156
+ import std.range : drop, walkLength;
156
157
import vibe.stream.memory;
158
+
157
159
assert (filename.startsWith(dst_path));
158
160
159
161
auto str = createMemoryOutputStream();
160
162
del(str);
161
163
auto h = md5Of(str.data).toHexString.idup;
162
- auto relfilename = filename[dst_path.length .. $].toString();
164
+ version (Have_vibe_core)
165
+ auto relfilename = NativePath(filename.bySegment.drop(dst_path.bySegment.walkLength)).toString();
166
+ else
167
+ auto relfilename = NativePath(filename.bySegment.drop(dst_path.bySegment.walkLength), false ).toString();
163
168
auto ph = relfilename in file_hashes;
164
169
if (! ph || * ph != h) {
165
170
// logInfo("do write %s", filename);
@@ -168,26 +173,28 @@ void generateHtmlDocs(Path dst_path, Package root, GeneratorSettings settings =
168
173
new_file_hashes[relfilename] = h;
169
174
}
170
175
171
- void visitModule (Module mod, Path pack_path)
176
+ void visitModule (Module mod, NativePath pack_path)
172
177
{
173
- auto modpath = pack_path ~ PathEntry(mod.name);
178
+ import std.range : walkLength;
179
+
180
+ auto modpath = pack_path ~ NativePath.Segment(mod.name);
174
181
if (! existsFile(modpath)) createDirectory(modpath);
175
182
logInfo(" Generating module: %s" , mod.qualifiedName);
176
- writeHashedFile(pack_path ~ PathEntry (mod.name~ " .html" ), (stream) {
177
- generateModulePage(stream, root, mod, settings, ent => linkTo(ent, pack_path.length - dst_path.length ));
183
+ writeHashedFile(pack_path ~ NativePath.Segment (mod.name~ " .html" ), (stream) {
184
+ generateModulePage(stream, root, mod, settings, ent => linkTo(ent, pack_path.bySegment.walkLength - dst_path.bySegment.walkLength ));
178
185
});
179
186
180
187
DocGroup[][string ] pages;
181
188
collectChildren(mod, pages);
182
189
foreach (name, decls; pages)
183
- writeHashedFile(modpath ~ PathEntry (name~ " .html" ), (stream) {
184
- generateDeclPage(stream, root, mod, name, decls, settings, ent => linkTo(ent, modpath.length - dst_path.length ));
190
+ writeHashedFile(modpath ~ NativePath.Segment (name~ " .html" ), (stream) {
191
+ generateDeclPage(stream, root, mod, name, decls, settings, ent => linkTo(ent, modpath.bySegment.walkLength - dst_path.bySegment.walkLength ));
185
192
});
186
193
}
187
194
188
- void visitPackage (Package p, Path path)
195
+ void visitPackage (Package p, NativePath path)
189
196
{
190
- auto packpath = p.parent ? path ~ PathEntry (p.name) : path;
197
+ auto packpath = p.parent ? path ~ NativePath.Segment (p.name) : path;
191
198
if ( ! packpath.empty && ! existsFile(packpath) ) createDirectory(packpath);
192
199
foreach ( sp; p.packages ) visitPackage(sp, packpath);
193
200
foreach ( m; p.modules ) visitModule(m, packpath);
@@ -197,15 +204,15 @@ void generateHtmlDocs(Path dst_path, Package root, GeneratorSettings settings =
197
204
198
205
if ( ! dst_path.empty && ! existsFile(dst_path) ) createDirectory(dst_path);
199
206
200
- writeHashedFile(dst_path ~ PathEntry (" index.html" ), (stream) {
207
+ writeHashedFile(dst_path ~ NativePath.Segment (" index.html" ), (stream) {
201
208
generateApiIndex(stream, root, settings, ent => linkTo(ent, 0 ));
202
209
});
203
210
204
211
writeHashedFile(dst_path ~ " symbols.js" , (stream) {
205
212
generateSymbolsJS(stream, root, settings, ent => linkTo(ent, 0 ));
206
213
});
207
214
208
- writeHashedFile(dst_path ~ PathEntry (" sitemap.xml" ), (stream) {
215
+ writeHashedFile(dst_path ~ NativePath.Segment (" sitemap.xml" ), (stream) {
209
216
generateSitemap(stream, root, settings, ent => linkTo(ent, 0 ));
210
217
});
211
218
@@ -214,7 +221,7 @@ void generateHtmlDocs(Path dst_path, Package root, GeneratorSettings settings =
214
221
// delete obsolete files
215
222
foreach (f; file_hashes.byKey )
216
223
if (f ! in new_file_hashes) {
217
- try removeFile (dst_path ~ Path (f));
224
+ try removeFile (dst_path ~ NativePath (f));
218
225
catch (Exception e) logWarn(" Failed to remove obsolete file '%s': %s" , f, e.msg);
219
226
}
220
227
@@ -252,7 +259,8 @@ struct DdoxDietTraits(HTMLOutputStyle htmlStyle) {
252
259
enum HTMLOutputStyle htmlOutputStyle = htmlStyle;
253
260
}
254
261
255
- void generateSitemap (OutputStream dst, Package root_package, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
262
+ void generateSitemap (OutputStream )(OutputStream dst, Package root_package, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
263
+ if (isOutputStream! OutputStream )
256
264
{
257
265
dst.write(" <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n " );
258
266
dst.write(" <urlset xmlns=\" http://www.sitemaps.org/schemas/sitemap/0.9\" >\n " );
@@ -266,10 +274,13 @@ void generateSitemap(OutputStream dst, Package root_package, GeneratorSettings s
266
274
267
275
void writeEntityRec (Entity ent){
268
276
import std.string ;
269
- if ( ! cast (Package)ent || ent is root_package ) {
277
+ if ( ! cast (Package)ent || ent is root_package) {
270
278
auto link = link_to(ent);
271
- if ( indexOf(link, ' #' ) < 0 ) // ignore URLs with anchors
272
- writeEntry((settings.siteUrl ~ Path(link)).toString());
279
+ if (indexOf(link, ' #' ) < 0 ) { // ignore URLs with anchors
280
+ auto p = InetPath(link);
281
+ p.normalize();
282
+ writeEntry((settings.siteUrl ~ p).toString());
283
+ }
273
284
}
274
285
ent.iterateChildren((ch){ writeEntityRec (ch); return true ; });
275
286
}
@@ -280,13 +291,14 @@ void generateSitemap(OutputStream dst, Package root_package, GeneratorSettings s
280
291
dst.flush();
281
292
}
282
293
283
- void generateSymbolsJS (OutputStream dst, Package root_package, GeneratorSettings settings, string delegate (in Entity) link_to)
294
+ void generateSymbolsJS (OutputStream )(OutputStream dst, Package root_package, GeneratorSettings settings, string delegate (in Entity) link_to)
295
+ if (isOutputStream! OutputStream )
284
296
{
285
297
import std.typecons : Tuple , tuple;
286
298
287
299
bool [Tuple ! (Entity, CachedString)] visited;
288
300
289
- auto rng = StreamOutputRange (dst);
301
+ auto rng = streamOutputRange (dst);
290
302
291
303
void writeEntry (Entity ent) {
292
304
auto key = tuple(ent.parent, ent.name);
@@ -316,15 +328,16 @@ void generateSymbolsJS(OutputStream dst, Package root_package, GeneratorSettings
316
328
rng.put(" ];\n " );
317
329
}
318
330
319
- void generateApiIndex (OutputStream dst, Package root_package, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
331
+ void generateApiIndex (OutputStream )(OutputStream dst, Package root_package, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
332
+ if (isOutputStream! OutputStream )
320
333
{
321
334
auto info = new DocPageInfo;
322
335
info.linkTo = link_to;
323
336
info.settings = settings;
324
337
info.rootPackage = root_package;
325
338
info.node = root_package;
326
339
327
- auto rng = StreamOutputRange (dst);
340
+ auto rng = streamOutputRange (dst);
328
341
final switch (settings.htmlOutputStyle)
329
342
{
330
343
foreach (htmlOutputStyle; EnumMembers! HTMLOutputStyle)
@@ -336,7 +349,8 @@ void generateApiIndex(OutputStream dst, Package root_package, GeneratorSettings
336
349
}
337
350
}
338
351
339
- void generateModulePage (OutputStream dst, Package root_package, Module mod, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
352
+ void generateModulePage (OutputStream )(OutputStream dst, Package root_package, Module mod, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
353
+ if (isOutputStream! OutputStream )
340
354
{
341
355
auto info = new DocPageInfo;
342
356
info.linkTo = link_to;
@@ -346,7 +360,7 @@ void generateModulePage(OutputStream dst, Package root_package, Module mod, Gene
346
360
info.node = mod;
347
361
info.docGroups = null ;
348
362
349
- auto rng = StreamOutputRange (dst);
363
+ auto rng = streamOutputRange (dst);
350
364
final switch (settings.htmlOutputStyle)
351
365
{
352
366
foreach (htmlOutputStyle; EnumMembers! HTMLOutputStyle)
@@ -358,7 +372,8 @@ void generateModulePage(OutputStream dst, Package root_package, Module mod, Gene
358
372
}
359
373
}
360
374
361
- void generateDeclPage (OutputStream dst, Package root_package, Module mod, string nested_name, DocGroup[] docgroups, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
375
+ void generateDeclPage (OutputStream )(OutputStream dst, Package root_package, Module mod, string nested_name, DocGroup[] docgroups, GeneratorSettings settings, string delegate (in Entity) link_to, HTTPServerRequest req = null )
376
+ if (isOutputStream! OutputStream )
362
377
{
363
378
import std.algorithm : sort;
364
379
@@ -372,7 +387,7 @@ void generateDeclPage(OutputStream dst, Package root_package, Module mod, string
372
387
sort! ((a, b) => cmpKind(a.members[0 ], b.members[0 ]))(info.docGroups);
373
388
info.nestedName = nested_name;
374
389
375
- auto rng = StreamOutputRange (dst);
390
+ auto rng = streamOutputRange (dst);
376
391
final switch (settings.htmlOutputStyle)
377
392
{
378
393
foreach (htmlOutputStyle; EnumMembers! HTMLOutputStyle)
0 commit comments