public static Template LoadTemplate(string path) { Template template; if (!CompiledTemplates.TryGetValue(path, out template)) { template = new Template(); string assetPath = Path.Combine(ConfigService.RootPath, "assets\\custom", path); if (File.Exists(assetPath)) { using (var reader = FileService.ReadFile(assetPath)) { template.Load(reader); } } else { string assetStream = String.Concat("RobMensching.TinyBugs.assets.", path.Replace('/', '.').Replace('\\', '.')); using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assetStream)) { StreamReader s = new StreamReader(stream); template.Load(s); } } //if (!CompiledTemplates.TryAdd(path, template)) //{ // template = CompiledTemplates[path]; //} } return template; }
public void Render(ViewContext viewContext, TextWriter writer) { var templatePath = _controllerContext.HttpContext.Server.MapPath(_viewPath); var templateSource = File.ReadAllText(templatePath); var template = new Template(); template.Load(new StringReader(templateSource)); template.Render(viewContext.ViewData, writer, null); }
/// <summary> /// Constructor /// </summary> public TemplateWriter(string pTemplateName) { _packageName = GetType().FullName.Split(new[] {'.'})[0]; _files = Assembly.GetCallingAssembly(); _template = new Template(); _template.Load(new StringReader(getTemplateAsString(pTemplateName))); }
public static void Template(TextReader reader, object data, TextWriter writer, TemplateLocator templateLocator, RenderContextBehaviour renderContextBehaviour = null) { var template = new Template(); template.Load(reader); var renderBehaviour = renderContextBehaviour ?? RenderContextBehaviour.GetDefaultRenderContextBehaviour(); template.Render(data, writer, templateLocator, renderBehaviour); }
public static void RenderStache(this ManosModule mod, IManosContext ctx, string template, object obj) { var t = new Template (); var path = Path.Combine (TEMPLATE_DIR, template); using (var r = new StreamReader (path)) { t.Load (r); } t.Render (obj, new StreamWriter (ctx.Response.Stream), locator.GetTemplate); ctx.Response.End (); }
public Template GetTemplate(string name) { string path = Path.Combine(_directory, name + _extension); if (File.Exists(path)) { string text = File.ReadAllText(path); var reader = new StringReader(text); var template = new Template(); template.Load(reader); return template; } return null; }
private Template LoadTemplate(string path) { var key = "Nustache:" + path; if (_controllerContext.HttpContext.Cache[key] != null) { return (Template)_controllerContext.HttpContext.Cache[key]; } var templatePath = _controllerContext.HttpContext.Server.MapPath(path); var templateSource = File.ReadAllText(templatePath); var template = new Template(); template.Load(new StringReader(templateSource)); _controllerContext.HttpContext.Cache.Insert(key, template, new CacheDependency(templatePath)); return template; }
public Template GetTemplate(string name) { foreach (var directory in _directories) { var path = Path.Combine(directory, name + _extension); if (File.Exists(path)) { var text = File.ReadAllText(path); var reader = new StringReader(text); var template = new Template(); template.Load(reader); return(template); } } return(null); }
public override void Render(RenderContext context) { var value = context.GetValue(_path); var lambda = CheckValueIsDelegateOrLambda(value); if (lambda != null) { var lambdaResult = lambda().ToString(); lambdaResult = _escaped ? Encoders.HtmlEncode(lambdaResult.ToString()) : lambdaResult.ToString(); using (System.IO.TextReader sr = new System.IO.StringReader(lambdaResult)) { Template template = new Template(); template.StartDelimiter = "{{"; template.EndDelimiter = "}}"; template.Load(sr); context.Enter(template); template.Render(context); context.Exit(); return; } } var helper = value as HelperProxy; if (helper != null) { helper(data => { }, data => { }); } else if (value != null) { context.Write(_escaped ? Encoders.HtmlEncode(value.ToString()) : value.ToString()); } }
public override void Render(RenderContext context) { var value = context.GetValue(_path); var lambda = CheckValueIsDelegateOrLambda(value); if(lambda != null) { var lambdaResult = lambda().ToString(); lambdaResult = _escaped ? Encoders.HtmlEncode(lambdaResult.ToString()) : lambdaResult.ToString(); using (System.IO.TextReader sr = new System.IO.StringReader(lambdaResult)) { Template template = new Template(); template.StartDelimiter = "{{"; template.EndDelimiter = "}}"; template.Load(sr); context.Enter(template); template.Render(context); context.Exit(); return; } } var helper = value as HelperProxy; if (helper != null) { helper(data => { }, data => { }); } else if (value != null) { context.Write(_escaped ? Encoders.HtmlEncode(value.ToString()) : value.ToString()); } }
/// <summary> /// Constructor /// </summary> public EmailTask(iJobService pJobService, iEmailService pEmailService, iMailingListService pMailingList) { if (pJobService == null || pEmailService == null || pMailingList == null) { throw new NullReferenceException(); } _jobService = pJobService; _emailService = pEmailService; _mailingList = pMailingList; Resources resources = new Resources(GetType(), "Email.Templates"); string markdown = resources.ReadAsString("email.md"); using (StringReader reader = new StringReader(markdown)) { _template = new Template(); _template.Load(reader); } _markdown = new Markdown { ExtraMode = true, SafeMode = false }; }
static Template GetTemplate( MustacheConfiguration configuration, string templateName) { var templatePath = Path.Combine( configuration.TemplateRootPath, String.Concat(templateName, configuration.TemplateFileExtension)); if (!File.Exists(templatePath)) throw new InvalidOperationException("Template path does not exist."); var templateSource = File.ReadAllText(templatePath); var template = new Template(); template.Load(new StringReader(templateSource)); return template; }
public static void Template(TextReader reader, object data, TextWriter writer, TemplateLocator templateLocator) { var template = new Template(); template.Load(reader); template.Render(data, writer, templateLocator); }
static Template GetTemplate(string templateName) { var templateSource = ReadEmbeddedTemplate(templateName); var template = new Template(); template.Load(new StringReader(templateSource)); return template; }
public override void Render(RenderContext context) { var value = context.GetValue(Name); var lambda = CheckValueIsDelegateOrLambda(value); if (lambda != null) { var lambdaResult = lambda(InnerSource()).ToString(); using (TextReader sr = new StringReader(lambdaResult)) { var template = new Template(); template.StartDelimiter = context.ActiveStartDelimiter; template.EndDelimiter = context.ActiveEndDelimiter; template.Load(sr); context.Enter(template); template.Render(context); context.Exit(); } return; } var helper = value as HelperProxy; if (helper != null) { helper(data => { context.Enter(this); context.Push(data); RenderParts(context); context.Pop(); context.Exit(); }, data => { if (Inverse != null) { context.Enter(Inverse); context.Push(data); Inverse.RenderParts(context); context.Pop(); context.Exit(); } }); return; } foreach (var item in context.GetValues(Name)) { context.Enter(this); context.Push(item); base.Render(context); context.Pop(); context.Exit(); } }
private Template Template(string text) { var template = new Template(); template.Load(new StringReader(text)); return template; }
public Template FindTemplate(string name) { if (name == null) { name = "default"; } foreach (var ext in TEMPLATE_LANGS) { var tpl = Path.Combine (TemplateDir, name.Trim () + "." + ext); if (!File.Exists (tpl)) { continue; } using (var reader = File.OpenText (tpl)) { var template = new Template (); template.Load (reader); return template; } } return null; }
public override void Render(RenderContext context) { var value = context.GetValue(Name); var lambda = CheckValueIsDelegateOrLambda(value); if (lambda != null) { var lambdaResult = lambda(InnerSource()).ToString(); using(TextReader sr = new StringReader(lambdaResult)) { var template = new Template(); template.StartDelimiter = context.ActiveStartDelimiter; template.EndDelimiter = context.ActiveEndDelimiter; template.Load(sr); context.Enter(template); template.Render(context); context.Exit(); } return; } var helper = value as HelperProxy; if (helper != null) { helper(data => { context.Enter(this); context.Push(data); RenderParts(context); context.Pop(); context.Exit(); }, data => { if (Inverse != null) { context.Enter(Inverse); context.Push(data); Inverse.RenderParts(context); context.Pop(); context.Exit(); } }); return; } foreach (var item in context.GetValues(Name)) { context.Enter(this); context.Push(item); base.Render(context); context.Pop(); context.Exit(); } }