Ejemplo n.º 1
0
        private static string BuildPrefix(TypeScriptWriter writer, string name, string[] extends, string[] implements, string[] decorators)
        {
            if (decorators != null && decorators.Any())
            {
                foreach (var decorator in decorators)
                {
                    writer.WriteLine($"@{decorator}");
                    writer.WriteIndent();
                }
            }

            writer.Write($"class {name}");

            if (extends != null && extends.Length > 0)
            {
                writer.Write($" extends {string.Join(", ", extends)}");
            }

            if (implements != null && implements.Length > 0)
            {
                writer.Write($" implements {string.Join(", ", implements)}");
            }

            writer.Write(" ");

            return(null);
        }
Ejemplo n.º 2
0
        private static string BuildPrefix(TypeScriptWriter writer, string name, string[] extends)
        {
            writer.Write($"interface {name}");

            if (extends != null && extends.Length > 0)
            {
                writer.Write($" extends {string.Join(", ", extends)}");
            }

            writer.Write(" ");

            return(null);
        }
Ejemplo n.º 3
0
        public TypeScriptBlock(TypeScriptWriter writer, string prefix = null, string suffix = null)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            Writer  = writer;
            _suffix = suffix;

            if (prefix != null)
            {
                Writer.WriteIndented($"{prefix} {{");
            }
            else
            {
                Writer.WriteIndented("{");
            }
            Writer.Indent(1);
        }
Ejemplo n.º 4
0
        public void Save(string rootFolder)
        {
            if (!Directory.Exists(rootFolder))
            {
                Directory.CreateDirectory(rootFolder);
            }

            foreach (var module in _modules.Values.Where(t => (t.Flags & (TypeScriptModuleFlags.BuiltIn | TypeScriptModuleFlags.External)) == 0))
            {
                var fullPath = Path.Combine(rootFolder, module.Path + ".ts");

                var template = _templateResolver.GetTemplate(module);

                using (var writer = new TypeScriptWriter(this))
                {
                    template.Write(writer, module);

                    using (var output = new StreamWriter(File.Create(fullPath)))
                        writer.Save(output);
                }
            }
        }
Ejemplo n.º 5
0
 public TypeScriptInterfaceBlock(TypeScriptWriter writer, string name, string[] extends)
     : base(writer, prefix: BuildPrefix(writer, name, extends))
 {
 }
Ejemplo n.º 6
0
 public TypeScriptClassBlock(TypeScriptWriter writer, string name, string[] extends, string[] implements, string[] decorators)
     : base(writer, prefix: BuildPrefix(writer, name, extends, implements, decorators))
 {
 }