public Parse ( |
||
templateFile | The template file. | |
return |
//public override ActionResult Create(string fileName, HiveId parentId, HiveId stubFileId = default(HiveId)) //{ // var model = CreateNewEditorModel(fileName, parentId, stubFileId); // return View("Edit", model); //} protected override EntityPathCollection CreatePaths(File file) { //return base.CreatePath(file); if (file.IsContainer) return base.CreatePaths(file); var parser = new TemplateParser(); var result = parser.Parse(file); if (string.IsNullOrWhiteSpace(result.Layout)) return base.CreatePaths(file); var path = new List<HiveId> { file.Id }; using (var uow = Hive.Create()) { // Get parent paths from layout //TODO: Need to fetch from the current folder if we want to support folders var files = uow.Repositories.GetAll<File>().Where(x => !x.IsContainer && x.Id != file.Id); var currentLayout = TemplateHelper.ResolveLayoutPath(result.Layout, file); while(!string.IsNullOrWhiteSpace(currentLayout)) { var parent = files.SingleOrDefault(x => TemplateHelper.ResolveLayoutPath(x.RootRelativePath, x) == currentLayout); if(parent != null) { path.Add(parent.Id); currentLayout = parser.Parse(parent).Layout; } else { currentLayout = ""; } } path.Reverse(); // Insert the actual parents path at the begining var actualParent = uow.Repositories.GetLazyParentRelations(file.Id, FixedRelationTypes.DefaultRelationType) .Select(x => x.Source as File) .SingleOrDefault(); if (actualParent != null) path.InsertRange(0, base.CreatePaths(actualParent)[0]); // Assumes a template will only ever be available at one location } return new EntityPathCollection(file.Id, new[]{ new EntityPath(path) }); }
public ActionResult Index(HiveId id) { var model = new ImplementSectionModel { AvailableSections = Enumerable.Empty<string>() }; using (var uow = _templateStore.CreateReadonly()) { var template = uow.Repositories.Get<File>(id); if(template != null) { var parser = new TemplateParser(); var result = parser.Parse(template); if (!string.IsNullOrWhiteSpace(result.Layout)) { var layoutFilePath = TemplateHelper.ResolveLayoutPath(result.Layout, template); var layoutFile = uow.Repositories.GetAll<File>().Where(x => x.RootedPath == layoutFilePath).FirstOrDefault(); var layoutResult = parser.Parse(layoutFile); model.AvailableSections = layoutResult.Sections.Where(x => x != "Body").ToArray(); } } } return View(model); }
protected override void EnsureViewData(FileEditorModel model, File file) { // Setup UIElements model.UIElements.Add(new SeperatorUIElement()); model.UIElements.Add(new ButtonUIElement { Alias = "InsertField", Title = "Insert an rebel page field", CssClass = "insert-field-button toolbar-button", AdditionalData = new Dictionary<string, string> { { "id", "submit_InsertField" }, { "name", "submit.InsertField" } } }); model.UIElements.Add(new ButtonUIElement { Alias = "InsertPartial", Title = "Insert a partial view", CssClass = "insert-partial-button toolbar-button", AdditionalData = new Dictionary<string, string> { { "id", "submit_InsertPartial" }, { "name", "submit.InsertPartial" } } }); model.UIElements.Add(new ButtonUIElement { Alias = "InsertMacro", Title = "Insert a macro", CssClass = "insert-macro-button toolbar-button", AdditionalData = new Dictionary<string, string> { { "id", "submit_InsertMacro" }, { "name", "submit.InsertMacro" } } }); model.UIElements.Add(new SeperatorUIElement()); model.UIElements.Add(new ButtonUIElement { Alias = "DefineSection", Title = "Define a Section", CssClass = "define-section-button toolbar-button", AdditionalData = new Dictionary<string, string> { { "id", "submit_DefineSection" }, { "name", "submit.DefineSection" } } }); model.UIElements.Add(new ButtonUIElement { Alias = "ImplementSection", Title = "Implement a Section", CssClass = "implement-section-button toolbar-button", AdditionalData = new Dictionary<string, string> { { "id", "submit_ImplementSection" }, { "name", "submit.ImplementSection" } } }); model.UIElements.Add(new SeperatorUIElement()); model.UIElements.Add(new SelectListUIElement { Alias = "Layout", Title = "Layout", CssClass = "layout-select-list", AdditionalData = new Dictionary<string, string> { { "id", "select_Layout" }, { "name", "select.Layout" } } }); // Setup data var parser = new TemplateParser(); ViewBag.CurrentLayout = file != null ? parser.Parse(file).Layout : ""; using (var uow = BackOfficeRequestContext.Application.Hive.OpenReader<IFileStore>(new Uri("storage://templates"))) { //create the allowed templates check box list ViewBag.AvailableTemplates = new List<SelectListItem>( uow.Repositories.GetAllNonContainerFiles() .OrderBy(x => x.Name) .Select(x => new SelectListItem { Text = x.GetFileNameForDisplay(), Value = x.Name })).ToArray(); } }