예제 #1
0
    public static void ExecuteAllRecipesAndGenerateWebsite(string cookbookProjectFolder)
    {
        Console.WriteLine("Deleting old cookbook files...");
        string outputFolder = Path.Combine(cookbookProjectFolder, "CookbookOutput");

        if (Directory.Exists(outputFolder))
        {
            Directory.Delete(outputFolder, recursive: true);
        }
        Directory.CreateDirectory(outputFolder);

        string jsonFilePath    = Path.Combine(outputFolder, "recipes.json");
        string imageFolderPath = Path.Combine(outputFolder, "images");

        Directory.CreateDirectory(imageFolderPath);

        Console.WriteLine($"Generating Images...");
        RecipeImages.Generate(imageFolderPath);

        Console.WriteLine($"Generating JSON...");
        string json = RecipeJson.Generate(cookbookProjectFolder);

        File.WriteAllText(jsonFilePath, json);

        Console.WriteLine($"Reading JSON...");
        RecipeSource[] recipes = RecipeJson.GetRecipes(jsonFilePath).Values.Select(x => x).ToArray();

        Console.WriteLine($"Generating website...");
        Website.Generate(outputFolder, recipes);

        Console.WriteLine($"SAVED IN: {outputFolder}");
    }
예제 #2
0
        public void Test_Json_IsValid()
        {
            string jsonFilePath = Path.GetFullPath("cookbook-valid-test.json");

            IRecipe[] recipes = Locate.GetRecipes();

            string json = RecipeJson.Generate(COOKBOOK_PROJECT_FOLDER);

            File.WriteAllText(jsonFilePath, json);

            Dictionary <string, RecipeSource> readRecipes = RecipeJson.GetRecipes(new FileInfo(jsonFilePath));

            Console.WriteLine($"Read {readRecipes.Count} recipes from JSON");

            Assert.AreEqual(recipes.Length, readRecipes.Count);
        }
예제 #3
0
    public static RecipeSource[] Generate(string cookbookProjectFolder, string outputFolder, bool regenerate = false)
    {
        string jsonFilePath    = Path.Combine(outputFolder, "recipes.json");
        string imageFolderPath = Path.Combine(outputFolder, "images");

        if (regenerate)
        {
            if (Directory.Exists(imageFolderPath))
            {
                Directory.Delete(imageFolderPath, recursive: true);
            }
            Directory.CreateDirectory(imageFolderPath);

            Console.WriteLine($"Generating Images: {imageFolderPath}");
            RecipeImages.Generate(imageFolderPath);

            Console.WriteLine($"Generating JSON ...");
            string json = RecipeJson.Generate(cookbookProjectFolder);
            File.WriteAllText(jsonFilePath, json);
        }

        Console.WriteLine($"Reading JSON ...");
        return(RecipeJson.GetRecipes(new FileInfo(jsonFilePath)).Values.Select(x => x).ToArray());
    }