mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 05:23:31 -07:00
splited MVC and nancy application
backbone app is now fully served from nancy including css,js,html
This commit is contained in:
parent
fd4ffa0fa2
commit
7093f352fe
184 changed files with 497 additions and 1959 deletions
43
NzbDrone.Api/FrontendModule/BootstrapModule.cs
Normal file
43
NzbDrone.Api/FrontendModule/BootstrapModule.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
|
||||
namespace NzbDrone.Api.FrontendModule
|
||||
{
|
||||
public class BootstrapModule : NancyModule
|
||||
{
|
||||
private readonly ICompileLess _lessCompiler;
|
||||
|
||||
public BootstrapModule(ICompileLess lessCompiler)
|
||||
{
|
||||
_lessCompiler = lessCompiler;
|
||||
Get[@"static/content/bootstrap/bootstrap.less"] = x => OnGet();
|
||||
}
|
||||
|
||||
private Response OnGet()
|
||||
{
|
||||
/* var urlParts = Request.Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (urlParts.Length < 2)
|
||||
{
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
urlParts[0] = "NzbDrone.Backbone";
|
||||
|
||||
var filePath = Path.Combine(urlParts);
|
||||
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
return new NotFoundResponse();
|
||||
}*/
|
||||
|
||||
var css = _lessCompiler.Compile(Path.Combine("NzbDrone.Backbone","Content","Bootstrap","bootstrap.less"));
|
||||
|
||||
return new TextResponse(HttpStatusCode.OK, css) { ContentType = "text/css" };
|
||||
}
|
||||
}
|
||||
}
|
13
NzbDrone.Api/FrontendModule/IndexModule.cs
Normal file
13
NzbDrone.Api/FrontendModule/IndexModule.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Linq;
|
||||
using Nancy;
|
||||
|
||||
namespace NzbDrone.Api.FrontendModule
|
||||
{
|
||||
public class IndexModule : NancyModule
|
||||
{
|
||||
public IndexModule()
|
||||
{
|
||||
Get[@"/"] = x => View["NzbDrone.Backbone/index.html"];
|
||||
}
|
||||
}
|
||||
}
|
56
NzbDrone.Api/FrontendModule/LessService.cs
Normal file
56
NzbDrone.Api/FrontendModule/LessService.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using dotless.Core;
|
||||
using dotless.Core.Importers;
|
||||
using dotless.Core.Input;
|
||||
using dotless.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Api.FrontendModule
|
||||
{
|
||||
public interface ICompileLess
|
||||
{
|
||||
string Compile(string filePath);
|
||||
}
|
||||
|
||||
public class LessCompiler : ICompileLess
|
||||
{
|
||||
|
||||
public string Compile(string filePath)
|
||||
{
|
||||
var parser = new Parser()
|
||||
{
|
||||
Importer = new Importer(new LessFileReader(filePath))
|
||||
};
|
||||
|
||||
var lessEngine = new LessEngine(parser, null, false, true);
|
||||
var lessContent = File.ReadAllText(filePath);
|
||||
return lessEngine.TransformToCss(lessContent, filePath);
|
||||
}
|
||||
|
||||
|
||||
class LessFileReader : IFileReader
|
||||
{
|
||||
private readonly string _rootFolders;
|
||||
|
||||
public LessFileReader(string masterFile)
|
||||
{
|
||||
_rootFolders = new FileInfo(masterFile).Directory.FullName;
|
||||
}
|
||||
|
||||
public byte[] GetBinaryFileContents(string fileName)
|
||||
{
|
||||
return File.ReadAllBytes(Path.Combine(_rootFolders, fileName));
|
||||
}
|
||||
|
||||
public string GetFileContents(string fileName)
|
||||
{
|
||||
return File.ReadAllText(Path.Combine(_rootFolders, fileName));
|
||||
}
|
||||
|
||||
public bool DoesFileExist(string fileName)
|
||||
{
|
||||
return File.Exists(Path.Combine(_rootFolders, fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue