public void Write(GenericTypeTemplate template, IOutputCache output) { output.Add(template.Name) .Add("<") .Add(template.Types, ", ") .Add(">"); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { UsingTemplate template = (UsingTemplate)fragment; if (template is UnknownExportTemplate unknownUsing) { output.Add(unknownUsing.Code).BreakLine(); return; } if (template.Path == null || template.Type == null) { Logger.Error("Invalid TypeScript import/export (path or type is missing)"); return; } string action = template is ExportTemplate ? "export" : "import"; string typeName = template.Type; if (!typeName.StartsWith("*")) { typeName = $"{{ {typeName} }}"; } output.Add($"{action} {typeName} from ") .Add(this.options.Formatting.Quote) .Add(template.Path.TrimEnd(".ts")) .Add(this.options.Formatting.Quote) .CloseLine(); }
private void WriteChained(ChainedCodeFragment fragment, IOutputCache output) { this.progressedChainedCodeFragments.Add(fragment.First()); bool isFirst = true; foreach (ChainedCodeFragment codeFragment in fragment.First().Yield().Cast <ChainedCodeFragment>()) { if (!isFirst) { output.Add(codeFragment.Separator); } isFirst = false; this.Write(codeFragment, output); //output.Add(codeFragment, this); if (codeFragment.NewLineAfter) { output.BreakLine(); } if (codeFragment.CloseAfter) { output.CloseLine(); } if (codeFragment.BreakAfter) { output.BreakLine().ExtraIndent(); } } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { if (fragment == null) { return; } this.lastFragments.Insert(0, fragment); while (this.lastFragments.Count > 10) { this.lastFragments.RemoveAt(this.lastFragments.Count - 1); } if (fragment is ChainedCodeFragment chainedCodeFragment && !this.IsProcessed(chainedCodeFragment)) { this.WriteChained(chainedCodeFragment, output); return; } Type key = fragment.GetType(); if (this.TemplateWriters.ContainsKey(key)) { this.TemplateWriters[key].Write(fragment, output); } else { throw new NotImplementedException($"The method {nameof(Write)} for type {key.Name} is not implemented in {this.Name}."); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { TypeScriptTemplate template = (TypeScriptTemplate)fragment; output.Add(template.Code); if (template.CloseAfter) { output.CloseLine(); } if (template.BreakAfter) { output.BreakLine(); } if (template.StartBlockAfter) { output.StartBlock(); } if (template.EndBlockAfter) { output.EndBlock(); } if (template.IndentAfter) { output.Indent(); } if (template.UnindentAfter) { output.UnIndent(); } }
public void Write(ICodeFragment fragment, IOutputCache output) { MethodGenericTemplate template = (MethodGenericTemplate)fragment; output.Add(template.Alias) .If(template.DefaultType != null).Add(" = ").Add(template.DefaultType).EndIf(); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { AttributeTemplate template = (AttributeTemplate)fragment; output.Add("[") .Add(template.Name); if (template.HasValue || template.Properties.Count > 0) { output.Add("("); if (template.HasValue) { output.Add(template.Code); } if (template.Properties.Count > 0) { foreach (KeyValuePair <string, object> pair in template.Properties) { output.Add($"{pair.Key} = {this.Language.ConvertValue(pair.Value)}"); } } output.Add(")"); } output.Add("]"); if (template.IsInline) { output.Add(" "); } else { output.BreakLine(); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { PropertyTemplate template = (PropertyTemplate)fragment; FieldTemplate fieldTemplate = new FieldTemplate(template.Class, template.Name, template.Type).FormatName(output.Language, true); if (fieldTemplate.Name == template.Name) { fieldTemplate.Name += "Field"; } fieldTemplate.DefaultValue = template.DefaultValue; output.Add(fieldTemplate); if (template.HasGetter) { output.If(template.Visibility != Visibility.None).Add(template.Visibility.ToString().ToLower()).Add(" ").EndIf() .If(template.IsStatic).Add("static ").EndIf() .Add($"get {template.Name}(): ") .Add(template.Type) .StartBlock() .Add(Code.Return(Code.This().Field(fieldTemplate.Name))) .EndBlock(); } if (template.HasSetter) { output.If(template.Visibility != Visibility.None).Add(template.Visibility.ToString().ToLower()).Add(" ").EndIf() .If(template.IsStatic).Add("static ").EndIf() .Add($"set {template.Name}(value: ") .Add(template.Type) .Add(")") .StartBlock() .Add(Code.This().Field(fieldTemplate.Name).Assign(Code.Local("value")).Close()) .EndBlock(); } }
public void Initialize() { this.resolver = new DependencyResolver(); this.options = new OptionsSet(null, null); this.options.Language = new TypeScriptLanguage(this.resolver); this.output = new FileWriter(this.options); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { NullCoalescingTemplate template = (NullCoalescingTemplate)fragment; output.Add(" ?? ") .Add(template.Code); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { FileTemplate template = (FileTemplate)fragment; if (string.IsNullOrEmpty(template.Name)) { Logger.Trace("Empty file skipped"); return; } if (template.Header.Description != null) { AssemblyName assemblyName = (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName(); template.Header.Description = string.Format(template.Header.Description, $"{assemblyName.Name} {assemblyName.Version}"); } template.FullPath = FileSystem.Combine(template.RelativePath, template.Name); this.WriteHeader(template, output); if (template is StaticFileTemplate staticFile) { output.Add(staticFile.Content, true); } else { this.WriteUsings(template, output); output.Add(template.Namespaces); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { CommentTemplate comment = (CommentTemplate)fragment; if (comment.IsEmpty()) { return; } foreach (string line in this.SplitLines(comment.Description)) { if (line.TrimStart().StartsWith("/*")) { if (line.EndsWith("*/")) { output.Add(line); } else { output.Add(line.Replace("*/", "*/ //")); } } else { output.Add($"// {line}".Trim()); } output.BreakLine(); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { BaseLanguage language = this.options.Language.CastTo <BaseLanguage>(); EnumTemplate template = (EnumTemplate)fragment; output.Add(template.Attributes) .Add(language.ClassScope) .Add(" enum ") .Add(template.Name); if (template.BasedOn != null) { output.Add(" : ").Add(template.BasedOn); } output.StartBlock(); EnumValueTemplate last = template.Values.LastOrDefault(); foreach (EnumValueTemplate enumTemplateValue in template.Values) { output.Add($"{enumTemplateValue.FormattedName} = ") .Add(enumTemplateValue.Value) .Add(last == enumTemplateValue ? string.Empty : ",") .BreakLine(); } output.EndBlock(); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { MethodTemplate template = (MethodTemplate)fragment; if (template.Generics != null && template.Generics.Any(x => x.DefaultType != null)) { throw new InvalidOperationException($"This language does not support default types for generic methods. {template.Class.Name}.{template.Name}"); } output.Add(template.Comment) .Add(template.Attributes) .Add(template.Visibility.ToString().ToLower()).Add(" ") .If(template.IsStatic).Add("static ").EndIf() .If(template.IsOverride).Add("override ").EndIf() .If(template.Type != null).Add(template.Type).Add(" ").EndIf() .Add(template.Name) .If(template.Generics != null && template.Generics.Count > 0).Add("<").Add(template.Generics, ", ").Add(">").EndIf() .Add("(") .If(template is ExtensionMethodTemplate).Add("this ").EndIf() .Add(template.Parameters.OrderBy(x => x.DefaultValue == null ? 0 : 1), ", ") .Add(")"); this.BeforeBlock(fragment, output); output.StartBlock() .Add(template.Code) .EndBlock(); }
public void Write(ICodeFragment fragment, IOutputCache output) { UsingDeclarationTemplate template = (UsingDeclarationTemplate)fragment; output.Add("using ") .Add(template.Code); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { LambdaTemplate template = (LambdaTemplate)fragment; output.Add("("); if (template.Parameters != null) { output.Add(template.Parameters, ", "); } else if (template.ParameterNames?.Count == 1) { output.Add(template.ParameterNames[0]); } else if (template.ParameterNames?.Count > 1) { output.Add(string.Join(", ", template.ParameterNames)); } output.Add(")") .Add(" =>"); if (template.Code is MultilineCodeFragment) { output.StartBlock(); } else { output.Add(" "); } output.Add(template.Code); if (template.Code is MultilineCodeFragment) { output.EndBlock(this.options.Formatting.StartBlockInNewLine); } }
public OutputCachingBehavior(IOutputCache cache, IOutputWriter writer, IResourceHash hash, IHeadersCache headersCache, ILogger logger) { _cache = cache; _writer = writer; _hash = hash; _headersCache = headersCache; _logger = logger; }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { TypeOfTemplate template = (TypeOfTemplate)fragment; output.Add("typeof(") .Add(template.Type) .Add(")"); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { CastTemplate template = (CastTemplate)fragment; output.Add("(") .Add(template.Type) .Add(")"); }
public OutputCachingBehavior(IOutputCache cache, IOutputWriter writer, IResourceHash hash, IHeadersCache headersCache) { _cache = cache; _writer = writer; _hash = hash; _headersCache = headersCache; }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { NullCoalescingOperatorTemplate template = (NullCoalescingOperatorTemplate)fragment; output.Add(template.LeftCode) .Add(" ?? ") .Add(template.RightCode); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { ParenthesisTemplate template = (ParenthesisTemplate)fragment; output.Add("(") .Add(template.Code) .Add(")"); }
protected virtual void WriteHeader(FileTemplate fileTemplate, IOutputCache output, bool appendBlankLine = true) { if (fileTemplate.Header?.Description != null) { output.Add(fileTemplate.Header) .If(appendBlankLine).BreakLine().EndIf(); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { ReturnTemplate template = (ReturnTemplate)fragment; output.Add("return ") .Add(template.Code) .CloseLine(); }
protected virtual void WriteHeader(FileTemplate fileTemplate, IOutputCache output) { if (fileTemplate.Header?.Description != null) { this.Write(fileTemplate.Header, output); output.BreakLine(); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { StringTemplate template = (StringTemplate)fragment; output.Add(this.options.Formatting.Quote) .Add(template.Value) .Add(this.options.Formatting.Quote); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { NumberTemplate template = (NumberTemplate)fragment; output.Add(template.LongValue?.ToString(CultureInfo.InvariantCulture) ?? template.DoubleValue?.ToString(CultureInfo.InvariantCulture) ?? template.FloatValue?.ToString(CultureInfo.InvariantCulture)); }
public void Write(ICodeFragment fragment, IOutputCache output) { YieldReturnTemplate template = (YieldReturnTemplate)fragment; output.Add("yield return ") .Add(template.Code) .CloseLine(); }
public override void Write(ICodeFragment fragment, IOutputCache output) { VerbatimStringTemplate template = (VerbatimStringTemplate)fragment; output.Add("@") .Add(this.options.Formatting.Quote) .Add(template.Value, true) .Add(this.options.Formatting.Quote); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { MultilineCodeFragment template = (MultilineCodeFragment)fragment; foreach (ICodeFragment codeFragment in template.Fragments) { output.Add(codeFragment); } }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { ExecuteMethodTemplate template = (ExecuteMethodTemplate)fragment; output.Add(template.Name) .Add("(") .Add(template.Parameters, ", ") .Add(")"); }
public OutputCachingBehavior(IActionBehavior inner, IOutputCache cache, IOutputWriter writer, ICurrentChain currentChain, IEtagCache etagCache) { _inner = inner; _cache = cache; _writer = writer; _currentChain = currentChain; _etagCache = etagCache; Invoker = x => x.Invoke(); PartialInvoker = x => x.InvokePartial(); }
public void SetUp() { file1 = new AssetFile("1"); file2 = new AssetFile("2"); file3 = new AssetFile("3"); file4 = new AssetFile("4"); file5 = new AssetFile("5"); file6 = new AssetFile("6"); theOutputCache = MockRepository.GenerateMock<IOutputCache>(); headersCache = MockRepository.GenerateMock<IHeadersCache>(); theCache = new AssetContentCache(headersCache, theOutputCache); theGraph = BehaviorGraph.BuildFrom(new FubuRegistry()); }
public AssetContentCache(IHeadersCache headers, IOutputCache outputCache) { _headers = headers; _outputCache = outputCache; }