public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder) { var partialName = viewSourceReader.CurrentInputLine.NormalizedText.Trim(); if (string.IsNullOrEmpty(partialName)) { if (viewSourceReader.ViewSourceQueue.Count == 0) { throw new InvalidOperationException(NoPartialName); } var templatePath = viewSourceReader.ViewSourceQueue.Dequeue(); viewSourceReader.MergeTemplate(templatePath, true); } else { partialName = partialName.Insert(partialName.LastIndexOf(@"\", StringComparison.OrdinalIgnoreCase) + 1, "_"); IViewSource viewSource; try { viewSource = options.TemplateContentProvider.GetViewSource(partialName, viewSourceReader.ViewSources); } catch (FileNotFoundException) { //ToDo: render content behind the ? tag viewSource = null; } viewSourceReader.ViewSourceModifiedChecks.Add(() => viewSource.IsModified); viewSourceReader.MergeTemplate(viewSource, true); } return EmptyClosingAction; }
public ViewSourceReader(TemplateOptions options, IList<IViewSource> viewSources) { this.options = options; ViewSources = viewSources; ViewSourceQueue = new Queue<IViewSource>(); ViewSourceModifiedChecks = new List<Func<bool>>(); //do a for here to avoid a modified closure for (var index = 0; index < viewSources.Count; index++) { var viewSource = viewSources[index]; ViewSourceModifiedChecks.Add(() => viewSource.IsModified); ViewSourceQueue.Enqueue(viewSource); } if (options.UseTabs) { _singleIndent = "\t"; } else { _singleIndent = string.Empty.PadLeft(options.IndentSize); } inputLines = new LinkedList<InputLine>(); inputLines.AddLast(new InputLine(string.Empty, 0, options.IndentSize)); inputLines.AddLast(new InputLine(EofMarkupRule.SignifierChar, 1, options.IndentSize)); CurrentNode = inputLines.First.Next; }
public TemplateParser(TemplateOptions options, TemplateClassBuilder templateClassBuilder, IList<IViewSource> viewSources) { BlockClosingActions = new Stack<BlockClosingAction>(); viewSourceReader = new ViewSourceReader(options, viewSources); Options = options; builder = templateClassBuilder; }
internal CompiledTemplate(TemplateOptions options, IList<IViewSource> layoutViewSources, Type templateBaseType, object context) { this.options = options; _layoutViewSources = layoutViewSources; _templateBaseType = templateBaseType; this.context = context; Compile(context); }
public TemplateEngine( TemplateOptions options ) { Invariant.ArgumentNotNull( options, "options" ); Options = options; _compiledTemplateCache = new Dictionary<string, CompiledTemplate>(); NHamlConfigurationSection.UpdateTemplateOptions( Options ); Options.TemplateBaseTypeChanged += (sender, args) => ClearCompiledTemplatesCache(); Options.TemplateCompilerChanged += (sender, args) => ClearCompiledTemplatesCache(); }
public HamlTemplateFactory(string baseTemplatePath) { var templateOptions = new TemplateOptions(); templateOptions.EncodeHtml = false; templateOptions.AutoRecompile = true; templateOptions.IndentSize = 2; templateOptions.TemplateBaseType = typeof(HamlTemplate); var fileTemplateResolver = new FileTemplateContentProvider(); fileTemplateResolver.PathSources = new [] { baseTemplatePath }.ToList(); this.templateEngine = new TemplateEngine(templateOptions) { TemplateContentProvider = fileTemplateResolver }; }
private TemplateOptions buildTemplateOptions(IComponentContext c) { var settings = c.Resolve<ToastSettings>(); // setup template content provider var tmplProvider = new FileTemplateContentProvider(); tmplProvider.PathSources.Clear(); tmplProvider.PathSources.Add("Content/haml"); // build the template options var opts = new TemplateOptions { AutoRecompile = true, UseTabs = false, IndentSize = 2, TemplateContentProvider = tmplProvider, OutputDebugFiles = settings.DebugMode, }; // add all assemblies required to be referenced by the template code var refs = new[] { typeof(ToastTemplate).Assembly, typeof(ToastSettings).Assembly, typeof(System.Web.HttpContext).Assembly }; opts.References.Clear(); Array.ForEach(refs, opts.AddReference); opts.AddReference("Toast.exe"); // add Toast-specific usings var usings = new[] { "Toast", "Toast.Web", "Toast.Web.Tokens" }; Array.ForEach(usings, opts.AddUsing); return opts; }