2018-11-01 15:49:30 +01:00
|
|
|
|
using System.Collections.Generic;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Umbraco.Core;
|
2020-05-28 07:50:56 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
|
|
|
|
|
using Umbraco.Web.Common.Attributes;
|
|
|
|
|
|
using Umbraco.Web.Editors;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
|
2020-05-28 07:50:56 +02:00
|
|
|
|
namespace Umbraco.Web.BackOffice.Controllers
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The API controller used for retrieving available stylesheets
|
|
|
|
|
|
/// </summary>
|
2020-06-09 13:01:05 +10:00
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
2018-06-29 19:52:40 +02:00
|
|
|
|
public class StylesheetController : UmbracoAuthorizedJsonController
|
|
|
|
|
|
{
|
2020-05-28 07:50:56 +02:00
|
|
|
|
private readonly IFileService _fileService;
|
|
|
|
|
|
|
|
|
|
|
|
public StylesheetController(IFileService fileService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_fileService = fileService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
|
public IEnumerable<Stylesheet> GetAll()
|
|
|
|
|
|
{
|
2020-05-28 07:50:56 +02:00
|
|
|
|
return _fileService.GetStylesheets()
|
2018-06-29 19:52:40 +02:00
|
|
|
|
.Select(x =>
|
|
|
|
|
|
new Stylesheet() {
|
|
|
|
|
|
Name = x.Alias,
|
|
|
|
|
|
Path = x.VirtualPath
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<StylesheetRule> GetRulesByName(string name)
|
|
|
|
|
|
{
|
2020-05-28 07:50:56 +02:00
|
|
|
|
var css = _fileService.GetStylesheetByName(name.EnsureEndsWith(".css"));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
if (css == null)
|
|
|
|
|
|
return Enumerable.Empty<StylesheetRule>();
|
|
|
|
|
|
|
|
|
|
|
|
return css.Properties.Select(x => new StylesheetRule() { Name = x.Name, Selector = x.Alias });
|
|
|
|
|
|
}
|
2018-10-31 21:33:32 +01:00
|
|
|
|
}
|
2018-11-01 15:49:30 +01:00
|
|
|
|
|
2020-05-28 07:50:56 +02:00
|
|
|
|
}
|