Ejemplo n.º 1
0
        public void Export(ScriptBook book, string filePath)
        {
            using (var writer = new HtmlTextWriter(new StreamWriter(File.Create(filePath))))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Style);

                var cssLines =
                    File.ReadAllLines(
                        Path.Combine(
                            Path.GetDirectoryName(
                                System.Reflection.Assembly.GetEntryAssembly().Location
                                ),
                            "style.css"
                            )
                        );

                writer.WriteLine();

                foreach (var cssLine in cssLines)
                {
                    writer.WriteLine(cssLine);
                }

                writer.RenderEndTag();
                writer.WriteLine();

                writer.RenderBeginTag(HtmlTextWriterTag.H1);
                writer.Write(book.Title);
                writer.RenderEndTag();
                writer.WriteLine();


                writer.AddAttribute(HtmlTextWriterAttribute.Class, "story-area");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                foreach (var chapter in book)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.H3);
                    writer.Write(chapter.Key.MainTitle);
                    writer.RenderEndTag();
                    writer.WriteLine();

                    writer.RenderBeginTag(HtmlTextWriterTag.H2);
                    writer.Write(chapter.Key.SubTitle);
                    writer.RenderEndTag();
                    writer.WriteLine();

                    foreach (var section in chapter.Value)
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Class, "story-section");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);

                        foreach (var paragraph in section)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.Class, "story-paragraph");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);

                            var lineBuilder = new LineBuilder();

                            foreach (var line in paragraph)
                            {
                                lineBuilder.Append(line);
                                //lineBuilder = concat(lineBuilder, line);
                            }

                            writer.Write(lineBuilder.ToString());
                            writer.RenderEndTag();
                            writer.WriteLine();
                        }

                        writer.RenderEndTag();
                        writer.WriteLine();

                        writer.AddAttribute(HtmlTextWriterAttribute.Class, "story-separator");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);
                        writer.Write("☆☆☆☆☆");
                        writer.RenderEndTag();

                        writer.AddAttribute(HtmlTextWriterAttribute.Class, "story-pagebreak");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);
                        writer.RenderEndTag();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var configuration = new ApplicationConfiguration(
                (NameValueCollection)ConfigurationManager.GetSection("Parser"),
                (NameValueCollection)ConfigurationManager.GetSection("ParserChapters"),
                (NameValueCollection)ConfigurationManager.GetSection("Writer")
                );

            var composition = new ApplicationComposition(configuration);

            ConversionAPI api = composition.ConversionAPI;

            ScriptBook book = api.Parse(args[0]);

            api.Export(book, args[1]);

            /*
             * Program()
             +Main()
             *
             *
             *
             * ConversionAPI(parser: ScriptParser, writer: DocumentWriter)
             +Parse(directory: string): ScriptText
             *      //calls parser.Parse()
             +Export(text: ScriptText, filePath: string)
             *  ...
             *
             * DocumentWriter(documentFormat: DocumentFormat)
             +Export(text: ScriptText, filePath: string)
             *      //choses export-method based on documentFormat
             *      //executes it
             *      //saves returned stream
             *  -ToHTML(text: ScriptText): Stream
             *  -ToEPUB(text: ScriptText): Stream
             *  -ToWord(text: ScriptText): Stream
             *
             * ScriptParser(chapters: ScriptChapters, parseMode: ParseMode)
             +Parse(directory: string): ScriptText
             *  -chapters
             *  -parseMode
             * =
             * ScriptText()
             *  //chapter-name -> section-name -> contained paragraphs -> single paragraph
             +Paragraphs: Dictionary<string, List<List<Paragraph>>>
             +AddChapter(name: string)
             +AddSection()
             +AddParagraph(paragraph: ScriptParagraph)
             *
             * ScriptChapters()
             +ById(id: int): string // chapter-name
             +Add(name: string, id: int)
             *
             * ScriptParagraph()
             +Lines: List<ScriptLine>
             +Add(line)
             *
             * ScriptLine(line: string, parseMode: ParseMode)
             *      uses ScriptLineParser
             *      creates ScriptLineWord[]
             +Person
             +Content: ScriptLineWord[]
             *
             * ParseMode() //enum
             *  SC3Output
             *  DoubleColonLine
             *
             * ScriptLineParser() //static
             +FromSC3Output(): ScriptLineWord[] //static
             +FromDoubleColonLine(): ScriptLineWord[] //static
             *
             * ScriptLineWord()
             +Content: string
             +Style: FontStyle
             +Alignment: TextAlignment
             *
             * ScriptFile(filePath: string)
             +IsScript: bool //story script, no menu or boot script
             +Prefix: string
             +ChapterIndex: int
             +SectionCharacter: char
             +SectionIndex: int
             +SubSectionIndex: int
             +FilePath
             *
             *
             *
             *
             *
             *
             *
             * Class-Variables:
             *  chapters: ScriptChapters
             *  parseMode: ParseMode
             *
             * t = ScriptText()
             * p = ScriptParagraph()
             * l = ScriptLine()
             *
             * each file: LinkedList<ScriptFile>
             *
             *  if file.Value.ChapterIndex > file.Previous.Value.ChapterIndex
             *      t.AddChapter(chapters.ById(file.Value.ChapterIndex))
             *
             *  else
             *      t.AddSection()
             *
             *  each line: LinkedList<string>
             *
             *      if line.Value.Person != line.Previous.Value.Person
             *          t.AddParagraph(p)
             *          p = ScriptParagraph()
             *
             *      l = ScriptLine(line.Value, parseMode)
             *      p.Add(l)
             */
        }
 internal void Export(ScriptBook book, string filePath)
 {
     writer.Export(book, filePath);
 }
Ejemplo n.º 4
0
 public void Export(ScriptBook book, string filePath)
 {
     throw new NotImplementedException("Word export won't ever be implemented!");
 }