예제 #1
0
 public void Write(GenericTypeTemplate template, IOutputCache output)
 {
     output.Add(template.Name)
     .Add("<")
     .Add(template.Types, ", ")
     .Add(">");
 }
예제 #2
0
        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();
        }
예제 #3
0
        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();
                }
            }
        }
예제 #4
0
        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}.");
            }
        }
예제 #5
0
        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();
            }
        }
예제 #6
0
        public void Write(ICodeFragment fragment, IOutputCache output)
        {
            MethodGenericTemplate template = (MethodGenericTemplate)fragment;

            output.Add(template.Alias)
            .If(template.DefaultType != null).Add(" = ").Add(template.DefaultType).EndIf();
        }
예제 #7
0
        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();
            }
        }
예제 #8
0
        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();
            }
        }
예제 #9
0
 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);
        }
예제 #11
0
        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);
            }
        }
예제 #12
0
        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();
            }
        }
예제 #13
0
        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();
        }
예제 #14
0
        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);
        }
예제 #16
0
        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);
            }
        }
예제 #17
0
 public OutputCachingBehavior(IOutputCache cache, IOutputWriter writer, IResourceHash hash, IHeadersCache headersCache, ILogger logger)
 {
     _cache        = cache;
     _writer       = writer;
     _hash         = hash;
     _headersCache = headersCache;
     _logger       = logger;
 }
예제 #18
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            TypeOfTemplate template = (TypeOfTemplate)fragment;

            output.Add("typeof(")
            .Add(template.Type)
            .Add(")");
        }
예제 #19
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            CastTemplate template = (CastTemplate)fragment;

            output.Add("(")
            .Add(template.Type)
            .Add(")");
        }
예제 #20
0
 public OutputCachingBehavior(IOutputCache cache, IOutputWriter writer,
     IResourceHash hash, IHeadersCache headersCache)
 {
     _cache = cache;
     _writer = writer;
     _hash = hash;
     _headersCache = headersCache;
 }
예제 #21
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            NullCoalescingOperatorTemplate template = (NullCoalescingOperatorTemplate)fragment;

            output.Add(template.LeftCode)
            .Add(" ?? ")
            .Add(template.RightCode);
        }
예제 #22
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            ParenthesisTemplate template = (ParenthesisTemplate)fragment;

            output.Add("(")
            .Add(template.Code)
            .Add(")");
        }
예제 #23
0
 protected virtual void WriteHeader(FileTemplate fileTemplate, IOutputCache output, bool appendBlankLine = true)
 {
     if (fileTemplate.Header?.Description != null)
     {
         output.Add(fileTemplate.Header)
         .If(appendBlankLine).BreakLine().EndIf();
     }
 }
예제 #24
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            ReturnTemplate template = (ReturnTemplate)fragment;

            output.Add("return ")
            .Add(template.Code)
            .CloseLine();
        }
예제 #25
0
 protected virtual void WriteHeader(FileTemplate fileTemplate, IOutputCache output)
 {
     if (fileTemplate.Header?.Description != null)
     {
         this.Write(fileTemplate.Header, output);
         output.BreakLine();
     }
 }
예제 #26
0
        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);
        }
예제 #27
0
        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));
        }
예제 #28
0
        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);
        }
예제 #30
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            MultilineCodeFragment template = (MultilineCodeFragment)fragment;

            foreach (ICodeFragment codeFragment in template.Fragments)
            {
                output.Add(codeFragment);
            }
        }
예제 #31
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            ExecuteMethodTemplate template = (ExecuteMethodTemplate)fragment;

            output.Add(template.Name)
            .Add("(")
            .Add(template.Parameters, ", ")
            .Add(")");
        }
예제 #32
0
        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;
 }