Example #1
0
        public static void Load(IVirtualDirectory svgDir)
        {
            var context = new ScriptContext().Init();

            foreach (var svgGroupDir in svgDir.GetDirectories())
            {
                foreach (var file in svgGroupDir.GetFiles())
                {
                    if (file.Extension == "svg")
                    {
                        var svg = file.ReadAllText();
                        AddImage(svg, file.Name.WithoutExtension(), svgGroupDir.Name);
                    }
                    else if (file.Extension == "html")
                    {
                        var script = file.ReadAllText();
                        var svg    = context.EvaluateScript(script);
                        if (svg.StartsWith("<svg"))
                        {
                            AddImage(svg, file.Name.WithoutExtension(), svgGroupDir.Name);
                        }
                        else
                        {
                            log.Warn($"Unable to load #Script SVG '{file.Name}'");
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Get All Files in current and all sub directories
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public static IEnumerable <IVirtualFile> GetAllFiles(this IVirtualDirectory dir)
        {
            foreach (var subDir in dir.GetDirectories())
            {
                foreach (var file in subDir.GetAllFiles())
                {
                    yield return(file);
                }
            }

            foreach (var file in dir.Files)
            {
                yield return(file);
            }
        }
Example #3
0
        public static void Load(IVirtualDirectory svgDir)
        {
            if (svgDir == null)
            {
                throw new ArgumentNullException(nameof(svgDir));
            }

            var context = new ScriptContext {
                ScriptBlocks =
                {
                    new SvgScriptBlock()
                }
            }.Init();

            foreach (var svgGroupDir in svgDir.GetDirectories())
            {
                foreach (var file in svgGroupDir.GetFiles())
                {
                    if (file.Extension == "svg")
                    {
                        var svg = file.ReadAllText();
                        AddImage(svg, file.Name.WithoutExtension(), svgGroupDir.Name);
                    }
                    else if (file.Extension == "html")
                    {
                        var script = file.ReadAllText();
                        var svg    = context.EvaluateScript(script);
                        if (svg.StartsWith("<svg"))
                        {
                            AddImage(svg, file.Name.WithoutExtension(), svgGroupDir.Name);
                        }
                        else
                        {
                            log.Warn($"Unable to load #Script SVG '{file.Name}'");
                        }
                    }
                }
            }

            // Also load any .html #Script files which can register svg using {{#svg name group}} #Script block
            foreach (var svgScript in svgDir.GetAllMatchingFiles("*.html"))
            {
                var script = svgScript.ReadAllText();
                var output = context.EvaluateScript(script);
            }
        }