public async Task <string> RenderAsync(ITemplateModel model) { if (model is RentalAgreement rentalAgreement) { return(await this.engine.CompileRenderAsync(model.TemplatePath, rentalAgreement)); } throw new InvalidOperationException("Unknown model"); }
private TemplateModel ToTemplateModel(ITemplateModel converted) { var result = new TemplateModel(); result.TemplatedFileContent = converted.TemplatedFileContent; result.TemplatedFilePath = converted.TemplatedFilePath; return(result); }
public string GetName(ITemplateModel template) { if (String.IsNullOrEmpty(template.TemplateType)) { return template.TemplateName; } return String.Format("{0}.{1}", template.TemplateName, template.TemplateType); }
private void AddValidTemplate(Assembly assembly,ICollection<Template> templates, ITemplateModel modelInstance) { _resolver = new EmbeddedTemplateResolver(assembly); Template template = new Template(); template.Name = _nameFormatter.GetName(modelInstance); template.Text = _resolver.GetTemplate(template.Name); template.Model = modelInstance; if (!String.IsNullOrEmpty(template.Text)) { templates.Add(template); } }
public Template LoadFor(ITemplateModel templateModel) { string text = _resolver.GetTemplate(templateModel.TemplateName); if (String.IsNullOrEmpty(text)) { throw new TemplateNotFoundException(templateModel.TemplateName); } return new Template() { Name = templateModel.TemplateName, Text=text, Model = templateModel }; }
private void PreProcess(ITemplateModel templateModel, IDictionary <string, AbstactPreprocessorContextHandler> handlersByStartContext) { var contextes = contextVisitor.ExtractAllContextUntilDepth(templateModel.TemplatedFileContent, 1); var contextesAndProcessesResult = contextes.Select(context => (contextAsString: ToContextValue(context), processedContextContent: PreProcess(ToContextValue(context), context, handlersByStartContext), context)).ToList(); int lenghtSumDifference = 0; var result = templateModel.TemplatedFileContent; foreach (var current in contextesAndProcessesResult) { result = result.Substring(0, current.context.current.StartIndex + lenghtSumDifference) + current.processedContextContent + result.Substring(current.context.current.StartIndex + current.contextAsString.Length + lenghtSumDifference, result.Length - (current.context.current.StartIndex + current.contextAsString.Length + lenghtSumDifference)); lenghtSumDifference = lenghtSumDifference + (current.processedContextContent.Length - current.contextAsString.Length); } templateModel.TemplatedFileContent = result; }
public void SetUp() { _factory = MockRepository.GenerateStub<ITemplatesFactory>(); _templateModel = MockRepository.GenerateStub<ITemplateModel>(); _factory.Stub(f => f.GetTemplateModel(_viewModel)).Return(_templateModel); }
public TemplatePresenter() { templateModel = new TemplateModel(); }
public ManageTemplatePresenter(IManageTemplateView view) : base(view) { this.templateModel = new TemplateModel(); this.templateCatalogModel = new TemplateCatalogModel(); }
public SiteTemplateModel(String siteTemplateTitle, ITemplateModel parentModel) { Title = siteTemplateTitle; Models = new List<IModel>(parentModel.Models); ProvisionCodeModels = new List<IProvisionCodeModel>(parentModel.ProvisionCodeModels); }
public LoadTemplatePresenter(ILoadTemplateView view) : base(view) { this.templateModel = new TemplateModel(); }
public static SiteTemplateModel Create(String siteTemplateTitle, ITemplateModel parentSiteModel) { return new SiteTemplateModel(siteTemplateTitle, parentSiteModel); }
public async Task <byte[]> RenderDocumentAsync(ITemplateModel templateModel) { string html = await this.htmlRenderingService.RenderAsync(templateModel); return(await this.pdfService.RenderPdfAsync(html)); }