PageRenderTime 49ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Modules/Orchard.Projections/Providers/Layouts/GridLayout.cs

https://github.com/kappel/OrchardCMS
C# | 57 lines | 48 code | 9 blank | 0 comment | 3 complexity | 7bb2481f52615f6d1a945355104f18c7 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Orchard.ContentManagement;
  5. using Orchard.DisplayManagement;
  6. using Orchard.Localization;
  7. using Orchard.Projections.Descriptors.Layout;
  8. using Orchard.Projections.Models;
  9. using Orchard.Projections.Services;
  10. namespace Orchard.Projections.Providers.Layouts {
  11. public class GridLayout : ILayoutProvider {
  12. private readonly IContentManager _contentManager;
  13. protected dynamic Shape { get; set; }
  14. public GridLayout(IShapeFactory shapeFactory, IContentManager contentManager) {
  15. _contentManager = contentManager;
  16. Shape = shapeFactory;
  17. T = NullLocalizer.Instance;
  18. }
  19. public Localizer T { get; set; }
  20. public void Describe(DescribeLayoutContext describe) {
  21. describe.For("Html", T("Html"),T("Html Layouts"))
  22. .Element("Grid", T("Grid"), T("Organizes content items in a grid."),
  23. DisplayLayout,
  24. RenderLayout,
  25. "GridLayout"
  26. );
  27. }
  28. public LocalizedString DisplayLayout(LayoutContext context) {
  29. string columns = context.State.Columns;
  30. bool horizontal = Convert.ToString(context.State.Alignment) != "vertical";
  31. return horizontal
  32. ? T("{0} columns grid", columns)
  33. : T("{0} lines grid", columns);
  34. }
  35. public dynamic RenderLayout(LayoutContext context, IEnumerable<LayoutComponentResult> layoutComponentResults) {
  36. int columns = Convert.ToInt32(context.State.Columns);
  37. bool horizontal = Convert.ToString(context.State.Alignment) != "vertical";
  38. string rowClass = context.State.RowClass;
  39. string gridClass = context.State.GridClass;
  40. string gridId = context.State.GridId;
  41. IEnumerable<dynamic> shapes =
  42. context.LayoutRecord.Display == (int)LayoutRecord.Displays.Content
  43. ? layoutComponentResults.Select(x => _contentManager.BuildDisplay(x.ContentItem, context.LayoutRecord.DisplayType))
  44. : layoutComponentResults.Select(x => x.Properties);
  45. return Shape.Grid(Id: gridId, Horizontal: horizontal, Columns: columns, Items: shapes, Classes: new [] { gridClass }, RowClasses: new [] { rowClass });
  46. }
  47. }
  48. }