public static void SellerTemp3() { string newline = Environment.NewLine; string templates = "SendRFQTemplate(SellerIds,Host) ::= \"$SellerIds:{SellerId|<a href=\\\"$Host$/Seller/About\\\" target=\\\"_blank\\\" title=\\\"$GetSellerName(SellerId)$\\\">$SellerId$</a>}; separator=\\\",\\\"$\""; templates += newline + "OfflineOrderTemplate(OrderNumber) ::= \"Order #: $OrderNumber$\""; templates += newline + "GetSellerName(SellerName) ::= \"$SellerName$\""; TemplateGroup templateGroup = new TemplateGroupString("[string]", templates, '$', '$'); //发送RFQ Template e = templateGroup.GetInstanceOf("SendRFQTemplate"); e.Add("Host", "http://newegg.com"); e.Add("SellerIds", "BG9H"); e.Add("SellerIds", "BHS9"); if (!e.impl.HasFormalArgs || (e.impl.HasFormalArgs && e.impl.TryGetFormalArgument("SellerIds1") != null)) { e.Add("SellerIds1", ""); } string result = e.Render(); //离线订单 e = templateGroup.GetInstanceOf("OfflineOrderTemplate"); e.Add("OrderNumber", "1234567890"); result += e.Render(); }
private static void generateTeX(Data data, TextBox?outputBox) { string strTemplate; using (var templateStream = typeof(Generators).Assembly.GetManifestResourceStream(templateFile)) { if (templateStream == null) { updateTextBox(outputBox, emptyStream); Console.Error.WriteLine(emptyStream); return; } var streamReader = new StreamReader(templateStream, Encoding.UTF8); strTemplate = streamReader.ReadToEnd(); } TemplateGroup templateGroup = new TemplateGroupString(strTemplate); var template = templateGroup.GetInstanceOf("main"); template.Add("data", data); var tex = template.Render(); File.WriteAllText(fName, tex); }
protected TemplateGroup GetTemplateGroupFromResource(string templateName) { var tg = new TemplateGroupString(templateName.Replace("_", "."), Resources.ResourceManager.GetString(templateName)); tg.ErrorManager = new ErrorManager(ERROR_LISTENER); tg.Load(); return(tg); }
static TemplateGroup LoadTemplateGroup(string resourceName) { var commonTemplate = new TemplateGroupString(Resources.CommonTemplate); var templateGroup = new TemplateGroupString(resourceName); templateGroup.ImportTemplates(commonTemplate); return(templateGroup); }
/// <summary> /// Create a template group from a string group definition. /// </summary> /// <param name="context">The <see cref="Cmdlet"/> context to throw from.</param> /// <param name="groupDefinition">The string group definition.</param> /// <returns>The compiled template group.</returns> internal static TemplateGroupInfo CreateFromGroupDefinition( Cmdlet context, string groupDefinition) { var group = new TemplateGroupString(groupDefinition); Bind(group, context); return(new TemplateGroupInfo(group)); }
public TemplateGroupString ReadTemplate(string template) { var full = Path.Combine(TemplatesPath, template); var resource = full.Replace('/', '.'); var s = new TemplateGroupString(ReadResource(resource)); s.Load(); return(s); }
/// <summary> /// Create a <see cref="TemplateGroupString"/> from a template definition string. /// </summary> /// <param name="context">The error listener attached to the currently running cmdlet.</param> /// <param name="templateDefinition">The template source to use.</param> /// <returns>The defined template.</returns> internal static TemplateGroupInfo CreateFromTemplateDefinition( Cmdlet context, string templateDefinition) { var group = new TemplateGroupString(string.Empty); Bind(group, context); group.DefineTemplate(Strings.DefaultTemplateName, templateDefinition); group.GetInstanceOf(Strings.DefaultTemplateName).impl.HasFormalArgs = false; return(new TemplateGroupInfo(group)); }
public static void UrlSellerTemp3() { string templates = "SendRFQTemplate(SellerIds) ::= \"$SellerIds:{SellerId|<a href=\\\"\\\" target=\\\"_blank\\\">$SellerId$</a>}; separator=\\\",\\\"$\""; TemplateGroup templateGroup = new TemplateGroupString(string.Empty, templates, '$', '$'); Template e = templateGroup.GetInstanceOf("SendRFQTemplate"); e.Add("SellerIds", "BG9H"); e.Add("SellerIds", "BHS9"); string result = e.Render(); }
public void TestDontTrimJustSpaceBeforeAfterInTemplate() { string templates = "a(x) ::= << foo >>\n"; TemplateGroupString group = new TemplateGroupString(templates); Template st = group.GetInstanceOf("a"); string expected = " foo "; string result = st.Render(); Assert.AreEqual(expected, result); }
public string Serialize() { using var stream = typeof(FunctionManager).Assembly.GetManifestResourceStream("Common.Templates.stg"); using var sr = new StreamReader(stream); var content = sr.ReadToEnd(); TemplateGroup templateGroup = new TemplateGroupString(content); var template = templateGroup.GetInstanceOf("breed"); template.Add("b", this); return(template.Render()); }
public void TestSimpleGroupFromString() { string g = "a(x) ::= <<foo>>\n" + "b() ::= <<bar>>\n"; TemplateGroup group = new TemplateGroupString(g); Template st = group.GetInstanceOf("a"); string expected = "foo"; string result = st.Render(); Assert.AreEqual(expected, result); }
public StringTemplateResult GenerateFromTemplateString(string groupFileContent) { InitData(); TemplateGroup group = new TemplateGroupString(groupFileContent); var errorListener = new CustomStringTemplateErrorListener(); group.ErrorManager = new ErrorManager(errorListener); Template templ = group.GetInstanceOf("TestCasesRoot"); templ.Add("root", this); return(new StringTemplateResult(errorListener, templ.Render())); }
public static void methodTemp() { string templates = "FromatSeller(SellerIDs) ::= <a href=\"\" target=\"_blank\">$SellerIDs$</a>"; TemplateGroup templateGroup = new TemplateGroupString("[string]", templates, '$', '$'); Template st = templateGroup.GetInstanceOf("FromatSeller"); st.Add("SellerIDs", "3"); string result = st.Render(); }
internal static void AssertIsValid(Uri templateUri) { var errors = new List <string>(); var templateContents = GetTemplateContents(templateUri); TemplateGroup group = new TemplateGroupString("template", templateContents, '$', '$'); if (string.IsNullOrWhiteSpace(Render(group, TemplateName))) { errors.Add("Missing property " + TemplateName); } if (string.IsNullOrWhiteSpace(Render(group, TemplateId))) { errors.Add("Missing property " + TemplateId); } else { Guid id; if (!Guid.TryParse(Render(group, TemplateId), out id)) { errors.Add("Property " + TemplateId + " is not a unique id"); } } if (string.IsNullOrWhiteSpace(Render(group, TemplateAllors))) { errors.Add("Missing property " + TemplateAllors); } if (string.IsNullOrWhiteSpace(Render(group, TemplateVersion))) { errors.Add("Missing property " + TemplateVersion); } try { var configurationTemplate = group.GetInstanceOf(TemplateConfiguration); configurationTemplate.Add(DomainKey, Domain.Create()); var configurationXml = new XmlDocument(); configurationXml.LoadXml(configurationTemplate.Render()); } catch { errors.Add("Missing or invalid " + TemplateConfiguration); } if (errors.Count > 0) { throw new Exception(String.Join("\n", errors)); } }
public void TestTrimmedNewlinesBeforeAfterInTemplate() { string templates = "a(x) ::= <<" + newline + "foo" + newline + ">>" + newline; TemplateGroupString group = new TemplateGroupString(templates); Template st = group.GetInstanceOf("a"); string expected = "foo"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestEmptyNoNewlineTemplate() { string template = "t(x) ::= <%%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = ""; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TemplateGroupFormalArgument() { var decl = @"decl(type, name) ::= ""<type> <name>;"""; var templateGroup = new TemplateGroupString("decl", decl, '<', '>'); var template = templateGroup.GetInstanceOf("decl"); Console.WriteLine("template.Name: {0}", template.Name); Console.WriteLine("IsAnonymousSubtemplate: {0}", template.IsAnonymousSubtemplate); var attrs = template.GetAttributes(); DumpIDictionary("GetAttributes", attrs); }
public void TestEarlyEvalOfDefaultArgs() { string templates = "s(x,y={<(x)>}) ::= \"<x><y>\"\n"; // should see x in def arg TemplateGroup group = new TemplateGroupString(templates); Template b = group.GetInstanceOf("s"); b.Add("x", "a"); string expecting = "aa"; string result = b.Render(); Assert.AreEqual(expecting, result); }
public void TestPassThruWithDefaultValueThatLacksDefinitionAbove() { string templates = "a(x) ::= \"<b(...)>\"\n" + // should not set y when it sees "no definition" from above "b(x,y={99}) ::= \"<x><y>\"\n"; TemplateGroup group = new TemplateGroupString(templates); Template a = group.GetInstanceOf("a"); a.Add("x", "x"); string expected = "x99"; string result = a.Render(); Assert.AreEqual(expected, result); }
static void Main(string[] args) { { var template = new Template("<asdf>"); template.Add("asdf", 1); var res = template.Render(); Console.WriteLine(res); } { var tree = Parsing.Parse("1+2"); var template = new Template("<first(asdf.expression).Text>"); template.Add("asdf", tree); var res = template.Render(); Console.WriteLine(res); } { var tg = new TemplateGroupString(@" decl(name, value) ::= ""<name> = <value>;"" "); var template = tg.GetInstanceOf("decl"); template.Add("name", "a"); template.Add("value", "1"); var res = template.Render(); Console.WriteLine(res); } { var tree = Parsing.Parse("1+2") as ArithmeticParser.File_Context; var tg = new TemplateGroupString(@" ex(c) ::= ""<if(c.PLUS)><first(c.expression).Text> PLUS <first(rest(c.expression)).Text><endif>"" "); tg.Verbose = true; var template = tg.GetInstanceOf("ex"); template.Add("c", tree.expression()[0]); var res = template.Render(); Console.WriteLine(res); } { var tree = Parsing.Parse("1+2") as ArithmeticParser.File_Context; var tg = new TemplateGroupString(@" ex(c) ::= ""<if(c.atom)><at(c.atom)><elseif(c.PLUS)><ex(first(c.expression))> PLUS <ex(first(rest(c.expression)))><elseif(c.MINUS)><ex(first(c.expression))> MINUS <ex(first(rest(c.expression)))><elseif(c.TIMES)><ex(first(c.expression))> TIMES <ex(first(rest(c.expression)))><elseif(c.DIV)><ex(first(c.expression))> DIV <ex(first(rest(c.expression)))><elseif(c.POW)><ex(first(c.expression))> POW <ex(first(rest(c.expression)))><elseif(c.LPAREN)><ex(first(c.expression))><endif>"" at(c) ::= ""<c.Text>"" "); tg.Verbose = true; var template = tg.GetInstanceOf("ex"); template.Add("c", tree.expression()[0]); var res = template.Render(); Console.WriteLine(res); } }
public void TestKeepWS() { string template = "t(x) ::= <%" + newline + " <x> <x> hi"+ newline + "%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "99 99 hi"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestPassThruNoMissingArgs() { string templates = "a(x,y) ::= \"<b(y={99},x={1},...)>\"\n" + "b(x,y) ::= \"<x><y>\"\n"; TemplateGroup group = new TemplateGroupString(templates); Template a = group.GetInstanceOf("a"); a.Add("x", "x"); a.Add("y", "y"); string expected = "199"; string result = a.Render(); Assert.AreEqual(expected, result); }
public void TestIgnoreIndent() { string template = "t(x) ::= <%" + newline + " foo"+ newline + " <x>"+ newline + "%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "foo99"; string result = st.Render(); Assert.AreEqual(expected, result); }
// This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called protected override void ProcessRecord() { var templateGroup = new TemplateGroupString(this.SourceName, this.Content); ST4TemplateGroup result = this.TemplateGroup; if (result is null) { result = new ST4TemplateGroup(); result.TemplateGroup = templateGroup; } else { result.TemplateGroup.ImportTemplates(templateGroup); } WriteObject(result); }
public static void SellerTemp() { string templates = "SendRFQTemplate(SellerIds,Host) ::= \"$SellerIds:{SellerId|<a href=\\\"$Host$/Seller/About\\\" target=\\\"_blank\\\" title=\\\"测试\\\">$SellerId$</a>}; separator=\\\",\\\"$\""; TemplateGroup templateGroup = new TemplateGroupString("[string]", templates, '$', '$'); Template e = templateGroup.GetInstanceOf("SendRFQTemplate"); e.Add("Host", "http://newegg.com"); e.Add("SellerIds", "BG9H"); e.Add("SellerIds", "BHS9"); if (!e.impl.HasFormalArgs || (e.impl.HasFormalArgs && e.impl.TryGetFormalArgument("SellerIds1") != null)) { e.Add("SellerIds1", ""); } string result = e.Render(); }
/// <summary> /// EndProcessing method. /// </summary> protected override void EndProcessing() { var group = new TemplateGroupString(Definition) { Listener = new ErrorListener(this) }; var groupInfo = new TemplateGroupInfo(group); group.RegisterModelAdaptor(typeof(PSObject), new PSObjectAdaptor()); group.RegisterModelAdaptor(typeof(Type), new TypeAdapter()); group.RegisterRenderer(typeof(DateTime), new DateRenderer()); group.RegisterRenderer(typeof(DateTimeOffset), new DateRenderer()); group.Listener = ErrorManager.DefaultErrorListener; WriteObject(groupInfo); }
public void TestDelimitersClauseInGroupString() { string templates = "delimiters \"$\", \"$\"" + newline + "method(name) ::= <<" + newline + "$stat(name)$" + newline + ">>" + newline + "stat(name,value=\"99\") ::= \"x=$value$; // $name$\"" + newline ; TemplateGroup group = new TemplateGroupString(templates); Template b = group.GetInstanceOf("method"); b.Add("name", "foo"); string expecting = "x=99; // foo"; string result = b.Render(); Assert.AreEqual(expecting, result); }
public void TestEvalExprEventForSpecialCharacter() { string templates = "t() ::= <<[<\\n>]>>\n"; // 012 345 TemplateGroupString g = new TemplateGroupString(templates); Template st = g.GetInstanceOf("t"); st.impl.Dump(); StringWriter writer = new StringWriter(); List <InterpEvent> events = st.GetEvents(new AutoIndentWriter(writer, "\n")); string expected = "[EvalExprEvent{self=/t(), expr='[', source=[0..1), output=[0..1)}, " + "EvalExprEvent{self=/t(), expr='\\n', source=[2..4), output=[1..2)}, " + "EvalExprEvent{self=/t(), expr=']', source=[5..6), output=[2..3)}, " + "EvalTemplateEvent{self=/t(), output=[0..3)}]"; string result = events.ToListString(); Assert.AreEqual(expected, result); }
public void TestRegion() { string template = "t(x) ::= <%\n" + "<@r>\n" + " Ignore\n"+ " newlines and indents\n"+ "<x>\n\n\n" + "<@end>\n" + "%>\n"; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "Ignorenewlines and indents99"; string result = st.Render(); Assert.AreEqual(expected, result); }
public static void UrlSellerTemp2() { //string templates = // "test(names,phones) ::= \"<foo([names,phones])>\"" + "\n" + // "foo(items) ::= \"<items:{a | *<a>*}>\"" + "\n"; //TemplateGroup templateGroup = new TemplateGroupString(templates); //TemplateGroup templateGroup = new TemplateGroupString("[string]", templates); string templates = "test(names) ::= \"$names:{a | *$a$*}$\""; TemplateGroup templateGroup = new TemplateGroupString("[string]", templates, '$', '$'); Template e = templateGroup.GetInstanceOf("test"); e.Add("names", "Ter"); e.Add("names", "Tom"); string result = e.Render(); }