public HtmlIncludesTemplateDetectorProviderImpl(
            IConfiguration configuration,
            IWebHostEnvironment hostingEnvironment,
            IServiceProvider serviceProvider)
        {
            _hostEnvironment = hostingEnvironment;
            _configuration   = configuration;

            _htmlTemplateFileIncludesProviderCustomProcessor = serviceProvider.GetService <IHtmlTemplateFileIncludesProviderCustomProcessor>();

            // default provider will set its "Applies" property to "False", as the file is "null"
            _defaultIncludeProvider = new HtmlTemplateFileIncludesProviderImpl(null, _htmlTemplateFileIncludesProviderCustomProcessor);

            ParseAllHtmlFiles();
        }
Esempio n. 2
0
        public HtmlTemplateFileIncludesProviderImpl(string htmlFilePath, IHtmlTemplateFileIncludesProviderCustomProcessor customProcessor = null)
        {
            HeaderIncludes    = "";
            BodyIncludes      = "";
            HeaderCssIncludes = "";
            HeaderJsIncludes  = "";
            BodyJsIncludes    = "";

            Applies = File.Exists(htmlFilePath);

            if (Applies)
            {
                string html = File.ReadAllText(htmlFilePath);

                if (customProcessor != null)
                {
                    html = customProcessor.ProcessHtml(htmlFilePath, html);
                }

                // header part of the HTML <head></head>
                Match header = Regex.Match(
                    html,
                    "<head(?:\\s[^>]*)?>(.*?)</head(?:\\s[^>]*)?>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase
                    );

                var(includes, css, js) = ExtractCssAndScripts(header);
                HeaderIncludes        += includes;
                HeaderCssIncludes     += css;
                HeaderJsIncludes      += js;

                // header part of the HTML <body></body>
                Match body = Regex.Match(
                    html,
                    "<body(?:\\s[^>]*)?>(.*?)</body(?:\\s[^>]*)?>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase
                    );

                (includes, _, js) = ExtractCssAndScripts(body);
                BodyIncludes     += includes;
                BodyJsIncludes   += js;

                // ignore all other parts outside
            }
        }