forked from sebastienros/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileProviderMapper.cs
41 lines (35 loc) · 1.2 KB
/
FileProviderMapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using System.IO;
namespace Fluid.ViewEngine
{
public class FileProviderMapper : IFileProvider
{
private readonly IFileProvider _fileProvider;
private readonly string _mappedFolder;
public FileProviderMapper(IFileProvider fileProvider, string mappedFolder)
{
_fileProvider = fileProvider;
_mappedFolder = mappedFolder;
if (!_mappedFolder.EndsWith("/") || _mappedFolder.EndsWith("\\"))
{
_mappedFolder = _mappedFolder + Path.DirectorySeparatorChar;
}
}
public IDirectoryContents GetDirectoryContents(string subpath)
{
var path = _mappedFolder + subpath;
return _fileProvider.GetDirectoryContents(path);
}
public IFileInfo GetFileInfo(string subpath)
{
var path = _mappedFolder + subpath;
return _fileProvider.GetFileInfo(path);
}
public IChangeToken Watch(string filter)
{
var mappedFilter = _mappedFolder + filter;
return _fileProvider.Watch(mappedFilter);
}
}
}