Skip to content

Commit

Permalink
Fix #17: Raise informative error when image file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak-mehta committed Aug 20, 2020
1 parent 19da798 commit 564fa72
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion present/markdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import os
import re
import shutil
from dataclasses import dataclass
Expand Down Expand Up @@ -115,13 +116,20 @@ def render(self):
return self.pad(self.obj["text"])


@dataclass
@dataclass(init=False)
class Image(object):
type: str = "image"
obj: dict = None

def __init__(self, type: str = "image", obj: dict = None):
self.type = type
self.obj = obj
if not os.path.exists(self.obj["src"]):
raise FileNotFoundError(f"{self.obj['src']} does not exist")

@property
def size(self):
# TODO: Support small, medium, large image sizes
return int(shutil.get_terminal_size()[1] / 2)

def render(self):
Expand Down

0 comments on commit 564fa72

Please sign in to comment.