コード例 #1
0
class RevelationTestCase(unittest.TestCase):
    def setUp(self):
        self.media = tempfile.mkdtemp()
        _, self.slide = tempfile.mkstemp('.md')

        with open(self.slide, 'w') as file:
            file = file.write('# Pag1\n---\n# Pag2')

        self.app = Revelation(self.slide, self.media)

    def test_parse_media_root_empty(self):
        media_config = self.app.parse_media_root(None)

        self.assertDictEqual(media_config, {})

    def test_parse_media_root(self):
        media_config = self.app.parse_media_root(self.media)

        self.assertDictEqual(
            media_config,
            {'/{}'.format(os.path.basename(self.media)): self.media})

    def test_load_slides(self):
        slides = self.app.load_slides(self.slide, '---')

        self.assertListEqual(slides, ['# Pag1\n', '\n# Pag2'])
コード例 #2
0
    def setUp(self):
        self.media = tempfile.mkdtemp()
        _, self.slide = tempfile.mkstemp('.md')

        with open(self.slide, 'w') as file:
            file = file.write('# Pag1\n---\n# Pag2')

        self.app = Revelation(self.slide, self.media)
コード例 #3
0
    def setUp(self):
        self.tests_folder = tempfile.mkdtemp()
        self.media = tempfile.mkdtemp(dir=self.tests_folder)
        _, self.slide = tempfile.mkstemp(".md", dir=self.tests_folder)

        with open(self.slide, "w") as file:
            file = file.write("# Pag1\n---\n# Pag2")

        self.app = Revelation(self.slide, media=self.media)
コード例 #4
0
class RevelationTestCase(TestCase):
    def setUp(self):
        self.tests_folder = tempfile.mkdtemp()
        self.media = tempfile.mkdtemp(dir=self.tests_folder)
        _, self.slide = tempfile.mkstemp(".md", dir=self.tests_folder)

        with open(self.slide, "w") as file:
            file = file.write("# Pag1\n---\n# Pag2")

        self.app = Revelation(self.slide, media=self.media)

    def tearDown(self):
        shutil.rmtree(self.tests_folder)

    def test_parse_shared_data_empty(self):
        shared_data_config = self.app.parse_shared_data(None)

        self.assertDictEqual(shared_data_config, {})

    def test_parse_shared_data(self):
        shared_data_config = self.app.parse_shared_data(self.media)

        self.assertDictEqual(
            shared_data_config,
            {"/{}".format(os.path.basename(self.media)): self.media},
        )

    def test_load_slides(self):
        slides = self.app.load_slides(self.slide, "---")

        self.assertListEqual(slides, ["# Pag1\n", "\n# Pag2"])

    def test_client_request_ok(self):
        client = Client(self.app, BaseResponse)
        response = client.get("/")
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"), "text/html")

    def test_client_with_reload(self):
        app = Revelation(self.slide, media=self.media, reloader=True)
        client = Client(app, BaseResponse)
        response = client.get("/")
        self.assertIn("reloader", response.data.decode("utf8"))

    def test_client_without_reload(self):
        app = Revelation(self.slide, media=self.media, reloader=False)
        client = Client(app, BaseResponse)
        response = client.get("/")
        self.assertNotIn("reloader", response.data.decode("utf8"))
コード例 #5
0
    def setUp(self):
        self.tests_folder = tempfile.mkdtemp()
        self.media = tempfile.mkdtemp(dir=self.tests_folder)
        _, self.slide = tempfile.mkstemp(".md", dir=self.tests_folder)
        _, self.non_normalized_slide = tempfile.mkstemp(".md",
                                                        dir=self.tests_folder)
        _, self.non_ascii_slide = tempfile.mkstemp(".md",
                                                   dir=self.tests_folder)

        with open(self.slide, "w") as file:
            file = file.write("# Pag1\n---\n# Pag2.1\n---~\n# Page2.2")

        with open(self.non_normalized_slide, "w") as file:
            file = file.write("# Pag1\r---\r\n# Pag2")

        with open(self.non_ascii_slide, "w") as file:
            file = file.write("# こんにちは\n---\n# 乾杯")

        self.app = Revelation(self.slide, media=self.media)
コード例 #6
0
ファイル: cli.py プロジェクト: danieleteti/revelation
def start(ctx, presentation, port, config, media, theme, style, debug):
    """Start revelation presentation command"""
    # Check if reveal.js is installed
    if not os.path.exists(REVEALJS_FOLDER):
        click.echo("Reveal.js not found, running installation...")
        ctx.invoke(installreveal)

    # Check for presentation file
    if os.path.isfile(presentation):
        path = os.path.dirname(presentation)
    else:
        click.echo("Error: Presentation file not found.")
        ctx.exit(1)

    # Check for style override file
    if style and (not os.path.isfile(style) or not style.endswith(".css")):
        click.echo("Error: Style is not a css file or does not exists.")
        ctx.exit(1)

    # Check for media root
    if not media:
        media = os.path.join(path, "media")

    if not os.path.isdir(media):
        # Running without media folder
        media = None

        click.echo("Media folder not detected, running without media")

    # Check for theme root
    if not theme:
        theme = os.path.join(path, "theme")

    if not os.path.isdir(theme):
        # Running without theme folder
        theme = None

    # Check for configuration file
    if not config:
        config = os.path.join(path, "config.py")

    if not os.path.isfile(config):
        # Running without configuration file
        config = None

        click.echo("Configuration file not detected, running with defaults.")

    click.echo("Starting revelation server...")

    # instantiating revelation app
    app = Revelation(presentation, config, media, theme, style, True)

    if debug:
        app = DebuggedApplication(app)

    PresentationReloader.tracking_path = os.path.abspath(path)

    click.echo("Running at http://localhost:{}".format(port))

    WebSocketServer(
        ("localhost", port),
        Resource([
            ("^/reloader.*", PresentationReloader),
            ("^/.*", DebuggedApplication(app)),
        ]),
    ).serve_forever()
コード例 #7
0
ファイル: cli.py プロジェクト: danieleteti/revelation
def mkstatic(
    ctx,
    presentation,
    config,
    media,
    theme,
    output_folder,
    output_file,
    force,
    style,
):
    """Make static presentation"""

    # Check if reveal.js is installed
    if not os.path.exists(REVEALJS_FOLDER):
        click.echo("Reveal.js not found, running installation...")
        ctx.invoke(installreveal)

    output_folder = os.path.realpath(output_folder)

    # Check for style override file
    if os.path.isfile(output_folder):
        error_echo(
            "Error: '{}' already exists and is a file.".format(output_folder))
        ctx.exit(1)

    # Check for presentation file
    if os.path.isfile(presentation):
        path = os.path.dirname(presentation)
    else:
        error_echo("Error: Presentation file not found.")
        ctx.exit(1)

    if style and (not os.path.isfile(style) or not style.endswith(".css")):
        click.echo("Error: Style is not a css file or does not exists.")
        ctx.exit(1)

    if os.path.isdir(output_folder):
        if force:
            shutil.rmtree(output_folder)
        else:
            error_echo(
                ("Error: '{}' already exists, use --force to override it."
                 ).format(output_folder))
            ctx.exit(1)

    staticfolder = os.path.join(output_folder, "static")

    # make the output path
    os.makedirs(output_folder)

    # if has override style copy
    if style:
        shutil.copy(style, os.path.join(output_folder,
                                        os.path.basename(style)))

    shutil.copytree(REVEALJS_FOLDER, os.path.join(staticfolder, "revealjs"))

    # Check for media root
    if not media:
        media = os.path.realpath(os.path.join(path, "media"))
    else:
        media = os.path.realpath(media)

    if not os.path.isdir(media):
        # Running without media folder
        media = None
        click.echo("Media folder not detected, running without media.")
    else:
        shutil.copytree(media, os.path.join(output_folder, "media"))

    # Check for theme root
    if not theme:
        theme = os.path.join(path, "theme")

    if not os.path.isdir(theme):
        # Running without theme folder
        theme = None
        click.echo("Theme not detected, running without custom theme.")
    else:
        shutil.copytree(theme, os.path.join(output_folder, "theme"))

    # Check for configuration file
    if not config:
        config = os.path.join(path, "config.py")

    if not os.path.isfile(config):
        # Running without configuration file
        config = None

        click.echo("Configuration file not detected, running with defaults.")

    click.echo("Generating static presentation...")

    # instantiating revelation app
    app = Revelation(presentation, config, media, theme, style)

    if not os.path.isdir(output_folder):
        os.makedirs(output_folder)

    output_file = os.path.join(output_folder, output_file)

    with open(output_file, "w", encoding="utf-8") as f:
        f.write(app.dispatch_request(None).get_data(as_text=True))

    click.echo("Static presentation generated in {}".format(
        os.path.realpath(output_folder)))
コード例 #8
0
 def test_client_without_reload(self):
     app = Revelation(self.slide, media=self.media, reloader=False)
     client = Client(app, BaseResponse)
     response = client.get("/")
     self.assertNotIn("reloader", response.data.decode("utf8"))