Exemplo n.º 1
0
 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");
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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
                       };
        }
Exemplo n.º 6
0
        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);
 }
Exemplo n.º 8
0
 public TemplatePresenter()
 {
     templateModel = new TemplateModel();
 }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 11
0
 public LoadTemplatePresenter(ILoadTemplateView view)
     : base(view)
 {
     this.templateModel = new TemplateModel();
 }
Exemplo n.º 12
0
 public static SiteTemplateModel Create(String siteTemplateTitle, ITemplateModel parentSiteModel)
 {
     return new SiteTemplateModel(siteTemplateTitle, parentSiteModel);
 }
Exemplo n.º 13
0
        public async Task <byte[]> RenderDocumentAsync(ITemplateModel templateModel)
        {
            string html = await this.htmlRenderingService.RenderAsync(templateModel);

            return(await this.pdfService.RenderPdfAsync(html));
        }