public void Generator_WithMultipleTemplate_AppliesAllTemplates() { fs.InputFiles = new Dictionary <string, string>() { { "_template_.html", "t1 {{body}} t1" }, { "index.md", "I'm the *root* index file" }, { "blog/_template_.html", "{% capture body %}t2 {{ body }} t2{% endcapture %}" }, { "blog/index.md", "{% capture body %}my posts:\r\n{% for item in post %}\r\n- {{ item.title }}{% endfor %}\r\n{% endcapture %}" }, { "blog/_template_post.html", "{% capture body %}t3 {{ body }} t3{% endcapture %}" }, { "blog/_post_first.md", "{% assign title = 'Title 1' %}{% capture body %}\r\n content one \r\n{% endcapture %}" }, { "blog/_post_second.md", "{% assign nessie-url-prefix = 'foo/bar' %}{% assign title = 'Title 2' %}{% capture body %} content two {% endcapture %}" }, }; generator.Generate(FakeFileSystem.Root, "_output", fs.InputFiles.Select(kvp => kvp.Key).ToList()); AssertHelper.AreEqualIgnoringNewLines("<p>I’m the <em>root</em> index file</p>\r\n", fs.OutputFiles["_output/index.html"]); AssertHelper.AreEqualIgnoringNewLines("t1 t2<p>my posts:</p>\r\n<ul>\r\n<li>Title 1</li>\r\n<li>Title 2</li>\r\n</ul><p>t2 t1</p>", fs.OutputFiles["_output/blog/index.html"]); AssertHelper.AreEqualIgnoringNewLines("t1 t2 t3<p>content one</p><p>t3 t2 t1</p>", fs.OutputFiles["_output/blog/first.html"]); AssertHelper.AreEqualIgnoringNewLines("<p>t1 t2 t3 content two t3 t2 t1</p>", fs.OutputFiles["_output/foo/bar/second.html"]); Assert.AreEqual(4, fs.OutputFiles.Count); }
private void CreateNewHoloJsApp(AppCreationOptions opts) { if (System.IO.Directory.Exists(opts.Path) && !opts.Overwrite) { Console.WriteLine("The directory already exists. Use --overwrite to force creating a new app in it."); return; } var generator = new ProjectGenerator(opts.Path); generator.Generate(); RunVsCode(System.IO.Path.GetFullPath(opts.Path)); }
private void Build(string projectDirectory) { var files = Directory .GetFiles(projectDirectory, "*", SearchOption.AllDirectories) .Where(IsValidInputFile) .ToList(); projectGenerator.Generate( projectDirectory, Path.Combine(projectDirectory, ProjectLocator.OutputDirectory), files); string time = DateTime.Now.ToString("T"); Console.WriteLine($"{time}: Built site"); OnBuilt?.Invoke(this, EventArgs.Empty); }
static void Main(string[] args) { // Get the arguments GenerationTarget serverTarget = null; List <GenerationTarget> clientTargets = new List <GenerationTarget>(); string srcFile = null; foreach (string arg in args) { if (arg.Contains("-server=")) { string servTargetStr = arg.Split('=')[1]; string[] parts = servTargetStr.Split(':'); string tag = parts[0]; string outputFile = parts[1]; serverTarget = new GenerationTarget(tag, outputFile); } else if (arg.Contains("-clients=")) { string[] clientTargetStrs = arg.Split('=')[1].Split('|'); foreach (string clientTargetStr in clientTargetStrs) { string[] parts = clientTargetStr.Split(':'); string tag = parts[0]; string outputFile = parts[1]; clientTargets.Add(new GenerationTarget(tag, outputFile)); } } else if (arg.Contains("-src=")) { srcFile = arg.Split('=')[1]; } else { PrintUsage(); throw new ArgumentException("Argument '" + arg + "' invalide."); } } // Arguments vides. if (serverTarget == null || clientTargets.Count == 0 || srcFile == null) { PrintUsage(); throw new ArgumentException("Nombre d'arguments invalide."); } // Fichier inexistant. if (!System.IO.File.Exists(srcFile)) { throw new System.IO.FileNotFoundException("Le fichier " + srcFile + " est introuvable."); } // Génère le projet et redirige la sortie vers la console. ProjectGenerator generator = new ProjectGenerator(); int errorCount = 0; int warningCount = 0; Clank.Core.Tools.EventLog.EventLogHandler handler = new Core.Tools.EventLog.EventLogHandler((Core.Tools.EventLog.Entry e) => { Console.WriteLine(e.Type.ToString() + " (" + e.Source + "). Line " + e.Line + "-" + e.Character + ": " + e.Message + "\r\n\r\n"); if (e.Type == Core.Tools.EventLog.EntryType.Error) { errorCount++; } else if (e.Type == Core.Tools.EventLog.EntryType.Warning) { warningCount++; } }); generator.Generate("#include " + srcFile.Trim('"'), serverTarget, clientTargets, handler); Console.WriteLine("=================================="); Console.WriteLine("== Compilation " + (errorCount > 0 ? "échouée." : "réussie") + "."); Console.WriteLine("== " + errorCount + " erreurs, " + warningCount + " warnings."); Console.WriteLine("Appuyez sur une touche pour terminer l'exécution du programme."); Console.Read(); }
static void Main(string[] args) { #region New string s1 = @" public class Array<T> { string Name() { string CS = 'List'; string Python = 'List'; string Java = 'Haha'; } string Item(int id) { string CS = '[$id]'; string Python = '[$id]'; } } ".Replace("'", "\""); string s2 = @" main { state { public class Patate<T> { public string Name() { string CS = 'List'; string Python = 'List'; int haha = '6556'; } string PATATE(int id) { string CS = '[$id]'; string Python = '[$id]'; } } } state { public class Hello { } } } ".Replace("'", "\""); string script = @" #include outside main { macro { #include myScript public class List<T> { string Name() { string Python = 'List'; string CS = 'List'; } public T get(int index) { string Python = '[$index]'; string CS = '[$index$]'; } } public class Vector2 { string Name() { string CS = 'Vector2'; string Python = 'vec2'; } # Obtient la position du vecteur. int GetX() { string CS = 'X'; string Python = 'x'; } int GetY() { string CS = 'Y'; string Python = 'y'; } # Définit la position du vecteur. int SetX(int x) { string CS = 'X = $x$'; string Python = 'x = $x$'; } int SetY(int y) { string CS = 'Y = $y$'; string Python = 'y = $y$'; } } } state { public class Ship<T> { public int Speed; public string Name; public T Position; public constructor Ship<T> New(T pos) { Speed = 5; Name = 'Spitfire'; Position = pos; } public static Ship<T> Create() { Ship<T> bllb; } public void Nothing() { } } List<Ship<Vector2>> Ships; } access { public Ship<Vector2> GetShip(int index) { int blbl = clientId; return state.Ships.get(index); } void FunctionWithErrors(int shit) { string blblb = 56; int carotte = 'hihi'; return 5; return 6; int[] things; Ship<Vector2> shippp = Ship<Vector2>.Create(); void voide = shippp.Nothing(); shippp = GetShip(1); int haha; if(haha + 5) { int jeSuisUnInt = 5; } elsif(haha + 5) { int jeSuisUnInt = 5; } Ship<Vector2> shiiip = Ship<Vector2>.New(Vector2.New()); while(haha + 5) { int jeSuisdeUnInt = 5; } #carotte.JeFaisPlanter(); } public Vector2 GetShipPosition(int index) { return state.Ships.get(index).Position; } } write { public bool SetShipPosition(int index, Vector2 position) { state.Ships.get(index).Position = position; return true; } public bool MoveShip(int index, Vector2 dir) { Ship<Vector2> ship = state.Ships.get(index); ship.Position.SetX(ship.Position.GetX() + dir.GetX()); ship.Position.SetY(ship.Position.GetX() + dir.GetX()); return true; } } } ".Replace("'", "\""); #endregion string generationLog; GenerationTarget serverTarget = new GenerationTarget("cs", "Serveur.cs"); List <GenerationTarget> clientTargets = new List <GenerationTarget>() { new GenerationTarget("cs", "Client.cs"), new GenerationTarget("Python", "Client.py") }; ProjectGenerator generator = new ProjectGenerator(); // System.IO.File.ReadAllText("samplescript.clank") List <OutputFile> files2 = generator.Generate("#include samplescript.clank", serverTarget, clientTargets, out generationLog); // Loader Generation.Preprocessor.MemoryIncludeLoader loader = new Generation.Preprocessor.MemoryIncludeLoader(); loader.AddFile("myScript", s1); loader.AddFile("outside", s2); loader.AddFile("main", script); generator.Preprocessor.ScriptIncludeLoader = loader; List <OutputFile> files = generator.Generate(script, serverTarget, clientTargets, out generationLog); // TODO : // - documenter changements récents. ---> TODO // - Surcharge des fonctions. OK // - Modificateurs macros : jsontype = array ! OK // - implémenter java OK // - implémenter cpp : headers / implémentation. OK // - implémenter python // - checks : si serializable : // - vérifier que toutes les variables le sont ok // - serializable + pas public = warning ok // - write/access : arguments de type public et serializable. // Remplir la todo-list ! // TODO 2 : le retour de la vengeance : // - Documenter macro fonctions // - Enums !!! // - Gérer les paramètres de métadonnées pour les classes (ex : C# namespace, java / python / cpp includes). }