aboutsummaryrefslogtreecommitdiff
path: root/textoutpc/builtin/_Progress.py
blob: 3692dc352c953d24009fe024b94da187e4bb6ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
#******************************************************************************
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************

from .. import BlockTag as _BlockTag

__all__ = ["ProgressTag"]


class ProgressTag(_BlockTag):
	""" Progress tag, used to display the progress on anything.
		Usage:

		[progress=50]My great progress bar[/progress]
		[progress=100][/progress] """

	aliases = ('[progress]',)
	raw = True

	def prepare(self, name, value):
		self._val = int(value)
		if self._val < 0 or self._val > 100:
			raise Exception("progress value should be between 0 and 100 incl.")

	def begin_html(self):
		return '<div>'

	def end_html(self):
		return '' \
			'<div class="progress">' \
			'<div class="progress-inner" style="width: {}%;">   {}%' \
			'</div></div></div>'.format(self._val, self._val)

# End of file.