Exemple #1
0
        protected static void MetaData(FlattenStyles fs)
        {
            if (!_incMeta)
            {
                return;
            }
            var settingFullName = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "SIL", "Pathway",
                                               "Dictionary", "DictionaryStyleSettings.xml");

            if (!File.Exists(settingFullName))
            {
                return;
            }
            SettingsXml.Load(settingFullName);
            fs.TitleDefault  = SetValue("Title");
            fs.AuthorDefault = SetValue("Creator");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // ReSharper disable AssignNullToNotNullAttribute
            XmlCss.Load(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                             "CssSimpler.XmlCss.xsl")));
            SimplifyXhtml.Load(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                                    "CssSimpler.XhtmlSimplify.xsl"), ReaderSettings), XsltSettings, new NullResolver());
            // ReSharper enable AssignNullToNotNullAttribute
            // see: http://stackoverflow.com/questions/491595/best-way-to-parse-command-line-arguments-in-c
            var p = new OptionSet
            {
                {
                    "x|xml", "produce XML output of CSS",
                    v => OutputXml = !OutputXml
                },
                {
                    "b|backup", "make a backup of the original CSS file",
                    v => _makeBackup = !_makeBackup
                },
                {
                    "v|verbose", "increase debug message verbosity",
                    v =>
                    {
                        if (v != null)
                        {
                            ++_verbosity;
                        }
                    }
                },
                {
                    "h|help", "show this message and exit",
                    v => _showHelp = !_showHelp
                },
                {
                    "f|flat", "flattens the hierarchy simplifies the css required for -secmrd",
                    v => _flatten = !_flatten
                },
                {
                    "s|structure", "Use header tags for structure (1-3)",
                    v => _headerStyles += 1
                },
                {
                    "e|embed", "embed styles in output",
                    v => _embedStyles = !_embedStyles
                },
                //{
                //    "c|combine", "combine main and reversal(s) in a single output",
                //    v => _combineMainRev = !_combineMainRev
                //},
                {
                    "m|meta", "include title and author meta data",
                    v => _incMeta = !_incMeta
                },
                {
                    "r|remove", "remove Xml header and DOCTYPE",
                    v => _noXmlHeader = !_noXmlHeader
                },
                {
                    "d|div", "replace span with div for display block",
                    v => _divBlocks = !_divBlocks
                },
                {
                    "p|prefix=", "prefix style names with value",
                    v => { _decorateStyles = v; }
                },
                {
                    "u|update", "report status",
                    v => ReportStatus = !ReportStatus
                },
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);
                if (extra.Count == 0)
                {
                    Console.WriteLine(@"Enter full file name to process");
                    extra.Add(Console.ReadLine());
                }
            }
            catch (OptionException e)
            {
                Console.Write(@"SimpleCss: ");
                Console.WriteLine(e.Message);
                Console.WriteLine(@"Try `CssSimple --help' for more information.");
                return;
            }
            if (_showHelp || extra.Count != 1)
            {
                ShowHelp(p);
                return;
            }
            var lc = new LoadClasses(extra[0]);

            EntryReportInit();
            var styleSheet = lc.StyleSheet;

            MakeBackupIfNecessary(styleSheet, extra[0]);
            DebugWriteClassNames(lc.UniqueClasses);
            VerboseMessage("Clean up Stylesheet: {0}", styleSheet);
            var parser = new CssTreeParser();
            var xml    = new XmlDocument();

            UniqueClasses = lc.UniqueClasses;
            if (!File.Exists(styleSheet))
            {
                var errName  = styleSheet;
                var proposed = extra[0].Replace(".xhtml", ".css");
                styleSheet = proposed;
                if (!File.Exists(proposed))
                {
                    proposed   = proposed.Replace("_", "");
                    styleSheet = proposed;
                    if (!File.Exists(proposed))
                    {
                        proposed = Path.Combine(Path.GetDirectoryName(proposed), "main.css");
                        if (!File.Exists(proposed))
                        {
                            throw new FileNotFoundException(errName);
                        }
                        File.Copy(proposed, styleSheet, true);
                    }
                }
            }
            LoadCssXml(parser, styleSheet, xml);
            var tmpXhtmlFullName = WriteSimpleXhtml(extra[0]);
            var tmp2Out          = Path.GetTempFileName();
            // ReSharper disable once UnusedVariable
            var inlineStyle = new MoveInlineStyles(tmpXhtmlFullName, tmp2Out, styleSheet);

            xml.RemoveAll();
            UniqueClasses = null;
            LoadCssXml(parser, styleSheet, xml);
            // ReSharper disable once UnusedVariable
            var ps = new ProcessPseudo(tmp2Out, extra[0], xml, NeedHigher);

            RemoveCssPseudo(styleSheet, xml);
            var tmp3Out = Path.GetTempFileName();

            if (_flatten)
            {
                var fs = new FlattenStyles(extra[0], tmp3Out, xml, NeedHigher, _noXmlHeader, _decorateStyles);
                fs.Structure = _headerStyles;
                fs.DivBlocks = _divBlocks;
                MetaData(fs);
                fs.Parse();
                File.Copy(tmp3Out, extra[0], true);
                if (OutputXml)
                {
                    SavedXmlCssFileName = FlatXmlName(styleSheet);
                }
                OutputFlattenedStylesheet(extra[0], styleSheet, fs);
            }
            try
            {
                File.Delete(tmpXhtmlFullName);
                File.Delete(tmp2Out);
                File.Delete(tmp3Out);
            }
            catch
            {
                // ignored
            }
        }
Exemple #3
0
 protected static void OutputFlattenedStylesheet(string outFullName, string styleSheet, FlattenStyles fs)
 {
     if (_embedStyles)
     {
         var ms = new MemoryStream();
         MapXmlCssToStream(fs.MakeFlatCss(), ms);
         ms.Seek(0, 0);
         var tmp4Out = Path.GetTempFileName();
         var es      = new EmbedStyles(outFullName, tmp4Out, ms, _noXmlHeader);
         es.Parse();
         File.Copy(tmp4Out, outFullName, true);
         try
         {
             File.Delete(styleSheet);
             File.Delete(tmp4Out);
         }
         catch
         {
             // ignored
         }
     }
     else
     {
         WriteXmlAsCss(styleSheet, fs.MakeFlatCss());
     }
 }