Files
Umbraco-CMS/src/Umbraco.Web/Editors/StylesheetController.cs
2018-06-29 19:52:40 +02:00

36 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
namespace Umbraco.Web.Editors
{
/// <summary>
/// The API controller used for retrieving available stylesheets
/// </summary>
[PluginController("UmbracoApi")]
public class StylesheetController : UmbracoAuthorizedJsonController
{
public IEnumerable<Stylesheet> GetAll()
{
return Services.FileService.GetStylesheets()
.Select(x =>
new Stylesheet() {
Name = x.Alias,
Path = x.VirtualPath
});
}
public IEnumerable<StylesheetRule> GetRulesByName(string name)
{
var css = Services.FileService.GetStylesheetByName(name.EnsureEndsWith(".css"));
if (css == null)
return Enumerable.Empty<StylesheetRule>();
return css.Properties.Select(x => new StylesheetRule() { Name = x.Name, Selector = x.Alias });
}
}
}