123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- from __future__ import unicode_literals
- from docutils import nodes
- from docutils.parsers.rst import directives, Directive
- from . import config
- import os
- class UnityWebgl(Directive):
- required_arguments = 1
- optional_arguments = 4
- option_spec = {
- 'width': directives.positive_int,
- 'height': directives.positive_int,
- 'gameroot': directives.unchanged_required,
- 'template': directives.unchanged_required,
- }
- final_argument_whitespace = False
- has_content = False
- def load_template(self, game, gamesroot, templatepath, width, height):
- basepath = os.path.dirname(__file__)
- filepath = os.path.abspath(os.path.join(basepath, 'template.txt'))
- with open(filepath, 'r') as template:
- data = template.read()
- return data.format(game, gamesroot, templatepath, width, height)
- def run(self):
-
- game = self.arguments[0].strip()
- games_path = config.GAMES_ROOT_DIR
- template_path = config.TEMPLATE_PATH
- width = config.DEFAULT_WIDTH
- height = config.DEFAULT_HEIGHT
-
- if 'width' in self.options:
- width = self.options['width']
- if 'height' in self.options:
- height = self.options['height']
- if 'gameroot' in self.options:
- games_path = self.options['gameroot']
- if 'template' in self.options:
- template_path = self.options['template']
-
- games_path = games_path.rstrip('/')
- template_path = template_path.rstrip('/')
- html = self.load_template(game, games_path, template_path, width, height)
- return [
- nodes.raw('', html, format='html')]
- def register():
- directives.register_directive('unitywebgl', UnityWebgl)
|