Skip to content

Commit

Permalink
Translated OnStage 2023 rules into AsciiDoc - minor fixes remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
David Schwarz committed May 10, 2023
0 parents commit 54cf0de
Show file tree
Hide file tree
Showing 18 changed files with 1,199 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .ci/adoc-to-tex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
mkdir -p tmp rules_documents

set -euo pipefail

OUTPUT_FILE=$1
cp $1.adoc tmp/$1.adoc

cd tmp

cp $OUTPUT_FILE.adoc _$OUTPUT_FILE.adoc
python3 ../.ci/criticmarkup_to_adoc.py _$OUTPUT_FILE.adoc > $OUTPUT_FILE.adoc

asciidoctor $OUTPUT_FILE.adoc
asciidoctor -b docbook $OUTPUT_FILE.adoc

mv $OUTPUT_FILE.html ../rules_documents/
148 changes: 148 additions & 0 deletions .ci/criticmarkup_to_adoc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import re
import sys
import textwrap

DELETION_REGEXP = re.compile(r'\{--(.*?)--\}', re.DOTALL)
ADDITION_REGEXP = re.compile(r'\{\+\+(.*?)\+\+\}', re.DOTALL)
SUBSTITUTION_REGEXP = re.compile(r'\{~~(.*?)~>(.*?)~~\}', re.DOTALL)


class Deletor:

def __init__(self, changes, note_fmt, replacement_fmt):
self.n_deletions = 0
self.changes = changes
self.note_fmt = note_fmt
self.replacement_fmt = replacement_fmt

def __call__(self, match):
self.n_deletions += 1

def callback(n_deletions, match):
m = match.group(1).replace('\n', ' ')
txt = self.replacement_fmt.replace('{PREVIOUS}', m)
note = self.note_fmt.replace('{PREVIOUS}', m)
change_id = f'deletion-{n_deletions}'
self.changes.append(change_id)
return f'[[{change_id}, {note}]]\n{txt}'

return callback(self.n_deletions, match)


class Additor:

def __init__(self, changes, note_fmt, replacement_fmt):
self.n_additions = 0
self.changes = changes
self.note_fmt = note_fmt
self.replacement_fmt = replacement_fmt

def __call__(self, match):
self.n_additions += 1

def callback(n_additions, match):
m = match.group(1).replace('\n', ' ')
txt = self.replacement_fmt.replace('{CURRENT}', m)
note = self.note_fmt.replace('{CURRENT}', m)
change_id = f'addition-{n_additions}'
self.changes.append(change_id)
return f'[[{change_id}, {note}]]\n{txt}'

return callback(self.n_additions, match)


class Substituter:

def __init__(self, changes, note_fmt, replacement_fmt,
wrap_long_strings_at=None):
self.n_substitutions = 0
self.changes = changes
self.note_fmt = note_fmt
self.replacement_fmt = replacement_fmt
self.wrap_long_strings_at = wrap_long_strings_at

def shorten(self, string):
if self.wrap_long_strings_at is not None:
return textwrap.shorten(string,
self.wrap_long_strings_at,
placeholder='...')
return string

def __call__(self, match):
self.n_substitutions += 1

def callback(n_substitutions, match):
previous = match.group(1).replace('\n', ' ')
current = match.group(2).replace('\n', ' ')

short_previous = self.shorten(previous)
short_current = self.shorten(current)

txt = self.replacement_fmt.replace('{CURRENT}', current) \
.replace('{PREVIOUS}', previous)
note = self.note_fmt.replace('{CURRENT}', short_current) \
.replace('{PREVIOUS}', short_previous)

change_id = f'substitution-{n_substitutions}'
self.changes.append(change_id)
return f'[[{change_id}, {note}]]\n{txt}'

return callback(self.n_substitutions, match)


class CriticMarkupPreprocessor:

def __init__(self,
change_listing_fmt='- {CHANGE}',
addition_note_fmt='Added "{CURRENT}"',
addition_replacement_fmt='{CURRENT}',
deletion_note_fmt='Deleted "{PREVIOUS}"',
deletion_replacement_fmt='(used to be "{PREVIOUS}")',
substitution_note_fmt='Changed "{PREVIOUS}" to "{CURRENT}"',
substitution_replacement_fmt='{CURRENT} (used to be "{PREVIOUS}")'): # noqa
self.changes = []
self.change_listing_fmt = change_listing_fmt
self.addition_note_fmt = addition_note_fmt
self.addition_replacement_fmt = addition_replacement_fmt
self.deletion_note_fmt = deletion_note_fmt
self.deletion_replacement_fmt = deletion_replacement_fmt
self.substitution_note_fmt = substitution_note_fmt
self.substitution_replacement_fmt = substitution_replacement_fmt

def convert(self, infile):
d = Deletor(self.changes,
self.deletion_note_fmt,
self.deletion_replacement_fmt)
a = Additor(self.changes,
self.addition_note_fmt,
self.addition_replacement_fmt)
s = Substituter(self.changes,
self.substitution_note_fmt,
self.substitution_replacement_fmt)

with open(infile) as f:
instr = f.read()
instr = DELETION_REGEXP.sub(d, instr)
instr = ADDITION_REGEXP.sub(a, instr)
instr = SUBSTITUTION_REGEXP.sub(s, instr)

list_of_changes = [self.change_listing_fmt.replace('{CHANGE}',
change)
for change in self.changes]
changes = '\n'.join(list_of_changes)

instr = instr.replace('{+-~TOC-CHANGES~-+}', changes)
return instr


if __name__ == '__main__':
cmp = CriticMarkupPreprocessor(
change_listing_fmt='- <<{CHANGE}>>',
addition_note_fmt='Added "{CURRENT}"',
addition_replacement_fmt='[red]#*{CURRENT}*#',
deletion_note_fmt='Deleted "{PREVIOUS}"',
deletion_replacement_fmt='footnote:[In previous version this said "{PREVIOUS}"]', # noqa
substitution_note_fmt='Changed "{PREVIOUS}" to "{CURRENT}"',
substitution_replacement_fmt='[red]#*{CURRENT}*#\nfootnote:[In previous version this said "{PREVIOUS}"]' # noqa
)
print(cmp.convert(sys.argv[1]))
25 changes: 25 additions & 0 deletions .ci/tex-to-pdf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -euo pipefail

OUTPUT_FILE=$1

cp manual.sty tmp/
cp -r media tmp/
cd tmp

# Apply custom styling to DocBook
dblatex -T db2latex $OUTPUT_FILE.xml -t tex --texstyle=./manual.sty -p ../custom.xsl

# Go through the generated .tex output, find the place where the preamble ends
# (marked by the \mainmatter command) and create a file without it.
cat $OUTPUT_FILE.tex | awk 'f;/\\mainmatter/{f=1}' > $OUTPUT_FILE"_without_preamble.tex"
# Concat the standardized preamble with the "without_preamble" version of the file
cat ../preamble.tex $OUTPUT_FILE"_without_preamble.tex" > $OUTPUT_FILE.tex
texliveonfly $OUTPUT_FILE.tex
pdflatex $OUTPUT_FILE.tex
pdflatex $OUTPUT_FILE.tex

mv $OUTPUT_FILE.pdf ../rules_documents/

cd ..
rm -r tmp
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on: [push]
jobs:
build:
name: build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: build the rules
run: |
docker run -v $(pwd):/documents asciidoctor/docker-asciidoctor .ci/adoc-to-tex.sh onstage_rules
docker run -v $(pwd):/documents mrshu/texlive-dblatex .ci/tex-to-pdf.sh onstage_rules
mkdir -p dist/${GITHUB_REF#refs/heads/}/
cp -R ./media rules_documents/* dist/${GITHUB_REF#refs/heads/}/
- name: publish the rules
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
keep_files: True
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tmp/*
rules_documents/*
61 changes: 61 additions & 0 deletions custom.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version='1.0' encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<xsl:template match="phrase[@role='red']">
<xsl:text>
\textcolor{red}{
</xsl:text>
<xsl:apply-templates/>
<xsl:text>
}
</xsl:text>
</xsl:template>
<xsl:template match="phrase[@role='blue-background']">
<xsl:text>
\sethlcolor{blue}\hl{
</xsl:text>
<xsl:apply-templates/>
<xsl:text>
}
</xsl:text>
</xsl:template>
<xsl:template match="phrase[@role='green-background']">
<xsl:text>
\sethlcolor{green}\hl{
</xsl:text>
<xsl:apply-templates/>
<xsl:text>
}
</xsl:text>
</xsl:template>

<xsl:template match="section/simpara">
<xsl:text>
\p </xsl:text>
<xsl:apply-templates/>
<xsl:text>

</xsl:text>
</xsl:template>

<xsl:template match="part|chapter|appendix|
sect1|sect2|sect3|sect4|sect5|section" mode="label.markup">
<xsl:text>\ref{</xsl:text>
<xsl:value-of select="(@id|@xml:id)[1]"/>
<xsl:text>}</xsl:text>
</xsl:template>


<xsl:param name="xref.with.number.and.title" select="1"></xsl:param>

<xsl:param name="local.l10n.xml" select="document('')"/>
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
<l:l10n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" language="en">
<l:context name="xref-number-and-title">
<l:template name="section" text="Rule %n, %t"/>
</l:context>
</l:l10n>
</l:i18n>

</xsl:stylesheet>


Binary file added icons/caution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/important.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/note.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/tip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions manual.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
%%
%% This style is derivated from the db2latex one
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{manual}


% The defined options
\DeclareOption{hyperlink}{ \def\DBKhyperlink{yes} }
\DeclareOption{nohyperlink}{ \def\DBKhyperlink{no} }

% Default values
\ExecuteOptions{hyperlink}

% If defined, process the options
\ProcessOptions\relax

%% Just use the original package and pass the options
\RequirePackageWithOptions{db2latex}

\renewcommand{\maketitle}{

\begin{center}
{\LARGE \@title \par}
\vskip 8em
\end{center}

% \pagestyle{empty}

% \noindent
% \textbf{\DBKtitle \\}
% \ifx\DBKauthor\empty\else{by \DBKauthor \\}\fi
% \hspace{0pt}\\
% \ifthenelse{\equal{\DBKedition}{}}{}{Edition \DBKedition \\}
% \ifthenelse{\equal{\DBKpubdate}{}}{}{Published \DBKpubdate \\}
% \ifthenelse{\equal{\DBKcopyright}{}}{}{\DBKcopyright \\}
% \hspace{0pt}\\
% Now the legalnotice block
% \DBKlegalblock
% Ahoj
% \newpage
}

\renewenvironment{DBKadmonition}[2] {
% this code corresponds to the \begin{admonition} command
\hspace{0mm}\newline\hspace*\fill\newline
\noindent
\setlength{\fboxsep}{5pt}
\setlength{\admlength}{\linewidth}
\addtolength{\admlength}{-2\fboxsep}
\addtolength{\admlength}{-10\fboxrule}
\admminipage{\admlength}
~\\[1mm]
\ifthenelse{\equal{#1}{}}{
\def\admgraph{false}
}{
\def\admgraph{true}
\includegraphics[width=1cm]{icons/#1}
\addtolength{\admlength}{-1cm}
\addtolength{\admlength}{-20pt}
\begin{minipage}[lt]{\admlength}
}
\parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt
} %done
{ % this code corresponds to the \end{admonition} command
\vspace{5mm}
\ifthenelse{\equal{\admgraph}{false}}{}{
\end{minipage}
}
\endadmminipage
\vspace{.5em}
\par
}
Binary file added media/OnStage/StageLayout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/OnStage/StagePerfLeft.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/OnStage/StagePerfRight.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/robocup_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 54cf0de

Please sign in to comment.