2022-06-20 08:37:17 +02:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
|
|
|
|
using Umbraco.Extensions;
|
2022-06-20 08:37:17 +02:00
|
|
|
using Stylesheet = Umbraco.Cms.Core.Models.ContentEditing.Stylesheet;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The API controller used for retrieving available stylesheets
|
|
|
|
|
/// </summary>
|
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
|
|
|
|
public class StylesheetController : UmbracoAuthorizedJsonController
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
private readonly IFileService _fileService;
|
2020-05-28 07:50:56 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
public StylesheetController(IFileService fileService) => _fileService = fileService;
|
2020-05-28 07:50:56 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
public IEnumerable<Stylesheet> GetAll() =>
|
|
|
|
|
_fileService.GetStylesheets()
|
|
|
|
|
.Select(x =>
|
|
|
|
|
new Stylesheet { Name = x.Alias, Path = x.VirtualPath });
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
public IEnumerable<StylesheetRule> GetRulesByName(string name)
|
|
|
|
|
{
|
|
|
|
|
IStylesheet? css = _fileService.GetStylesheet(name.EnsureEndsWith(".css"));
|
|
|
|
|
if (css is null || css.Properties is null)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
return Enumerable.Empty<StylesheetRule>();
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2018-11-01 15:49:30 +01:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return css.Properties.Select(x => new StylesheetRule { Name = x.Name, Selector = x.Alias });
|
|
|
|
|
}
|
2020-05-28 07:50:56 +02:00
|
|
|
}
|