protected override void Arrange() { var expectedTemplateString = @"using EdFi.Ods.Xml.XmlMetadata;"; var templatesByTemplateName = new Dictionary <string, string> { { templateName, expectedTemplateString }, { "template2", "template2 string" } }; _templateWriterData = new TemplateWriterData { Model = new { NamespaceName = "testNamespace", ClassName = "testClass", InterfaceName = "testInterfaceName" }, TemplateSet = new TemplateSet { Name = templateName } }; _mustacheTemplateProvider = Stub <IMustacheTemplateProvider>(); A.CallTo(() => _mustacheTemplateProvider.GetMustacheTemplates()) .Returns(templatesByTemplateName); _templateWriter = new TemplateWriter(_mustacheTemplateProvider); }
public virtual int Write(ITemplateWriter @out, CultureInfo culture, ITemplateErrorListener listener) { Interpreter interp = new Interpreter(Group, culture, new ErrorManager(listener), false); TemplateFrame frame = new TemplateFrame(this, null); return(interp.Execute(@out, frame)); }
public virtual int Write(ITemplateWriter @out, CultureInfo locale) { Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, impl.NativeGroup.ErrorManager); interp.SetDefaultArguments(this); return(interp.Execute(@out, this)); }
public virtual int Write(ITemplateWriter @out, CultureInfo locale, ITemplateErrorListener listener) { Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, new ErrorManager(listener)); interp.SetDefaultArguments(this); return(interp.Execute(@out, this)); }
public virtual List<InterpEvent> GetEvents(CultureInfo culture, ITemplateWriter writer) { Interpreter interp = new Interpreter(Group, culture, true); TemplateFrame frame = new TemplateFrame(this, null); interp.Execute(writer, frame); // Render and track events return interp.GetEvents(); }
public static string RenderToString(this ITemplateWriter templateWriter, Dictionary <string, object> scopeArgs) { var writer = StringWriterCache.Allocate(); templateWriter.Write(null, writer, scopeArgs); return(StringWriterCache.ReturnAndFree(writer)); }
public virtual List <InterpEvent> GetEvents(CultureInfo culture, ITemplateWriter writer) { Interpreter interp = new Interpreter(groupThatCreatedThisInstance, culture); interp.Execute(writer, this); // Render and track events return(interp.GetEvents()); }
public virtual int Write(ITemplateWriter @out, CultureInfo culture) { Interpreter interp = new Interpreter(Group, culture, impl.NativeGroup.ErrorManager, false); TemplateFrame frame = new TemplateFrame(this, null); return(interp.Execute(@out, frame)); }
public GridTagWriter(IColumnPolicies policies, ITemplateWriter templates, IAssetRequirements assets, IUrlRegistry urls, T grid) { _policies = policies; _templates = templates; _assets = assets; _urls = urls; _grid = grid; }
public CreateCommand(IConsole console, ILogger <CreateCommand> logger, IConsoleReader consoleReader, IProjectService projectService, IProviderService providerService, IExternalServiceService externalServiceService, ITemplateWriter templateWriter) : base(console, logger) { _consoleReader = consoleReader; _projectService = projectService; _providerService = providerService; _externalServiceService = externalServiceService; _templateWriter = templateWriter; }
public GridTagWriter(IColumnPolicies policies, ITemplateWriter templates, IAssetRequirements assets, IUrlRegistry urls, T grid, IFieldAccessService accessService) { _policies = policies; _templates = templates; _assets = assets; _urls = urls; _grid = grid; _accessService = accessService; }
public static string RenderToString(this ITemplateWriter templateWriter, Dictionary <string, object> scopeArgs) { var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { templateWriter.Write(null, writer, scopeArgs); } return(sb.ToString()); }
public TemplateProcessor( IGeneratorProvider generatorProvider, ITemplateWriter templateWriter, ITemplateSetProvider templateSetProvider, ITemplateContextProvider templateContextProvider) { _templateWriter = Preconditions.ThrowIfNull(templateWriter, nameof(templateWriter)); _templateSetProvider = Preconditions.ThrowIfNull(templateSetProvider, nameof(templateSetProvider)); _templateContextProvider = Preconditions.ThrowIfNull(templateContextProvider, nameof(templateContextProvider)); _generatorProvider = Preconditions.ThrowIfNull(generatorProvider, nameof(generatorProvider)); }
void IGridColumn.WriteTemplates(ITemplateWriter writer) { if (Editor() == SlickGridEditor.Underscore) { writer.AddElement(Accessor, ElementConstants.Editor); } if (Formatter() == SlickGridFormatter.Underscore) { writer.AddElement(Accessor, ElementConstants.Display); } }
protected override void Arrange() { _assemblyData = new AssemblyData { AssemblyName = "testAssembly", Path = "testFolder", TemplateSet = "standard" }; _templateSet = new TemplateSet { Name = "Entities.mustache", Driver = "Entities", OutputPath = "Models\\Entities\\Entities.generated.cs" }; var templates = new List <TemplateSet> { _templateSet }; var model = new object(); _templateContext = new TemplateContext(); _templateWriter = Stub <ITemplateWriter>(); _codeRepositoryProvider = Stub <ICodeRepositoryProvider>(); _templateSetProvider = Stub <ITemplateSetProvider>(); _templateContextProvider = Stub <ITemplateContextProvider>(); _generator = Stub <IGenerator>(); _generatorProvider = Stub <IGeneratorProvider>(); A.CallTo(() => _codeRepositoryProvider.GetResolvedCodeRepositoryByName(A <string> ._, A <string> ._)) .Returns("testRepo\\testFolder"); A.CallTo(() => _templateSetProvider.GetTemplatesByName(A <string> ._)) .Returns(templates); A.CallTo(() => _templateContextProvider.Create(A <AssemblyData> ._)) .Returns(_templateContext); A.CallTo(() => _generator.Generate(A <TemplateContext> ._)) .Returns(model); A.CallTo(() => _generatorProvider.GetGeneratorByDriverName(A <string> ._)) .Returns(_generator); _templateProcessor = new TemplateProcessor( _generatorProvider, _templateWriter, _templateSetProvider, _templateContextProvider); }
public ReportGenerator(IResponseMapper responseMapper, IVeracodeRepository veracodeRepository, IOutputWriter outputWriter, IGenericReadOnlyRepository <Template> templateRepository, ITemplateWriter templateWriter, IZippingService zippingService, IOptions <FlawFilterConfiguration> flawFilter ) { _responseMapper = responseMapper; _veracodeRepository = veracodeRepository; _outputWriter = outputWriter; _templateRepository = templateRepository; _templateWriter = templateWriter; _zippingService = zippingService; _flawFilter = flawFilter.Value; }
void IGridDefinition.WriteAnyTemplates(ITemplateWriter writer) { _columns.Each(x => x.WriteTemplates(writer)); }
public void SetUp() { theColumn = new ColumnDefinition<ColumnDefTarget, string>(x => x.Name, new Projection<ColumnDefTarget>()); theTemplates = MockRepository.GenerateMock<ITemplateWriter>(); }
public void WriteAnyTemplates(ITemplateWriter writer) { throw new NotImplementedException(); }
protected virtual int ExecuteImpl(ITemplateWriter @out, TemplateFrame frame) { Template self = frame.Template; int start = @out.Index; // track char we're about to Write Bytecode prevOpcode = Bytecode.Invalid; int n = 0; // how many char we Write out int nargs; int nameIndex; int addr; string name; object o, left, right; Template st; object[] options; byte[] code = self.impl.instrs; // which code block are we executing int ip = 0; while (ip < self.impl.codeSize) { if (trace || _debug) Trace(frame, ip); Bytecode opcode = (Bytecode)code[ip]; frame.InstructionPointer = ip; ip++; //jump to next instruction or first byte of operand switch (opcode) { case Bytecode.INSTR_LOAD_STR: int strIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; operands[++sp] = self.impl.strings[strIndex]; break; case Bytecode.INSTR_LOAD_ATTR: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = self.impl.strings[nameIndex]; try { o = GetAttribute(frame, name); if (o == Template.EmptyAttribute) o = null; } catch (AttributeNotFoundException) { _errorManager.RuntimeError(frame, ErrorType.NO_SUCH_ATTRIBUTE, name); o = null; } operands[++sp] = o; break; case Bytecode.INSTR_LOAD_LOCAL: int valueIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; o = self.locals[valueIndex]; if (o == Template.EmptyAttribute) o = null; operands[++sp] = o; break; case Bytecode.INSTR_LOAD_PROP: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; o = operands[sp--]; name = self.impl.strings[nameIndex]; operands[++sp] = GetObjectProperty(frame, o, name); break; case Bytecode.INSTR_LOAD_PROP_IND: object propName = operands[sp--]; o = operands[sp]; operands[sp] = GetObjectProperty(frame, o, propName); break; case Bytecode.INSTR_NEW: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = self.impl.strings[nameIndex]; nargs = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; // look up in original hierarchy not enclosing template (variable group) // see TestSubtemplates.testEvalSTFromAnotherGroup() st = self.Group.GetEmbeddedInstanceOf(frame, name); // get n args and store into st's attr list StoreArguments(frame, nargs, st); sp -= nargs; operands[++sp] = st; break; case Bytecode.INSTR_NEW_IND: nargs = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = (string)operands[sp - nargs]; st = self.Group.GetEmbeddedInstanceOf(frame, name); StoreArguments(frame, nargs, st); sp -= nargs; sp--; // pop template name operands[++sp] = st; break; case Bytecode.INSTR_NEW_BOX_ARGS: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = self.impl.strings[nameIndex]; IDictionary<string, object> attrs = (IDictionary<string, object>)operands[sp--]; // look up in original hierarchy not enclosing template (variable group) // see TestSubtemplates.testEvalSTFromAnotherGroup() st = self.Group.GetEmbeddedInstanceOf(frame, name); // get n args and store into st's attr list StoreArguments(frame, attrs, st); operands[++sp] = st; break; case Bytecode.INSTR_SUPER_NEW: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = self.impl.strings[nameIndex]; nargs = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; SuperNew(frame, name, nargs); break; case Bytecode.INSTR_SUPER_NEW_BOX_ARGS: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = self.impl.strings[nameIndex]; attrs = (IDictionary<string, object>)operands[sp--]; SuperNew(frame, name, attrs); break; case Bytecode.INSTR_STORE_OPTION: int optionIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; o = operands[sp--]; // value to store options = (object[])operands[sp]; // get options options[optionIndex] = o; // store value into options on stack break; case Bytecode.INSTR_STORE_ARG: nameIndex = GetShort(code, ip); name = self.impl.strings[nameIndex]; ip += Instruction.OperandSizeInBytes; o = operands[sp--]; attrs = (IDictionary<string, object>)operands[sp]; attrs[name] = o; // leave attrs on stack break; case Bytecode.INSTR_WRITE: o = operands[sp--]; int n1 = WriteObjectNoOptions(@out, frame, o); n += n1; nwline += n1; break; case Bytecode.INSTR_WRITE_OPT: options = (object[])operands[sp--]; // get options o = operands[sp--]; // get option to Write int n2 = WriteObjectWithOptions(@out, frame, o, options); n += n2; nwline += n2; break; case Bytecode.INSTR_MAP: st = (Template)operands[sp--]; // get prototype off stack o = operands[sp--]; // get object to map prototype across Map(frame, o, st); break; case Bytecode.INSTR_ROT_MAP: int nmaps = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; List<Template> templates = new List<Template>(); for (int i = nmaps - 1; i >= 0; i--) templates.Add((Template)operands[sp - i]); sp -= nmaps; o = operands[sp--]; if (o != null) RotateMap(frame, o, templates); break; case Bytecode.INSTR_ZIP_MAP: st = (Template)operands[sp--]; nmaps = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; List<object> exprs = new List<object>(); for (int i = nmaps - 1; i >= 0; i--) exprs.Add(operands[sp - i]); sp -= nmaps; operands[++sp] = ZipMap(frame, exprs, st); break; case Bytecode.INSTR_BR: ip = GetShort(code, ip); break; case Bytecode.INSTR_BRF: addr = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; o = operands[sp--]; // <if(expr)>...<endif> if (!TestAttributeTrue(o)) ip = addr; // jump break; case Bytecode.INSTR_OPTIONS: operands[++sp] = new object[Compiler.TemplateCompiler.NUM_OPTIONS]; break; case Bytecode.INSTR_ARGS: operands[++sp] = new Dictionary<string, object>(); break; case Bytecode.INSTR_PASSTHRU: nameIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; name = self.impl.strings[nameIndex]; attrs = (IDictionary<string, object>)operands[sp]; PassThrough(frame, name, attrs); break; case Bytecode.INSTR_LIST: operands[++sp] = new List<object>(); break; case Bytecode.INSTR_ADD: o = operands[sp--]; // pop value List<object> list = (List<object>)operands[sp]; // don't pop list AddToList(list, frame, o); break; case Bytecode.INSTR_TOSTR: // replace with string value; early eval operands[sp] = ToString(frame, operands[sp]); break; case Bytecode.INSTR_FIRST: operands[sp] = First(frame, operands[sp]); break; case Bytecode.INSTR_LAST: operands[sp] = Last(frame, operands[sp]); break; case Bytecode.INSTR_REST: operands[sp] = Rest(frame, operands[sp]); break; case Bytecode.INSTR_TRUNC: operands[sp] = Trunc(frame, operands[sp]); break; case Bytecode.INSTR_STRIP: operands[sp] = Strip(frame, operands[sp]); break; case Bytecode.INSTR_TRIM: o = operands[sp--]; if (o.GetType() == typeof(string)) { operands[++sp] = ((string)o).Trim(); } else { _errorManager.RuntimeError(frame, ErrorType.EXPECTING_STRING, "trim", o.GetType()); operands[++sp] = o; } break; case Bytecode.INSTR_LENGTH: operands[sp] = Length(operands[sp]); break; case Bytecode.INSTR_STRLEN: o = operands[sp--]; if (o.GetType() == typeof(string)) { operands[++sp] = ((string)o).Length; } else { _errorManager.RuntimeError(frame, ErrorType.EXPECTING_STRING, "strlen", o.GetType()); operands[++sp] = 0; } break; case Bytecode.INSTR_REVERSE: operands[sp] = Reverse(frame, operands[sp]); break; case Bytecode.INSTR_NOT: operands[sp] = !TestAttributeTrue(operands[sp]); break; case Bytecode.INSTR_OR: right = operands[sp--]; left = operands[sp--]; operands[++sp] = TestAttributeTrue(left) || TestAttributeTrue(right); break; case Bytecode.INSTR_AND: right = operands[sp--]; left = operands[sp--]; operands[++sp] = TestAttributeTrue(left) && TestAttributeTrue(right); break; case Bytecode.INSTR_INDENT: strIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; Indent(@out, frame, strIndex); break; case Bytecode.INSTR_DEDENT: @out.PopIndentation(); break; case Bytecode.INSTR_NEWLINE: try { if (prevOpcode == Bytecode.INSTR_NEWLINE || prevOpcode == Bytecode.INSTR_INDENT || nwline > 0) { @out.Write(Environment.NewLine); } nwline = 0; } catch (IOException ioe) { _errorManager.IOError(self, ErrorType.WRITE_IO_ERROR, ioe); } break; case Bytecode.INSTR_NOOP: break; case Bytecode.INSTR_POP: sp--; // throw away top of stack break; case Bytecode.INSTR_NULL: operands[++sp] = null; break; case Bytecode.INSTR_TRUE: operands[++sp] = true; break; case Bytecode.INSTR_FALSE: operands[++sp] = false; break; case Bytecode.INSTR_WRITE_STR: strIndex = GetShort(code, ip); ip += Instruction.OperandSizeInBytes; o = self.impl.strings[strIndex]; n1 = WriteObjectNoOptions(@out, frame, o); n += n1; nwline += n1; break; // TODO: generate this optimization //case Bytecode.INSTR_WRITE_LOCAL: // valueIndex = GetShort(code, ip); // ip += Instruction.OperandSizeInBytes; // o = self.locals[valueIndex]; // if (o == Template.EmptyAttribute) // o = null; // n1 = WriteObjectNoOptions(@out, frame, o); // n += n1; // nwline += n1; // break; default: _errorManager.InternalError(self, "invalid bytecode @ " + (ip - 1) + ": " + opcode, null); self.impl.Dump(); break; } prevOpcode = opcode; } if (_debug) { EvalTemplateEvent e = new EvalTemplateEvent(frame, Interval.FromBounds(start, @out.Index)); TrackDebugEvent(frame, e); } return n; }
/** Execute template self and return how many characters it wrote to out */ public virtual int Execute(ITemplateWriter @out, TemplateFrame frame) { try { if (frame.StackDepth > 200) throw new TemplateException("Template stack overflow.", null); if (trace) Console.Out.WriteLine("Execute({0})", frame.Template.Name); SetDefaultArguments(frame); return ExecuteImpl(@out, frame); } catch (Exception e) { if (e.IsCritical()) { e.PreserveStackTrace(); throw; } StringBuilder builder = new StringBuilder(); builder.AppendLine(e.ToString()); builder.AppendLine(e.StackTrace); _errorManager.RuntimeError(frame, ErrorType.INTERNAL_ERROR, "internal error: " + builder); return 0; } }
protected virtual int WritePlainObject(ITemplateWriter @out, TemplateFrame frame, object o, string[] options) { string formatString = null; if (options != null) formatString = options[(int)RenderOption.Format]; IAttributeRenderer r = frame.Template.impl.NativeGroup.GetAttributeRenderer(o.GetType()); string v; if (r != null) { v = r.ToString(o, formatString, culture); } else { if (o is bool) v = (bool)o ? "true" : "false"; else if (o is bool? && ((bool?)o).HasValue) v = ((bool?)o).Value ? "true" : "false"; else v = o.ToString(); } int n; if (options != null && options[(int)RenderOption.Wrap] != null) { n = @out.Write(v, options[(int)RenderOption.Wrap]); } else { n = @out.Write(v); } return n; }
/** Write out an expression result that uses expression options. * E.g., <names; separator=", "> */ protected virtual int WriteObjectWithOptions(ITemplateWriter @out, TemplateFrame frame, object o, object[] options) { int start = @out.Index; // track char we're about to Write // precompute all option values (Render all the way to strings) string[] optionStrings = null; if (options != null) { optionStrings = new string[options.Length]; for (int i = 0; i < Compiler.TemplateCompiler.NUM_OPTIONS; i++) { optionStrings[i] = ToString(frame, options[i]); } } if (options != null && options[(int)RenderOption.Anchor] != null) { @out.PushAnchorPoint(); } int n = WriteObject(@out, frame, o, optionStrings); if (options != null && options[(int)RenderOption.Anchor] != null) { @out.PopAnchorPoint(); } if (_debug) { Interval templateLocation = frame.Template.impl.sourceMap[frame.InstructionPointer]; EvalExprEvent e = new EvalExprEvent(frame, Interval.FromBounds(start, @out.Index), templateLocation); TrackDebugEvent(frame, e); } return n; }
/** Write out an expression result that doesn't use expression options. * E.g., <name> */ protected virtual int WriteObjectNoOptions(ITemplateWriter @out, TemplateFrame frame, object o) { int start = @out.Index; // track char we're about to Write int n = WriteObject(@out, frame, o, null); if (_debug) { Interval templateLocation = frame.Template.impl.sourceMap[frame.InstructionPointer]; EvalExprEvent e = new EvalExprEvent(frame, Interval.FromBounds(start, @out.Index), templateLocation); TrackDebugEvent(frame, e); } return n; }
public ExportCommand(IConsole console, ILogger <ExportCommand> logger, IProjectService projectService, ITemplateWriter templateWriter) : base(console, logger) { _projectService = projectService; _templateWriter = templateWriter; }
public virtual List<InterpEvent> GetEvents(ITemplateWriter writer) { return GetEvents(CultureInfo.CurrentCulture, writer); }
public virtual List<InterpEvent> GetEvents(CultureInfo culture, ITemplateWriter writer) { Interpreter interp = new Interpreter(groupThatCreatedThisInstance, culture); interp.Execute(writer, this); // Render and track events return interp.GetEvents(); }
public void SetUp() { theColumn = new ColumnDefinition <ColumnDefTarget, string>(x => x.Name, new Projection <ColumnDefTarget>()); theTemplates = MockRepository.GenerateMock <ITemplateWriter>(); }
public virtual List <InterpEvent> GetEvents(ITemplateWriter writer) { return(GetEvents(CultureInfo.CurrentCulture, writer)); }
protected void Indent(ITemplateWriter @out, TemplateFrame frame, int strIndex) { Template self = frame.Template; string indent = self.impl.strings[strIndex]; if (_debug) { int start = @out.Index; // track char we're about to write EvalExprEvent e = new IndentEvent(frame, new Interval(start, indent.Length), GetExpressionInterval(frame)); TrackDebugEvent(frame, e); } @out.PushIndentation(indent); }
public override int Write(ITemplateWriter @out) { return 0; }
protected virtual int WriteIterator(ITemplateWriter @out, TemplateFrame frame, object o, string[] options) { if (o == null) return 0; int n = 0; IEnumerator it = (IEnumerator)o; string separator = null; if (options != null) separator = options[(int)RenderOption.Separator]; bool seenAValue = false; while (it.MoveNext()) { object iterValue = it.Current; // Emit separator if we're beyond first value bool needSeparator = seenAValue && separator != null && // we have a separator and (iterValue != null || // either we have a value options[(int)RenderOption.Null] != null); // or no value but null option if (needSeparator) n += @out.WriteSeparator(separator); int nw = WriteObject(@out, frame, iterValue, options); if (nw > 0) seenAValue = true; n += nw; } return n; }
/** Generic method to emit text for an object. It differentiates * between templates, iterable objects, and plain old Java objects (POJOs) */ protected virtual int WriteObject(ITemplateWriter @out, TemplateFrame frame, object o, string[] options) { int n = 0; if (o == null) { if (options != null && options[(int)RenderOption.Null] != null) o = options[(int)RenderOption.Null]; else return 0; } ITypeProxyFactory proxyFactory = frame.Template.Group.GetTypeProxyFactory(o.GetType()); if (proxyFactory != null) o = proxyFactory.CreateProxy(frame, o); System.Diagnostics.Debug.Assert(!(o is TemplateFrame)); Template template = o as Template; if (template != null) { frame = new TemplateFrame(template, frame); if (options != null && options[(int)RenderOption.Wrap] != null) { // if we have a wrap string, then inform writer it // might need to wrap try { @out.WriteWrap(options[(int)RenderOption.Wrap]); } catch (IOException ioe) { _errorManager.IOError(template, ErrorType.WRITE_IO_ERROR, ioe); } } n = Execute(@out, frame); } else { o = ConvertAnythingIteratableToIterator(frame, o); // normalize try { if (o is IEnumerator) n = WriteIterator(@out, frame, o, options); else n = WritePlainObject(@out, frame, o, options); } catch (IOException ioe) { _errorManager.IOError(frame.Template, ErrorType.WRITE_IO_ERROR, ioe, o); } } return n; }
public virtual int Write(ITemplateWriter @out, CultureInfo culture) { Interpreter interp = new Interpreter(groupThatCreatedThisInstance, culture); interp.SetDefaultArguments(this); return interp.Exec(@out, this); }