public void SetUp() { var library = new DefaultHtmlConventions().Library; theTemplates = new TemplateWriter(new ActiveProfile(), library, new DefaultElementNamingConvention(), new InMemoryServiceLocator()); }
public void SetUp() { _writer = new TemplateWriter(writer => { _delegateInvoked = true; writer.Write("Content"); }); }
public void SetUp() { var library = new DefaultHtmlConventions().Library; var namingConventions = new DefaultElementNamingConvention(); var activators = new ElementIdActivator(namingConventions); theTemplates = new TemplateWriter(new ActiveProfile(), library, new TagRequestBuilder(new []{activators})); }
public void SetUp() { var library = new DefaultHtmlConventions().Library; var namingConventions = new DefaultElementNamingConvention(); var activators = new ElementIdActivator(namingConventions); theTemplates = new TemplateWriter(new ActiveProfile(), library, new TagRequestBuilder(new [] { activators })); }
public void TestTemplateWriter() { var writer = new TemplateWriter("one {two} three {four} five {six} seven"); writer.Add("two", "too"); writer.Add("two", "2"); var result = writer.ToString(); Assert.AreEqual("one 2 three five seven", result); }
public void SetUp() { var library = new DefaultHtmlConventions().Library; theTemplates = new TemplateWriter(new ActiveProfile(), library, new TagRequestBuilder(new ITagRequestActivator[0])); theTemplates.AddTemplate("foo", new HtmlTag("span").MustacheText("foo")); theTemplates.AddTemplate("bar", "some {{bar}} text"); templates = theTemplates.WriteAll(); }
private SlickGridFormatter determineFormatter(IGridDefinition grid, IColumnPolicies policies) { if (grid.DefaultFormatter != null) { return(grid.DefaultFormatter); } if (grid.UsesHtmlConventions) { Property("displaySubject", TemplateWriter.SubjectFor(Accessor, ElementConstants.Display)); return(SlickGridFormatter.Underscore); } return(policies.FormatterFor(Accessor)); }
private static void CreateFile(bool project) { Console.Write("\n" + (project ? "Projektnamn:" : "Mötesnamn")); var projectName = Console.ReadLine(); Console.Write("Titel:"); var title = Console.ReadLine(); var templateWriter = new TemplateWriter(); var folder = project ? "Projekt & Features" : "Möten"; var folderPath = $@"H:\dokument\-=[Dokument Sparas\{folder}\{projectName}"; Directory.CreateDirectory(folderPath); templateWriter.PrintToFile($@"{folderPath}\Anteckningar.txt", title.Length == 0 ? projectName : title, "Anteckningar"); }
/// <summary> /// Generates code files from an edmx file. /// </summary> /// <param name="edmxString">The EDMX file as a string.</param> /// <param name="targetLanguage">Specifies the target language. Possible values are csharp, php, etc.</param> /// <returns></returns> static private IEnumerable <TextFile> MetadataToClientSource(string edmxString, string targetLanguage, IEnumerable <string> properties, string endpointVersion = "v1.0") { if (String.IsNullOrEmpty(edmxString)) { throw new ArgumentNullException("edmxString", "The EDMX file string contains no content."); } var reader = new OdcmReader(); var writer = new TemplateWriter(targetLanguage, properties, endpointVersion); writer.SetConfigurationProvider(new ConfigurationProvider()); var model = reader.GenerateOdcmModel(new List <TextFile> { new TextFile("$metadata", edmxString) }); return(writer.GenerateProxy(model)); }
void ITemplate.Run(ExecuteContext context, TextWriter textWriter) { var builder = new StringBuilder(); _executeContextAdapter = new ExecuteContextAdapter(this, context); using (var writer = new StringWriter(builder)) { _executeContextAdapter.CurrentWriter = writer; OnStart(); Execute(); OnEnd(); _executeContextAdapter.CurrentWriter = null; } var parent = ResolveLayout(Layout); if (parent == null && string.IsNullOrEmpty(Layout)) { var result = builder.ToString(); textWriter.Write(result); return; } if (parent == null) { throw new InvalidOperationException("Layout template was not found."); } parent.SetData(null, ViewBag); var exposingParent = parent as ExposingTemplate; if (exposingParent == null) { throw new InvalidOperationException("Unexpected layout template base type."); } exposingParent._templateVisitor = _templateVisitor; var bodyWriter = new TemplateWriter(tw => tw.Write(builder.ToString())); _executeContextAdapter.PushBody(bodyWriter); _executeContextAdapter.PushSections(); parent.Run(_executeContextAdapter.Context, textWriter); }
public TemplateWriter Partial(string templateName, object model = null) { var template = this._templateService.Resolve(templateName, model); if (template == null) { throw new ArgumentException("No template could be resolved with the name '" + templateName + "'"); } var templateWriter = null as TemplateWriter; try { templateWriter = new TemplateWriter(tw => tw.Write(template.Run(this._executeContext))); } catch (TemplateCompilationException ex) { var error = string.Format("{0}\n{1}\n{2}\n{3}\n\n{4}\n(Partial){5}", ex.Message, ex.InnerException, ex.Data, ex.Source, ex.StackTrace, templateName); throw new Exception(error); } return(templateWriter); }
public void SelectFormatterAndEditor(IGridDefinition grid, IColumnPolicies policies) { if (Editor() == null && grid.AllColumnsAreEditable) { if (grid.UsesHtmlConventions) { Editor(SlickGridEditor.Underscore); Property("editorSubject", TemplateWriter.SubjectFor(Accessor, ElementConstants.Editor)); } else { Editor(policies.EditorFor(Accessor)); } } if (Formatter() == null) { var formatter = determineFormatter(grid, policies); if (formatter != null) { Formatter(formatter); } } }
/// <summary> /// Parses the template using a regular expression and converts it /// to a series of delegate calls that render the template. After this /// method is executed the member variable _writer will reference the /// root level writer that renders the template. /// </summary> private void Parse() { MatchCollection sections = _rxFields.Matches(_source); Dictionary<string, TemplateWriter> writerLookup = new Dictionary<string, TemplateWriter>(); List<TemplateWriter> writerList = new List<TemplateWriter>(); _fieldNames = new List<string>(sections.Count); int curIndex = 0; foreach (Match m in sections) { _fieldNames.Add(m.Groups["field"].Value); if (m.Index > curIndex) { // create a literal from curIndex to m.Index string literal = _source.Substring(curIndex, m.Index - curIndex); writerList.Add(LiteralWriter(literal)); } string field = m.Value; TemplateWriter writer; if (!writerLookup.TryGetValue(field, out writer)) { CaptureCollection parts = m.Groups["parts"].Captures; string format = m.Groups["format"].Value.Trim(); if (string.IsNullOrEmpty(format)) writer = FieldWriter(parts); else { format = "{0" + format + "}"; writer = FieldWriter(parts, format); } writerLookup.Add(field, writer); } writerList.Add(writer); curIndex = m.Index + m.Length; } if (curIndex < _source.Length) { // generate a literal for the remaining text string literal = _source.Substring(curIndex); writerList.Add(LiteralWriter(literal)); } // Create an aggregate writer that calls all the // writers that make up the template TemplateWriter[] writers = writerList.ToArray(); _writer = delegate(TextWriter textWriter, TemplateFieldAccessor root) { for (int i = 0; i < writers.Length; i++) writers[i](textWriter, root); }; }
public GMailUserjs(string path, PackInfo pack) : base(pack, "Gmail", path) { this.path = packRootPath + String.Format("{0}/", PackFullName); this.imagePath = this.path + "emo/"; Directory.CreateDirectory(this.imagePath); tw = new TemplateWriter("chrome.user.js", String.Format("{0}{1}.user.js", this.path, this.PathPackFullName), pack); tw.AddReplacement("__PACKURL__", @"http://artyfarty.ru/emo/"); }
public void SetUp() { var library = new DefaultHtmlConventions().Library; theTemplates = new TemplateWriter(new ActiveProfile(), library, new DefaultElementNamingConvention(), new InMemoryServiceLocator()); theTemplates.AddTemplate("foo", new HtmlTag("span").MustacheText("foo")); theTemplates.AddTemplate("bar", "some {{bar}} text"); templates = theTemplates.WriteAll(); }
internal void PushBody(TemplateWriter writer) { writer.ThrowIfNull("writer"); _bodyWriters.Push(writer); }