Beispiel #1
0
    void ImportNecessaryFiles()
    {
        //create the icon file
        if (Icon != null)
        {
            try
            {
                string absolutePath = FileSystemServices.GetAbsolutePath(Icon, this.Document.SourcePath);
                string imgName = Path.GetFileName(absolutePath);
                BytesFile iconOutput = new BytesFile(imgName);
                ((BytesFile)iconOutput).Bytes = FileSystemServices.ReadBytesFromFile(absolutePath);
                this.Document.OutputDirectory.Add(iconOutput, true);
            }
            catch (Exception ex)
            {
                Messenger.Notify(
                        new QuicException(ex.Message,
                            this.Document.SourcePath, this.Line, this.Column, ex));
            }
        }

        if (this.Document.OutputFile is HtmlOutputFile)
        {
            HtmlOutputFile outputFile = (HtmlOutputFile)this.Document.OutputFile;

            outputFile.HeadSection.WriteLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
            outputFile.HeadSection.WriteLine("<!-- Bootstrap -->");
            outputFile.HeadSection.WriteLine("<link href=\"css/bootstrap.min.css\" rel=\"stylesheet\">");
            outputFile.HeadSection.WriteLine("<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->");
            outputFile.HeadSection.WriteLine("<!-- WARNING: Respond.js doesn't work if you view the page");
            outputFile.HeadSection.WriteLine("via file:// --> <!--[if lt IE 9]>");
            outputFile.HeadSection.WriteLine("<script src=\"https://oss.maxcdn.com/libs/html5shiv/3.7.0/ html5shiv.js\"></script>");
            outputFile.HeadSection.WriteLine("<script src=\"https://oss.maxcdn.com/libs/respond.js/1.3.0/ respond.min.js\"></script>");
            outputFile.HeadSection.WriteLine("<![endif]-->");
            if (Icon != null)
            {
                outputFile.HeadSection.WriteLine(string.Format("<link rel=\"icon\" href=\"{0}\">", Icon));
            }
        }
        else if (this.Document.OutputFile is TextFile)
        {
            TextFile outputFile = (TextFile)this.Document.OutputFile;

            outputFile.WriteLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
            outputFile.WriteLine("<link href=\"css/bootstrap.min.css\" rel=\"stylesheet\">");
            if (Icon != null)
            {
                outputFile.WriteLine(string.Format("<link rel=\"icon\" href=\"{0}\">", Icon));
            }
        }
    }
Beispiel #2
0
    void CheckForNecessaryFiles()
    {
        //css
        var cssObj = this.Document.OutputDirectory.Get("css");
        if (cssObj == null) //ensure the css dir exists
        {
            cssObj = new OutputDirectory("css");
            this.Document.OutputDirectory.Add(cssObj, true);
        }
        if (cssObj is OutputDirectory)
        {
            var cssDir = (OutputDirectory)cssObj;

            //ensure the relevant css files exist
            var bootstrapCss = cssDir.Get("bootstrap.css");
            if (bootstrapCss == null)
            {
                bootstrapCss = new CssOutputFile("bootstrap.css");
                ((CssOutputFile)bootstrapCss).Text = Properties.Resources.BootstrapDotCss;
                cssDir.Add(bootstrapCss, true);
            }

            var bootstrapCssMap = cssDir.Get("bootstrap.css.map");
            if (bootstrapCssMap == null)
            {
                bootstrapCssMap = new CssOutputFile("bootstrap.css.map");
                ((CssOutputFile)bootstrapCssMap).Text = Properties.Resources.BootstrapDotCssDotMap;
                cssDir.Add(bootstrapCssMap, true);
            }

            var bootstrapMinCss = cssDir.Get("bootstrap.min.css");
            if (bootstrapMinCss == null)
            {
                bootstrapMinCss = new CssOutputFile("bootstrap.min.css");
                ((CssOutputFile)bootstrapMinCss).Text = Properties.Resources.BootstrapDotMinDotCss;
                cssDir.Add(bootstrapMinCss, true);
            }

            var bootstrapThemeCss = cssDir.Get("bootstrap-theme.css");
            if (bootstrapThemeCss == null)
            {
                bootstrapThemeCss = new CssOutputFile("bootstrap-theme.css");
                ((CssOutputFile)bootstrapThemeCss).Text = Properties.Resources.BootstrapDashThemeDotCss;
                cssDir.Add(bootstrapThemeCss, true);
            }

            var bootstrapThemeCssMap = cssDir.Get("bootstrap-theme.css.map");
            if (bootstrapThemeCssMap == null)
            {
                bootstrapThemeCssMap = new CssOutputFile("bootstrap-theme.css.map");
                ((CssOutputFile)bootstrapThemeCssMap).Text = Properties.Resources.BootstrapDashThemeDotCssDotMap;
                cssDir.Add(bootstrapThemeCssMap, true);
            }

            var bootstrapThemeMinCss = cssDir.Get("bootstrap-theme.min.css");
            if (bootstrapThemeMinCss == null)
            {
                bootstrapThemeMinCss = new CssOutputFile("bootstrap-theme.min.css");
                ((CssOutputFile)bootstrapThemeMinCss).Text = Properties.Resources.BootstrapDashThemeDotMinDotCss;
                cssDir.Add(bootstrapThemeMinCss, true);
            }
        }

        //javascript
        var jsObj = this.Document.OutputDirectory.Get("js");
        if (jsObj == null) //ensure the js dir exists
        {
            jsObj = new OutputDirectory("js");
            this.Document.OutputDirectory.Add(jsObj, true);
        }
        if (jsObj is OutputDirectory)
        {
            var jsDir = (OutputDirectory)jsObj;

            //ensure the relevant js files exist
            var bootstrapJs = jsDir.Get("bootstrap.js");
            if (bootstrapJs == null)
            {
                bootstrapJs = new JsOutputFile("bootstrap.js");
                ((JsOutputFile)bootstrapJs).Text = Properties.Resources.BootstrapDotJs;
                jsDir.Add(bootstrapJs, true);
            }

            var bootstrapMinJs = jsDir.Get("bootstrap.min.js");
            if (bootstrapMinJs == null)
            {
                bootstrapMinJs = new JsOutputFile("bootstrap.min.js");
                ((JsOutputFile)bootstrapMinJs).Text = Properties.Resources.BootstrapDotMinDotJs;
                jsDir.Add(bootstrapMinJs, true);
            }

            var jqueryJs = jsDir.Get("jquery.js");
            if (jqueryJs == null)
            {
                jqueryJs = new JsOutputFile("jquery.js");
                ((JsOutputFile)jqueryJs).Text = Properties.Resources.JqueryDotJs;
                jsDir.Add(jqueryJs, true);
            }

            var npmJs = jsDir.Get("npm.js");
            if (npmJs == null)
            {
                npmJs = new JsOutputFile("npm.js");
                ((JsOutputFile)npmJs).Text = Properties.Resources.NpmDotJs;
                jsDir.Add(npmJs, true);
            }
        }

        //fonts
        var fontsObj = this.Document.OutputDirectory.Get("fonts");
        if (fontsObj == null) //ensure the fonts dir exists
        {
            fontsObj = new OutputDirectory("fonts");
            this.Document.OutputDirectory.Add(fontsObj, true);
        }
        if (fontsObj is OutputDirectory)
        {
            var fontsDir = (OutputDirectory)fontsObj;

            //ensure the relevant font files exist
            var glyphEot = fontsDir.Get("glyphicons-halflings-regular.eot");
            if (glyphEot == null)
            {
                glyphEot = new BytesFile("glyphicons-halflings-regular.eot");
                ((BytesFile)glyphEot).Bytes = Properties.Resources.GlyphiconsDashHalflingsDashRegularDotEot;
                fontsDir.Add(glyphEot, true);
            }

            var glyphSvg = fontsDir.Get("glyphicons-halflings-regular.svg");
            if (glyphSvg == null)
            {
                glyphSvg = new BytesFile("glyphicons-halflings-regular.svg");
                ((BytesFile)glyphSvg).Bytes = Properties.Resources.GlyphiconsDashHalflingsDashRegularDotSvg;
                fontsDir.Add(glyphSvg, true);
            }

            var glyphTtf = fontsDir.Get("glyphicons-halflings-regular.ttf");
            if (glyphTtf == null)
            {
                glyphTtf = new BytesFile("glyphicons-halflings-regular.ttf");
                ((BytesFile)glyphTtf).Bytes = Properties.Resources.GlyphiconsDashHalflingsDashRegularDotTtf;
                fontsDir.Add(glyphTtf, true);
            }

            var glyphWoff = fontsDir.Get("glyphicons-halflings-regular.woff");
            if (glyphWoff == null)
            {
                glyphWoff = new BytesFile("glyphicons-halflings-regular.woff");
                ((BytesFile)glyphWoff).Bytes = Properties.Resources.GlyphiconsDashHalflingsDashRegularDotWoff;
                fontsDir.Add(glyphWoff, true);
            }

            var glyphWoff2 = fontsDir.Get("glyphicons-halflings-regular.woff2");
            if (glyphWoff2 == null)
            {
                glyphWoff2 = new BytesFile("glyphicons-halflings-regular.woff2");
                ((BytesFile)glyphWoff2).Bytes = Properties.Resources.GlyphiconsDashHalflingsDashRegularDotWoff2;
                fontsDir.Add(glyphWoff2, true);
            }
        }
    }
Beispiel #3
0
    public override void Render()
    {
        if (this.Document.OutputFile is TextFile)
        {
            TextFile outputFile = (TextFile)this.Document.OutputFile;

            //opening tag
            outputFile.Write("<img");
            outputFile.Write(EmitID());

            if (Source != null)
            {
                try
                {
                    //get image absolute path
                    string absolutePath = FileSystemServices.GetAbsolutePath(Source, this.Document.SourcePath);
                    string finalPath = "";
                    //check if the image has already been saved
                    if (savedImages.ContainsKey(absolutePath.ToLower()))
                    {
                        finalPath = savedImages[absolutePath.ToLower()];
                    }
                    else
                    {
                        var imgObj = this.Document.OutputDirectory.Get("images");
                        if (imgObj == null)
                        {
                            imgObj = new OutputDirectory("images");
                            this.Document.OutputDirectory.Add(imgObj, true);
                        }
                        if (imgObj is OutputDirectory)
                        {
                            string imgName = Path.GetFileNameWithoutExtension(absolutePath);
                            string imgExt = Path.GetExtension(absolutePath);

                            var ImgDir = (OutputDirectory)imgObj;

                            string uniqueName = imgName + imgExt;
                            var imgOutput = ImgDir.Get(uniqueName);
                            int copyCount = 2;
                            while (imgOutput != null) //while an image with that name exists
                            {
                                //try names like "<img-name>2.png", "<img-name>3.png", "<img-name>4.png",...
                                uniqueName = imgName + copyCount + imgExt;
                                imgOutput = ImgDir.Get(uniqueName);
                                copyCount++;
                            }
                            //if (imgOutput == null) //not necessary since the while loop above ensures that it MUST be null on this line
                            {
                                imgOutput = new BytesFile(uniqueName);
                                //Bitmap image = new Bitmap(absolutePath);
                                //MemoryStream stream = new MemoryStream();
                                //image.Save(stream, ImageFormat.Png);
                                //((BytesOutputFile)imgOutput).Bytes = stream.GetBuffer();
                                ((BytesFile)imgOutput).Bytes = FileSystemServices.ReadBytesFromFile(absolutePath);
                                ImgDir.Add(imgOutput, true);

                                finalPath = "images\\" + uniqueName;
                                savedImages.Add(absolutePath.ToLower(), finalPath);
                            }
                        }
                    }

                    outputFile.Write(" src=\"" + finalPath + "\"");
                }
                catch (Exception ex)
                {
                    Messenger.Notify(
                            new QuicException(ex.Message,
                                this.Document.SourcePath, this.Line, this.Column, ex));
                }
            }
            outputFile.Write(EmitClasses());
            if (Hint != null)
            {
                outputFile.Write(string.Format(" alt=\"{0}\"", Hint));
            }

            //custom properties
            outputFile.Write(EmitCustomProperties());

            //closing tag
            outputFile.Write(">");
        }
    }