private string GetParsedView(IView view, string viewTemplate) { if (view.ModelType == null) { _templateService.Compile(viewTemplate, view.ViewName); return(_templateService.Run(view.ViewName)); } _templateService.Compile(viewTemplate, view.ModelType, view.ViewName); return(_templateService.Run(view.ViewName, view.Model)); }
private void CompileLayouts(string languageCode) { _logger("Compiling PlainText Razor Layout for {0}".FormatWith(languageCode)); var plainTextLayoutTemplate = _emailResourceProvider.GetPlainTextLayoutTemplate(); _templateService.Compile(plainTextLayoutTemplate, typeof(string), GetPlainTextLayoutName(languageCode)); _logger("Compiling Html Razor Layout for {0}".FormatWith(languageCode)); var htmlLayoutTemplate = _emailResourceProvider.GetHtmlLayoutTemplate(); _templateService.Compile(htmlLayoutTemplate, typeof(string), GetHtmlLayoutName(languageCode)); }
public Templater(string filepath) { file = filepath; service = new TemplateService(); service.Compile(File.ReadAllText(filepath), typeof(StatsModel), "stats"); string parent = Path.GetDirectoryName(filepath); if (parent == string.Empty) parent = "."; string shortname = Path.GetFileName(file); // File watcher normally uses a glob pattern to match a series of // files, but since we are just watching for one file we just use // the name of the file as the glob. watcher = new FileSystemWatcher(parent, shortname); watcher.Changed += watcher_Changed; watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.EnableRaisingEvents = true; }
/// <summary> /// Compiles the email body using the specified Razor view and model. /// </summary> public void Compile <T>(T model, bool trimBody, string externalViewPath = null) { string body = string.Empty; AlternateView altView; var hasTxtView = false; try { var itemplate = _templateService.Compile(_viewName, _masterName, externalViewPath); body = itemplate.Run(model, _viewBag); } catch (TemplateResolvingException) { if (!hasTxtView) { throw new NoViewsFoundException( string.Format( "Could not find any HBS views named [{0}] in the path [{1}]. Ensure that you specify the format in the file name (ie: {0}.hbs)", _viewName, _viewPath)); } } catch (NullReferenceException ex) { var error = string.Format("{0}\n{1}\n{2}\n{3}\n\n{4}\nFile:{5}", ex.Message, ex.InnerException, ex.Data, ex.Source, ex.StackTrace, _viewName); throw new NullReferenceException(error); } if (trimBody) { body = body.Trim(); } altView = AlternateView.CreateAlternateViewFromString(body, MessageEncoding ?? Encoding.Default, MediaTypeNames.Text.Html); MailAttributes.AlternateViews.Add(altView); }
/// <summary> /// Compiles the specified template. /// </summary> /// <param name="razorTemplate">The string template.</param> /// <param name="modelType">The model type.</param> /// <param name="cacheName">The name of the template type in the cache.</param> public void Compile(string razorTemplate, Type modelType, string cacheName) { _proxy.Compile(razorTemplate, modelType, cacheName); }
/// <summary> /// Compiles the specified template. /// </summary> /// <param name="razorTemplate">The string template.</param> /// <param name="modelType">The model type.</param> /// <param name="cacheName">The name of the template type in the cache.</param> /// <param name="logger"></param> public void Compile(string razorTemplate, Type modelType, string cacheName, ILogger logger) { _proxy.Compile(razorTemplate, modelType, cacheName, logger); }
public Type Compile(Stream razorTemplate) { return(_razorService.Compile(razorTemplate, null)); }
public void Compile(string razorTemplate, string name) { _inner.Compile(razorTemplate, name); }
/// <summary> /// Compiles the specified template. /// </summary> /// <param name="razorTemplate">The string template.</param> /// <param name="name">The name of the template.</param> public void Compile(string razorTemplate, string name) { _proxy.Compile(razorTemplate, name); }
public void Compile(ITemplate template, String cacheName) { _templateService.Compile(template.Content, template.Meta.Type, cacheName); template.CachedTemplateIdentifier = cacheName; }