public static XElement Render(this CmsContext context, CmsView view, params CmsPart[] parts) { return view.Render(context, new CmsDocument("dynamic", parts)).Single(); }
private void ConfigureCms() { var rootFolder = Server.MapPath("~/"); var cmsDirectory = new DirectoryInfo(Path.Combine(rootFolder, @"App_Data\Cms")); if (cmsDirectory.Exists && !UseSql) { cmsDirectory.Delete(true); } var unity = new UnityContainer(); var configuration = unity.ConfigureCms() .UseHtmlRenderer() .UseTextRenderer() .UseMarkdownRenderer() .UseSourceCodeRenderer(); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (UseAzure) { var azureStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true"); configuration .UseAzureStorage(azureStorageAccount.CreateCloudBlobClient(), "cms") .UseLuceneSearch(new AzureDirectory(azureStorageAccount, "cms-index", new RAMDirectory())); } // ReSharper disable once ConditionIsAlwaysTrueOrFalse else if (UseRedis) { configuration .UseRedisStorage() .UseLuceneSearch(new SimpleFSDirectory(new DirectoryInfo(Path.Combine(cmsDirectory.FullName, "Index")))); } // ReSharper disable once ConditionIsAlwaysTrueOrFalse else if (UseSql) { // To configure db via web.config, uncomment entityFramework section and connection string and pass in connection string // name to ICmsConfigurator; e.g. .UseSqlStorage("DefaultConnection") if (!cmsDirectory.Exists) cmsDirectory.Create(); string connectionString = string.Format( @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename={0}\{1}.mdf;Initial Catalog={1};Integrated Security=True;MultipleActiveResultSets=true", cmsDirectory.FullName, "MicroCmsSqlDb"); configuration .UseSqlStorage(connectionString) .UseSqlSearch(connectionString); } else { configuration .UseFileSystemStorage(cmsDirectory) .UseLuceneSearch(new SimpleFSDirectory(new DirectoryInfo(Path.Combine(cmsDirectory.FullName, "Index")))); } Cms.Configure(() => new UnityCmsContainer(unity.CreateChildContainer())); using (var context = Cms.CreateContext()) { if (!context.Documents.GetAll().Any()) { var rowView = new CmsView("RowView", "<div class=\"row\">{0}</div>"); var sidebarView = new CmsView("SidebarView", "<div>{0}</div>"); context.Views.Save(rowView); context.Views.Save(sidebarView); var document = new CmsDocument("Example Rows", CreateMarkdown("#MD4", 4), CreateMarkdown("#MD8", 8), CreateMarkdown("#MD3", 3), CreateMarkdown("#MD3", 3), CreateMarkdown("#MD3", 3), CreateMarkdown("#MD3", 3), CreateMarkdown("#MD12", 12)); document.Tags.Add("documents"); context.Documents.Save(document); context.Documents.Save(new CmsDocument("Source Code Example", CreateMarkdown(@"#CODE {{CSharp}} public class Thing { public string Name { get; set; } } ", 12))); var sidebar = new CmsDocument("TableOfContents", new CmsPart(CmsTypes.Markdown, @"[Home](/) [Docs](/docs/)")); sidebar.Tags.Add("TableOfContents"); context.Documents.Save(sidebar); var readmeText = File.ReadAllText(Path.Combine(rootFolder, @"..\..\README.md")); var homeDocument = new CmsDocument("Readme", CreateMarkdown(readmeText, 12)); homeDocument.Tags.Add("home"); Cms.CreateContext().Documents.Save(homeDocument); } } }
public static IHtmlString RenderCms(this HtmlHelper html, CmsDocument document, CmsView view = null) { return html.GetCmsContext().Render(view ?? CmsView.Default, document.Parts.ToArray()).ToHtml(); }