Rebel.Cms.Web.Templates.TemplateParser.Parse C# (CSharp) Method

Parse() public method

Parses the specified template for a Layout and any RenderSections.
public Parse ( File templateFile ) : TemplateParserResult
templateFile Rebel.Framework.Persistence.Model.IO.File The template file.
return TemplateParserResult
        public TemplateParserResult Parse(File templateFile)
        {
            //TODO: Would probably be better to use the Razor engine to parse but was unable to get it working, so resorted to Regex for now
            var fileContents = Encoding.UTF8.GetString(templateFile.ContentBytes);
            return Parse(fileContents);
        }

Same methods

TemplateParser::Parse ( string templateFileContents ) : TemplateParserResult

Usage Example

コード例 #1
0
        //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) });
        }
All Usage Examples Of Rebel.Cms.Web.Templates.TemplateParser::Parse
TemplateParser