diff --git a/examples/unreachable.gamebook b/examples/unreachable.gamebook index 37e15fd..96641b3 100644 --- a/examples/unreachable.gamebook +++ b/examples/unreachable.gamebook @@ -6,12 +6,17 @@ You can get here. Congratulations! * nothere You can not get here. Verification -should warn you about that, if enabled (with the --verify option). +should warn you about that. -* nothereeither :fake: +* notevenincluded :dummy: +This section is not even included in the output. Definitely +ignored when verifying. The section numbering is affected though. +That might be a bug. + +* nothereeither :fake: You can not get here either, but because it is tagged as fake there will be no warning generated. -* seconddummy :fake: +* secondfake :fake: Another fake section that is also ignored. diff --git a/expected/format.debug b/expected/format.debug index 6b72e5b..360d5be 100644 --- a/expected/format.debug +++ b/expected/format.debug @@ -11,5 +11,5 @@ Adventure begins in section 1. 1 (start) - This examples tests gamebook formatting, not so much game mechanics or references. Currently there is nothing here really. This section contains some tricky characters to quote, like } and { and " and ' and \. HTML will probably not like
or &boom;. There should be an image below as well. If something broke, turn to 2, otherwise turn to 3. [IMG]testimage.png[/IMG] 2 (bad) - Bad. 3 (good) - Good! -4 (dum) - Sections tagged as dummy will not be visible in output at all. +4 () - (EMPTY) END DEBUG OUTPUT diff --git a/expected/format.html b/expected/format.html index 64ccdce..f9eb8af 100644 --- a/expected/format.html +++ b/expected/format.html @@ -72,16 +72,6 @@ if (this.gamebook) { if (this.gamebook) { gamebook.addSection(3, document.getElementById('section3')); } -
-
4
-
- Sections tagged as dummy will not be visible in output at all. -
-
-
diff --git a/expected/format.rtf b/expected/format.rtf index a007e46..21a2dd4 100644 --- a/expected/format.rtf +++ b/expected/format.rtf @@ -45,9 +45,4 @@ \ql Good! \ \ -\b \qc 4 -\b0\ -\ql Sections tagged as dummy will not be visible in output at all. \ -\ - } diff --git a/expected/format.tex b/expected/format.tex index 3b2ad6d..213ee14 100644 --- a/expected/format.tex +++ b/expected/format.tex @@ -76,12 +76,5 @@ Adventure begins in section 1. \noindent Good! \vspace{1em} -\phantomsection \refstepcounter{sectionnr} -\label{section4} -\subsection*{\begin{center} \textbf{4} \end{center}} - - \noindent - Sections tagged as dummy will not be visible in output at all. -\vspace{1em} \end{document} diff --git a/expected/format.txt b/expected/format.txt index 85cfb6b..8d646f0 100644 --- a/expected/format.txt +++ b/expected/format.txt @@ -18,6 +18,3 @@ Adventure begins in section 1. 3 Good! -4 - Sections tagged as dummy will not be visible in output at all. - diff --git a/expected/unreachable.debug b/expected/unreachable.debug index 36bbeda..12f6592 100644 --- a/expected/unreachable.debug +++ b/expected/unreachable.debug @@ -1,12 +1,13 @@ BEGIN DEBUG OUTPUT Book title: Gamebook -Number of sections: 5 +Number of sections: 6 Turn to 1 to begin. -1 (start) - It starts here. You can get to 5. -2 (seconddummy) - Another fake section that is also ignored. +1 (start) - It starts here. You can get to 6. +2 (secondfake) - Another fake section that is also ignored. 3 (nothereeither) - You can not get here either, but because it is tagged as fake there will be no warning generated. -4 (nothere) - You can not get here. Verification should warn you about that, if enabled (with the --verify option). -5 (here) - You can get here. Congratulations! +4 () - (EMPTY) +5 (nothere) - You can not get here. Verification should warn you about that. +6 (here) - You can get here. Congratulations! END DEBUG OUTPUT diff --git a/expected/unreachable.dot b/expected/unreachable.dot index e68d216..3c51112 100644 --- a/expected/unreachable.dot +++ b/expected/unreachable.dot @@ -1,4 +1,4 @@ digraph gamebook { - 1->5 + 1->6 } diff --git a/expected/unreachable.html b/expected/unreachable.html index cd43cda..8fa7cc8 100644 --- a/expected/unreachable.html +++ b/expected/unreachable.html @@ -33,7 +33,7 @@
1
- It starts here. You can get to 5. + It starts here. You can get to 6.
-
4
+
+
5
- You can not get here. Verification should warn you about that, if enabled (with the --verify option). + You can not get here. Verification should warn you about that.
-
5
+
+
6
You can get here. Congratulations!
diff --git a/expected/unreachable.rtf b/expected/unreachable.rtf index 1f7fad1..87b61d2 100644 --- a/expected/unreachable.rtf +++ b/expected/unreachable.rtf @@ -14,7 +14,7 @@ \ \b \qc 1 \b0\ -\ql It starts here. You can get to \b 5 +\ql It starts here. You can get to \b 6 \b0 . \ \ @@ -29,12 +29,12 @@ \ql You can not get here either, but because it is tagged as fake there will be no warning generated. \ \ -\b \qc 4 +\b \qc 5 \b0\ -\ql You can not get here. Verification should warn you about that, if enabled (with the --verify option). \ +\ql You can not get here. Verification should warn you about that. \ \ -\b \qc 5 +\b \qc 6 \b0\ \ql You can get here. Congratulations! \ \ diff --git a/expected/unreachable.tex b/expected/unreachable.tex index 712b60d..3e65c31 100644 --- a/expected/unreachable.tex +++ b/expected/unreachable.tex @@ -42,7 +42,7 @@ Turn to 1 to begin. \subsection*{\begin{center} \textbf{1} \end{center}} \noindent - It starts here. You can get to \textbf{\autoref{section5}}. + It starts here. You can get to \textbf{\autoref{section6}}. \vspace{1em} \phantomsection \refstepcounter{sectionnr} @@ -60,19 +60,20 @@ Turn to 1 to begin. \noindent You can not get here either, but because it is tagged as fake there will be no warning generated. \vspace{1em} -\phantomsection \refstepcounter{sectionnr} -\label{section4} -\subsection*{\begin{center} \textbf{4} \end{center}} - - \noindent - You can not get here. Verification should warn you about that, if enabled (with the --verify option). -\vspace{1em} \phantomsection \refstepcounter{sectionnr} \label{section5} \subsection*{\begin{center} \textbf{5} \end{center}} + \noindent + You can not get here. Verification should warn you about that. +\vspace{1em} +\phantomsection +\refstepcounter{sectionnr} +\label{section6} +\subsection*{\begin{center} \textbf{6} \end{center}} + \noindent You can get here. Congratulations! \vspace{1em} diff --git a/expected/unreachable.txt b/expected/unreachable.txt index 586a0f8..35506f9 100644 --- a/expected/unreachable.txt +++ b/expected/unreachable.txt @@ -4,7 +4,7 @@ Turn to 1 to begin. 1 - It starts here. You can get to 5. + It starts here. You can get to 6. 2 Another fake section that is also ignored. @@ -12,9 +12,9 @@ Turn to 1 to begin. 3 You can not get here either, but because it is tagged as fake there will be no warning generated. -4 - You can not get here. Verification should warn you about that, if enabled (with the --verify option). - 5 + You can not get here. Verification should warn you about that. + +6 You can get here. Congratulations! diff --git a/formatgamebook.py b/formatgamebook.py index 6dfb05d..aaf91c5 100755 --- a/formatgamebook.py +++ b/formatgamebook.py @@ -67,9 +67,10 @@ def format_gamebook(inputfilenames, outputfilename, import_default_map_file, templatedirs, - shuffle): + shuffle, + includetag): output_format = make_output(outputfilename, templatedirs) - book = sections.Book(make_bookid(outputfilename)) + book = sections.Book(make_bookid(outputfilename), includetag) for inputfilename in inputfilenames: parse_file_to_book(open(inputfilename, 'r'), book) if import_default_map_file: @@ -185,6 +186,8 @@ if __name__ == '__main__': help='input gamebook file (eg test.gamebook)') ap.add_argument('outputfile', metavar='outputfile', help='output file (eg test.tex or test.rtf)') + ap.add_argument('-i', '--include', action='store', metavar='T', + dest='includetag', help='only include sections with tag') ap.add_argument('-M', '--no-default-map', action='store_false', dest='import_default_map_file', help='ignore default map file') @@ -203,4 +206,5 @@ if __name__ == '__main__': args.outputfile, args.import_default_map_file, templatedirs, - args.shuffle) + args.shuffle, + args.includetag) diff --git a/readme.org b/readme.org index 0b5ad3b..feb4a31 100644 --- a/readme.org +++ b/readme.org @@ -12,6 +12,7 @@ gamebook on paper or a screen (or for debugging it). : : optional arguments: : -h, --help show this help message and exit +: -i T, --include T only include sections with tag : -M, --no-default-map ignore default map file : -t D, --template D add custom template dir : -S, --no-shuffle do not shuffle sections diff --git a/sections.py b/sections.py index 36dc84f..610cfbe 100644 --- a/sections.py +++ b/sections.py @@ -58,12 +58,13 @@ STR_BOOK_CONFIG = set(['id', 'title', 'author', 'starttext', 'hideintrotext', INT_BOOK_CONFIG = set(['max']) class Book: - def __init__(self, bookid="gamebook"): + def __init__(self, bookid='gamebook', includetag=None): self.sections = [] self.introsections = [] self.from_name = {} self.nr_sections = {} self.codewords = set() + self.includetag = includetag self.config = {'max' : 0, 'title' : 'Gamebook', 'author' : '', @@ -82,6 +83,8 @@ class Book: raise Exception("Unknown book option '%s'." % name) def add(self, section): + if self.includetag and not section.hastag(self.includetag): + return if section.name in self.from_name: raise Exception('Duplicate section names (%s) not allowed.' % section.name) diff --git a/test_sections.py b/test_sections.py index fffdabd..3188a4d 100755 --- a/test_sections.py +++ b/test_sections.py @@ -35,5 +35,19 @@ class TestBook(TestCase): self.assertEqual(b.nr_sections, {}) self.assertEqual(b.config['max'], 0) + def test_includetag(self): + b = sections.Book(includetag='test') + sec = sections.Section("nnn", "text") + sec.add_tags(['some', 'test', 'other']) + b.add(sec) + self.assertEqual(b.sections, [sec]) + + def test_excludetag(self): + b = sections.Book(includetag='test') + sec = sections.Section("nnn", "text") + sec.add_tags(['some', 'other']) + b.add(sec) + self.assertEqual(b.sections, []) + if __name__ == '__main__': unittest.main()