-
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()