예제 #1
0
        public static string getLayoutContents(string layout, string filePath)
        {
            Console.WriteLine("getLayoutContents - " + layout + ", " + filePath);
            var layoutPath     = GlobalConfiguration.getConfiguration().source + "/" + GlobalConfiguration.getConfiguration().layouts_dir + "/" + layout + ".html";
            var layoutContents = WDHANFile.getFileContents(layoutPath);

            Console.WriteLine("getLayoutContents WITHOUTINCLUDE:\n" + layoutContents);
            layoutContents = Include.evalInclude(layoutPath);
            Console.WriteLine("getLayoutContents WITH:\n" + layoutContents);
            //layoutContents = WDHANFile.getFileContents(layoutPath);
            try
            {
                var subLayout = Page.parseFrontMatter(layoutPath)["layout"].ToString();
                Console.WriteLine(subLayout);
                var subLayoutPath = GlobalConfiguration.getConfiguration().source + "/" + GlobalConfiguration.getConfiguration().layouts_dir + "/" + subLayout + ".html";
                Console.WriteLine(subLayoutPath);
                layoutContents = getLayoutContents(subLayout, filePath).Replace("{{ content }}", layoutContents);
                Console.WriteLine(layout + " - HASSUB:\n" + layoutContents);
                return(layoutContents);
                //return parseLayout(collectionName, filePath, layoutContents);
            }
            catch (Exception ex)
            {
                Console.WriteLine("SUBLAYOUTEXCEPTION:\n" + ex.ToString());
                Console.WriteLine(layout + ":\n" + layoutContents);
                return(layoutContents);
                //return parseLayout(collectionName, filePath, layoutContents);
            }
        }
예제 #2
0
        public static string getSassContents(string file)
        {
            var fileContents   = WDHANFile.getFileContents(file);
            var includeSection = getIncludeSection(fileContents);
            int lastInd        = 0;

            for (int i = 0; i < includeSection.Split('"').Length - 1; i++)
            {
                Console.WriteLine("i: " + i);
                if (i % 2 == 0)
                {
                    lastInd = includeSection.IndexOf('"', lastInd + 1);
                    Console.WriteLine("LASTIND: " + lastInd);
                    includeSection = includeSection.Insert(lastInd + 1, GlobalConfiguration.getConfiguration().sass_dir + "/");
                    continue;
                }
                else
                {
                    lastInd = includeSection.IndexOf('"', lastInd + 1);
                    continue;
                }
            }
            Console.WriteLine("SASSINCLUDESECTION:\n" + includeSection);
            Console.WriteLine(fileContents.Replace(getIncludeSection(fileContents), includeSection));
            return(fileContents.Replace(getIncludeSection(fileContents), includeSection));
        }
예제 #3
0
파일: Include.cs 프로젝트: fossabot/WDHAN
        public static FluidValue IncludeFilter(FluidValue input, FilterArguments arguments, TemplateContext context)
        {
            // When a property of a JObject value is accessed, try to look into its properties
            TemplateContext.GlobalMemberAccessStrategy.Register <JObject, object>((source, name) => source[name]);

            // Convert JToken to FluidValue
            FluidValue.SetTypeMapping <JObject>(o => new ObjectValue(o));
            FluidValue.SetTypeMapping <JValue>(o => FluidValue.Create(o.Value));

            var    includePath = GlobalConfiguration.getConfiguration().source + "/" + GlobalConfiguration.getConfiguration().includes_dir + "/" + arguments.At(0).ToStringValue();
            string includeFile = WDHANFile.getFileContents(includePath);

            var includeContext = new TemplateContext();
            var includeJSON    = WDHANFile.parseFrontMatter(includePath);

            if (FluidTemplate.TryParse(includeFile, out var template))
            {
                for (int i = 1; i < arguments.Count - 1; i++)
                {
                    includeContext.SetValue(arguments.At(i).ToStringValue(), arguments.At(i));
                }
                includeContext.SetValue("include", includeJSON);
            }

            return(new StringValue(template.Render(includeContext)));
        }
예제 #4
0
 public static WDHANFile getDefinedFile(WDHANFile file)
 {
     file.modified_time = System.IO.File.GetLastWriteTimeUtc("./" + file.path);
     file.basename      = Path.GetFileNameWithoutExtension("./" + file.path);
     file.extname       = Path.GetExtension("./" + file.path);
     return(file);
 }
예제 #5
0
파일: Include.cs 프로젝트: fossabot/WDHAN
        public string parseInclude(string includePath, string filePath)
        {
            Console.WriteLine();
            var siteConfig   = GlobalConfiguration.getConfiguration();
            var fileContents = WDHANFile.getFileContents(includePath);

            // Expand layouts, then parse includes

            // When a property of a JObject value is accessed, try to look into its properties
            TemplateContext.GlobalMemberAccessStrategy.Register <JObject, object>((source, name) => source[name]);

            // Convert JToken to FluidValue
            FluidValue.SetTypeMapping <JObject>(o => new ObjectValue(o));
            FluidValue.SetTypeMapping <JValue>(o => FluidValue.Create(o.Value));

            var siteModel = JObject.Parse(File.ReadAllText("./_config.json"));
            var dataSet   = JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_data.json"));
            var pageModel = WDHANFile.parseFrontMatter(filePath);

            setVariables();
            var includeModel       = JObject.Parse(JsonConvert.SerializeObject(variables));
            var includeFrontmatter = WDHANFile.parseFrontMatter(includePath);

            includeModel.Merge(includeFrontmatter, new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            });

            try
            {
                if (FluidTemplate.TryParse(fileContents, out var template))
                {
                    var context = new TemplateContext();
                    context.CultureInfo = new CultureInfo(siteConfig.culture);

                    siteModel.Merge(dataSet, new JsonMergeSettings {
                        MergeArrayHandling = MergeArrayHandling.Union
                    });
                    context.SetValue("site", siteModel);
                    context.SetValue("page", pageModel);
                    foreach (var collection in siteConfig.collections)
                    {
                        context.SetValue(collection, JObject.Parse(File.ReadAllText(siteConfig.source + "/_" + collection + "/_config.json")));
                    }
                    context.SetValue("include", includeModel);
                    return(template.Render(context));
                }
                else
                {
                    Console.WriteLine("ERROR: Could not parse Liquid context for include " + includePath + ".");
                    return(fileContents);
                }
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Include " + includePath + " has no Liquid context to parse.");
                return(fileContents);
            }
        }
예제 #6
0
파일: Include.cs 프로젝트: fossabot/WDHAN
        public static string evalInclude(string filePath)
        {
            var fileContents = WDHANFile.getFileContents(filePath);

            if (fileContents.Contains("{% include "))
            {
                Console.WriteLine("INCLUDESPOTTED");
                List <string> includeCalls = new List <string>();
                string        readerString = "";
                Boolean       hitOnce      = false;
                foreach (var character in fileContents)
                {
                    if (character.Equals('{') && !hitOnce)
                    {
                        hitOnce       = true;
                        readerString += character;
                        continue;
                    }
                    if (character.Equals('}') && hitOnce)
                    {
                        hitOnce       = false;
                        readerString += character;
                        if (readerString.Contains("{% include "))
                        {
                            includeCalls.Add(readerString);
                            Console.WriteLine("INCLUDEADDED");
                        }
                        readerString = "";
                        continue;
                    }
                    if (hitOnce)
                    {
                        readerString += character;
                        continue;
                    }
                }
                foreach (var includeCall in includeCalls)
                {
                    Include currentInclude = new Include {
                        input = includeCall
                    };
                    string includePath = GlobalConfiguration.getConfiguration().source + "/" + GlobalConfiguration.getConfiguration().includes_dir + "/" + currentInclude.getCallArgs()[2];
                    fileContents = fileContents.Replace(includeCall, currentInclude.parseInclude(includePath, filePath));
                    Console.WriteLine("INCLUDEAAA: " + fileContents);
                }
            }
            else
            {
                //Console.WriteLine("NOINCLUDE - " + filePath);
            }
            Console.WriteLine("evalInclude:\n" + fileContents);
            return(fileContents);
        }
예제 #7
0
        public static List <Post> getPosts(string collection)
        {
            var         siteConfig = GlobalConfiguration.getConfiguration();
            List <Post> postList   = new List <Post>();
            var         builder    = new MarkdownPipelineBuilder().UseAdvancedExtensions();

            builder.BlockParsers.TryRemove <IndentedCodeBlockParser>();
            var pipeline = builder.Build();

            builder.Extensions.Remove(pipeline.Extensions.Find <AutoLinkExtension>());


            foreach (var post in Directory.GetFiles(siteConfig.collections_dir + "/_" + collection))
            {
                if (GlobalConfiguration.isMarkdown(Path.GetExtension(post).Substring(1)))
                {
                    if (!Path.GetFileNameWithoutExtension(post).Equals("index", StringComparison.OrdinalIgnoreCase))
                    {
                        postList.Add(getDefinedPost(new Post()
                        {
                            frontmatter = parseFrontMatter(post),
                            content     = Markdown.ToHtml(WDHANFile.parseRaw(post), pipeline),
                            path        = post
                        }));
                    }
                }
            }


            foreach (var post in postList)
            {
                Console.WriteLine(post);
            }

            try
            {
                postList.Sort((y, x) => x.frontmatter["date"].ToString().CompareTo(y.frontmatter["date"].ToString()));
                postList.Sort((y, x) => x.title.CompareTo(y.title));
            }
            catch (NullReferenceException)
            {
                postList.Sort((y, x) => x.title.CompareTo(y.title));
            }

            return(postList);
        }
예제 #8
0
파일: Include.cs 프로젝트: fossabot/WDHAN
        public string parseInclude(string includePath, JObject pageModel, string collectionName, string filePath)
        {
            setVariables();
            var siteConfig = GlobalConfiguration.getConfiguration();

            // When a property of a JObject value is accessed, try to look into its properties
            TemplateContext.GlobalMemberAccessStrategy.Register <JObject, object>((source, name) => source[name]);

            // Convert JToken to FluidValue
            FluidValue.SetTypeMapping <JObject>(o => new ObjectValue(o));
            FluidValue.SetTypeMapping <JValue>(o => FluidValue.Create(o.Value));

            string includeFile = WDHANFile.getFileContents(includePath);

            var context          = new TemplateContext();
            var givenModel       = JObject.Parse(JsonConvert.SerializeObject(variables));
            var frontmatterModel = WDHANFile.parseFrontMatter(includePath);

            givenModel.Merge(frontmatterModel, new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            });

            var siteModel = JObject.Parse(File.ReadAllText("./_config.json"));
            Dictionary <string, object> collectionConfig = JsonConvert.DeserializeObject <Dictionary <string, object> >(File.ReadAllText(siteConfig.source + "/_" + collectionName + "/_config.json"));
            var collectionModel = JObject.Parse(File.ReadAllText(siteConfig.source + "/_" + collectionName + "/_config.json"));
            var collectionPosts = JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_" + collectionName + "/_entries.json"));
            var dataSet         = JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_data.json"));

            try
            {
                JObject pageObjectModel = Page.getPage(Page.getDefinedPage(new Page {
                    frontmatter = pageModel, content = WDHANFile.getFileContents(filePath), path = filePath
                }));
                pageModel.Merge(pageObjectModel, new JsonMergeSettings
                {
                    MergeArrayHandling = MergeArrayHandling.Union
                });
            }
            catch
            {
            }

            siteModel.Merge(dataSet, new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            });

            Console.WriteLine("INCFILE: \n" + includeFile);

            try
            {
                if (FluidTemplate.TryParse(includeFile, out var template))
                {
                    context.SetValue("include", givenModel);
                    context.SetValue("site", siteModel);
                    context.SetValue("page", pageModel);
                    collectionModel.Merge(collectionPosts, new JsonMergeSettings
                    {
                        MergeArrayHandling = MergeArrayHandling.Union
                    });
                    context.SetValue(collectionName, collectionModel);
                    return(template.Render(context));
                }
                else
                {
                    Console.WriteLine("ERROR: Could not parse Liquid context.");
                    return(includeFile);
                }
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("No Liquid context to parse.");
                return(includeFile);
            }
        }
예제 #9
0
        public static string parseRaw(string filePath)
        {
            Console.WriteLine("parseRaw - " + filePath);

            var siteConfig   = GlobalConfiguration.getConfiguration();
            var fileContents = WDHANFile.getFileContents(filePath);

            fileContents = Include.evalInclude(filePath); // Expand includes (must happen after layouts are retreived, as layouts can have includes)

            // When a property of a JObject value is accessed, try to look into its properties
            TemplateContext.GlobalMemberAccessStrategy.Register <JObject, object>((source, name) => source[name]);

            // Convert JToken to FluidValue
            FluidValue.SetTypeMapping <JObject>(o => new ObjectValue(o));
            FluidValue.SetTypeMapping <JValue>(o => FluidValue.Create(o.Value));


            var siteModel = JObject.Parse(File.ReadAllText("./_config.json"));
            var dataSet   = JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_data.json"));
            var pageModel = WDHANFile.parseFrontMatter(filePath);

            Console.WriteLine("fileContents!!!" + filePath + ":\n" + fileContents);

            try
            {
                if (FluidTemplate.TryParse(fileContents, out var template))
                {
                    var context = new TemplateContext();
                    context.CultureInfo = new CultureInfo(siteConfig.culture);

                    siteModel.Merge(dataSet, new JsonMergeSettings {
                        MergeArrayHandling = MergeArrayHandling.Union
                    });
                    context.SetValue("site", siteModel);
                    context.SetValue("page", pageModel);

                    foreach (var collection in siteConfig.collections)
                    {
                        if (File.Exists(siteConfig.source + "/temp/_" + collection + "/_entries.json"))
                        {
                            var collectionModel = JObject.Parse(File.ReadAllText(siteConfig.source + "/_" + collection + "/_config.json"));
                            collectionModel.Merge(JObject.Parse(File.ReadAllText(siteConfig.source + "/temp/_" + collection + "/_entries.json")), new JsonMergeSettings {
                                MergeArrayHandling = MergeArrayHandling.Union
                            });
                            context.SetValue(collection, collectionModel);
                        }
                    }
                    Console.WriteLine("DONE!!! - " + filePath + " \n" + template.Render(context));
                    return(template.Render(context));
                }
                else
                {
                    Console.WriteLine("ERROR: Could not parse Liquid context for file " + filePath + ".");
                    Console.WriteLine("TryParse error:\n" + fileContents);
                    return(fileContents);
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("File " + filePath + " has no Liquid context to parse.\n" + ex.ToString());
                return(fileContents);
            }
        }