Skip to content

Commit

Permalink
Merge pull request #127 from frederikmoellers/slide-numbers
Browse files Browse the repository at this point in the history
Option to show slide numbers
  • Loading branch information
regebro committed May 2, 2017
2 parents 98ecc42 + 4f5cb06 commit 1defc95
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes
2.4 (unreleased)
----------------

- Option to display slide numbers [frederikmoellers]

- #51: Positioning relative to other slide [naraesk]

- Removed the code that uses pkg_util to access included templates. We don't
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Other contributors (see CHANGES.txt for details):

* Adam Johnson [adamchainz]

* Frederik Möllers [frederikmoellers]

* David Baum [naraesk]

.. _impress.js: http://github.com/bartaz/impress.js
Expand Down
5 changes: 3 additions & 2 deletions docs/presentations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ them first in the document, or first on a slide.

Any fields you put first in a document will be rendered into attributes on
the main impress.js ``<div>``. The only ones that Hovercraft! will use are
``data-transition-duration``, ``skip-help`` and ``auto-console``.
``data-transition-duration``, ``skip-help``, ``auto-console`` and
``slide-numbers``.

Any fields you put first in a slide will be rendered into attributes on the
slide ``<div>``. This is used primarily to set the position/zoom/rotation of
Expand Down Expand Up @@ -442,4 +443,4 @@ included with Hovercraft!
.. _tutorial.rst: ./_sources/examples/tutorial.txt
.. _positions.rst: ./_sources/examples/positions.txt
.. _Reveal.js: http://lab.hakim.se/reveal-js/
.. _MathJax: http://www.mathjax.org/
.. _MathJax: http://www.mathjax.org/
6 changes: 5 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ Optional arguments:
``-s, --skip-help`` Do not show the initial help popup. You can also set
this by having ``:skip-help: true`` first in the presentation.


``-n, --skip-notes``
Do not include presenter notes in the output.

``-N, --slide-numbers``
Show the current slide number on the slide itself and in the presenter
console. You can also set this by having ``slide-numbers: true`` in
the presentation preamble.

``-p PORT, --port PORT``
The address and port that the server uses. Ex 8080 or
127.0.0.1:9000. Defaults to 0.0.0.0:8000.
Expand Down
5 changes: 5 additions & 0 deletions hovercraft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def my_gettext(s):
default=os.environ.get('HOVERCRAFT_MATHJAX', 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML'),
help=('The URL to the mathjax library.'
' (It will only be used if you have rST ``math::`` in your document)'))
parser.add_argument(
'-N',
'--slide-numbers',
action='store_true',
help=('Show slide numbers during the presentation.'))

args = parser.parse_args()

Expand Down
9 changes: 7 additions & 2 deletions hovercraft/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def resolve(self, url, pubid, context):
return self.resolve_string(resource_string(__name__, filename), context)


def rst2html(filepath, template_info, auto_console=False, skip_help=False, skip_notes=False, mathjax=False):
def rst2html(filepath, template_info, auto_console=False, skip_help=False, skip_notes=False, mathjax=False, slide_numbers=False):
# Read the infile
with open(filepath, 'rb') as infile:
rststring = infile.read()
Expand Down Expand Up @@ -79,6 +79,10 @@ def rst2html(filepath, template_info, auto_console=False, skip_help=False, skip_
if skip_help:
tree.attrib['skip-help'] = 'True'

# If the slide numbers should be displayed, set an attribute on the document:
if slide_numbers:
tree.attrib['slide-numbers'] = 'True'

# We need to set up a resolver for resources, so we can include the
# reST.xsl file if so desired.
parser = etree.XMLParser()
Expand Down Expand Up @@ -134,7 +138,8 @@ def generate(args):
# Make the resulting HTML
htmldata, dependencies = rst2html(args.presentation, template_info,
args.auto_console, args.skip_help,
args.skip_notes, args.mathjax)
args.skip_notes, args.mathjax,
args.slide_numbers)
source_files.extend(dependencies)

# Write the HTML out
Expand Down
11 changes: 11 additions & 0 deletions hovercraft/templates/default/css/hovercraft.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@
#hovercraft-help.disabled {
display: none;
}

/* Slide numbers */

div#slide-number
{
bottom: 1em;
font-size: 5vh;
position: absolute;
right: 2.5em;
text-align: right;
}
7 changes: 7 additions & 0 deletions hovercraft/templates/default/css/impressConsole.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ div#timer {
text-align: center;
float: left;
}

div#counter {
margin-left: 2em;
margin-right: 2em;
text-align: right;
float: right;
}
7 changes: 7 additions & 0 deletions hovercraft/templates/default/js/hovercraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ if (impressConsole) {
consoleWindow = console().open();
}
}

// Function updating the slide number counter
function update_slide_number(evt)
{
var step = evt.target.attributes['step'].value;
document.getElementById('slide-number').innerText = parseInt(step) + 1;
}
5 changes: 5 additions & 0 deletions hovercraft/templates/default/js/impressConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'<div id="clock">00:00:00 AM</div>' +
'<div id="timer" onclick="timerReset()">00m 00s</div>' +
'<div id="status">Loading</div>' +
'<div id="counter">Slide <span id="slide-number">1</span></div>' +
'</div>' +
'</body></html>';

Expand Down Expand Up @@ -137,6 +138,10 @@
preView.src = preSrc;
}

// Update the slide number
var slide_number = parseInt(document.querySelector('.active').attributes['step'].value) + 1;
consoleWindow.document.getElementById('slide-number').innerHTML = '' + slide_number;

consoleWindow.document.getElementById('status').innerHTML = '<span style="color: green">Ready</span>';
}
};
Expand Down
10 changes: 10 additions & 0 deletions hovercraft/templates/default/template.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ xmlns="http://www.w3.org/1999/xhtml">
</xsl:for-each>
</div>
</xsl:for-each>
<xsl:if test="/document/@slide-numbers">
<div id="slide-number" class="slide-number">
1
</div>
</xsl:if>

<div id="hovercraft-help">
<xsl:if test="/document/@skip-help">
Expand All @@ -110,6 +115,11 @@ xmlns="http://www.w3.org/1999/xhtml">
<xsl:copy-of select="@*"/>
</script>
</xsl:for-each>
<xsl:if test="/document/@slide-numbers">
<script type="text/javascript">
document.getElementById("impress").addEventListener("impress:stepenter", update_slide_number, false);
</script>
</xsl:if>

</body>
</html>
Expand Down
11 changes: 11 additions & 0 deletions hovercraft/templates/simple/css/hovercraft.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@
.impress-enabled #hovercraft-help.show {
display: block;
}

/* Slide numbers */

div#slide-number
{
bottom: 1em;
font-size: 5vh;
position: absolute;
right: 2.5em;
text-align: right;
}
9 changes: 8 additions & 1 deletion hovercraft/templates/simple/js/hovercraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ if (console) {
if (impressattrs.hasOwnProperty('auto-console') && impressattrs['auto-console'].value.toLowerCase() === 'true') {
consoleWindow = console().open();
}
}
}

// Function updating the slide number counter
function update_slide_number(evt)
{
var step = evt.target.attributes['step'].value;
document.getElementById('slide-number').innerText = parseInt(step) + 1;
}
10 changes: 10 additions & 0 deletions hovercraft/templates/simple/template.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ xmlns="http://www.w3.org/1999/xhtml">
</xsl:for-each>
</div>
</xsl:for-each>
<xsl:if test="/document/@slide-numbers">
<div id="slide-number" class="slide-number">
1
</div>
</xsl:if>

<div id="hovercraft-help">
<xsl:if test="not(/document/@skip-help)">
Expand All @@ -88,6 +93,11 @@ xmlns="http://www.w3.org/1999/xhtml">
<xsl:copy-of select="@*"/>
</script>
</xsl:for-each>
<xsl:if test="/document/@slide-numbers">
<script type="text/javascript">
document.getElementById("impress").addEventListener("impress:stepenter", update_slide_number, false);
</script>
</xsl:if>

</body>
</html>
Expand Down

0 comments on commit 1defc95

Please sign in to comment.