public override void Build(Transpilation context)
        {
            if (Assembly == null)
            {
                throw new InvalidDataException("Please specify an assembly.");
            }

            var name = string.Join(".", Assembly.GetName().Name
                                   .TrimEnd()
                                   .Split('.')
                                   .Select(s => s.CamelCase()))
                       + ".decorators.ts";

            File = new TypescriptFile {
                Path = Path.Combine(context.Path, name)
            };
            File.Elements.Add(new Comment("This file is generated from Audacia.Typescript.Transpiler. Any changes will be overwritten. \n"));

            foreach (var type in Types)
            {
                var attributeUsage = type.GetCustomAttribute <AttributeUsageAttribute>();

                if (attributeUsage == null || attributeUsage.ValidOn.HasFlag(AttributeTargets.Class) || attributeUsage.ValidOn.HasFlag(AttributeTargets.Enum))
                {
                    File.Elements.Add(new ClassDecoratorFunction(type.ClassDecoratorName(), type.Name));
                }

                if (attributeUsage == null || attributeUsage.ValidOn.HasFlag(AttributeTargets.Property))
                {
                    File.Elements.Add(new PropertyDecoratorFunction(type.PropertyDecoratorName(), type.Name));
                }
            }
        }
Example #2
0
 public IEnumerable <TypescriptConstruct> Traverse(TypescriptFile file)
 {
     return(file.RootConstruct.Flatten().Where(c => c.ExportToken != null).Where(c => c.ExportToken.Equals(_token)));
 }
Example #3
0
        public IEnumerable <HtmlDocument> Traverse(TypescriptFile file)
        {
            var components = file.RootConstruct.Flatten().Where(c => c is TypescriptDecorator && c.Name.Equals("Component"));

            return(components.OfType <TypescriptDecorator>().Select(this.ExtractHtmlDocument));
        }
Example #4
0
 public IEnumerable <ComponentOptions> Traverse(TypescriptFile file)
 {
     return(file.RootConstruct.Flatten()
            .Where(c => c is TypescriptDecorator && c.Name.Equals("Component"))
            .OfType <TypescriptDecorator>().Select(d => d.Options as ComponentOptions));
 }
Example #5
0
        public void Returns_a_correctly_formed_file()
        {
            var expected = System.IO.File.ReadAllText("typescriptFile.ts");
            var file     = new TypescriptFile
            {
                new Interface("IStudent")
                {
                    Comment = "Interface",
                    Members =
                    {
                        new Property("yearOfBirth",  "number"),
                        new Property("age",          "number"),
                        new Function("printDetails", "void")
                    }
                },
                new Class("School")
                {
                    Comment = "Base class",
                    Members =
                    {
                        new Constructor
                        {
                            { "name",       "string" },
                            { "city",       "string" }
                        },

                        new Property("name", "string"),
                        new Property("city", "string"),
                        new Function("address")
                        {
                            Modifiers  = { Modifier.Public },
                            Arguments  = { { "streetName", "string" } },
                            Statements =
                            {
                                "return ('College Name:' + this.name + ' City: ' + this.city + ' Street Name: ' + streetName);"
                            }
                        }
                    }
                },
                new Class("Student")
                {
                    Comment    = "Child Class implements IStudent and inherits from College",
                    Extends    = "School",
                    Implements = { "IStudent", "IArguments" },
                    Members    =
                    {
                        { "length",                 "number"     },
                        { "callee",                 "Function"   },
                        { "firstName",              "string"     },
                        { "lastName",               "string"     },
                        { "yearOfBirth",            "number"     },
                        new Constructor
                        {
                            Comment   = "Constructor",
                            Arguments =
                            {
                                { "firstName",   "string"                       },
                                { "lastName",    "string"                       },
                                { "name",        "string"                       },
                                { "city",        "string"                       },
                                { "yearOfBirth", "number"                       }
                            },
                            Statements =
                            {
                                "super(name, city);",
                                "this.firstName = firstName;",
                                "this.lastName = lastName;",
                                "this.yearOfBirth = yearOfBirth;"
                            }
                        },
                        new Property("age", "number")
                        {
                            Get = new Getter
                            {
                                "return 2014 - this.yearOfBirth;"
                            },
                            Set = new Setter("value")
                            {
                                "// Do a thing",
                                "var self = this;",
                                new Function("nested")
                                {
                                    new Interface("IAlsoNested")
                                    {
                                        Extends ={ "IStudent",               "IArguments" },
                                        Members ={ new Property("faveColor", "string")    }
                                    },

                                    "return self.firstName;"
                                },

                                "nested();"
                            }
                        },
                        new Function("collegeDetails")
                        {
                            "var y = super.address('Maple Street');",
                            "alert(y);"
                        },
                        new Function("printDetails", "void")
                        {
                            "alert(this.firstName + ' ' + this.lastName + ' College is: ' + this.name);"
                        }
                    }
                }
            };

            file.ToString().Should().BeEquivalentTo(expected);
        }