Skip to content

Commit

Permalink
option figure_thumb
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Feb 21, 2023
1 parent 9e14ed1 commit ef7e559
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 11 deletions.
8 changes: 4 additions & 4 deletions customblocks/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def figure(
alt = kwds.pop('alt', None)
id = kwds.pop('id', None) or (str(uuid.uuid4()) if lightbox else None)
classes = list(args)

if local is None:
local = ctx.config.get('figure_local', None)
if embed is None:
embed = ctx.config.get('figure_embed', None)
"""
if thumb is None:
thumb = ctx.config.get('figure_thumb', None)
"""
thumbOption = ctx.config.get('figure_thumb', None)
if thumb is None or (thumb is True and thumbOption):
thumb=thumbOption
if lightbox is None:
lightbox = ctx.config.get('figure_lightbox', None)

Expand Down
78 changes: 71 additions & 7 deletions customblocks/generators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_figure(self):
"</figure>"
)

def test_figure_title(self):
def test_figure__title(self):
self.assertMarkdown("""
::: figure "https://via.placeholder.com/300.png" title="This is a title"
This figure is awesome
Expand All @@ -520,7 +520,7 @@ def test_figure_title(self):
"</figure>"
)

def test_figure_alt(self):
def test_figure__alt(self):
self.assertMarkdown("""
::: figure "https://via.placeholder.com/300.png" alt="This is a title"
This figure is awesome
Expand All @@ -537,7 +537,7 @@ def test_figure_alt(self):
"</figure>"
)

def test_figure_classes(self):
def test_figure__classes(self):
self.assertMarkdown("""
::: figure "https://via.placeholder.com/300.png" left-align
This figure is awesome
Expand All @@ -554,7 +554,7 @@ def test_figure_classes(self):
)


def test_figure_attributes_toFigure(self):
def test_figure__attributes_toFigure(self):
self.assertMarkdown("""
::: figure "https://via.placeholder.com/300.png" style="background: red"
This figure is awesome
Expand All @@ -570,7 +570,7 @@ def test_figure_attributes_toFigure(self):
"</figure>"
)

def test_figure_lightbox(self):
def test_figure__lightbox(self):
self.assertMarkdown("""
::: figure "https://via.placeholder.com/300.png" lightbox id=myimage
This figure is awesome
Expand Down Expand Up @@ -793,7 +793,7 @@ def test_figure__config_embed(self):
"</figure>"
)

def test_figure_config_lightbox(self):
def test_figure__config_lightbox(self):
self.setupConfig(figure_lightbox=True)
self.assertMarkdown("""
::: figure "https://via.placeholder.com/300.png" id=myimage
Expand All @@ -811,7 +811,7 @@ def test_figure_config_lightbox(self):
"</figure>"
)

def test_figure_config_lightbox_overriden(self):
def test_figure__config_lightbox_overriden(self):
self.setupConfig(figure_lightbox=True)
self.assertMarkdown("""
::: figure nolightbox "https://via.placeholder.com/300.png" id=myimage
Expand All @@ -828,6 +828,70 @@ def test_figure_config_lightbox_overriden(self):
"</figure>"
)

def test_figure__config_thumb(self):
with sandbox_dir() as sandbox:
self.setupConfig(figure_thumb=True)
self.sample_image('image.jpg')
self.assertMarkdown("""
::: figure image.jpg
""",
'<figure>'
'<a href="image.jpg" target="_blank">'
'<img '
'src="image.thumb-200x200.jpg" '
'/></a>'
"<figcaption></figcaption>\n"
"</figure>"
)

def test_figure__config_thumb_overriden(self):
with sandbox_dir() as sandbox:
self.setupConfig(figure_thumb=True)
self.sample_image('image.jpg')
self.assertMarkdown("""
::: figure nothumb image.jpg
""",
'<figure>'
'<a href="image.jpg" target="_blank">'
'<img '
'src="image.jpg" '
'/></a>'
"<figcaption></figcaption>\n"
"</figure>"
)

def test_figure__config_thumb_sizeNotOverridenByThumb(self):
with sandbox_dir() as sandbox:
self.setupConfig(figure_thumb=100)
self.sample_image('image.jpg')
self.assertMarkdown("""
::: figure thumb image.jpg
""",
'<figure>'
'<a href="image.jpg" target="_blank">'
'<img '
'src="image.thumb-100x100.jpg" '
'/></a>'
"<figcaption></figcaption>\n"
"</figure>"
)

def test_figure__config_thumb_sizedOverridenByFalse(self):
with sandbox_dir() as sandbox:
self.setupConfig(figure_thumb=100)
self.sample_image('image.jpg')
self.assertMarkdown("""
::: figure nothumb image.jpg
""",
'<figure>'
'<a href="image.jpg" target="_blank">'
'<img '
'src="image.jpg" '
'/></a>'
"<figcaption></figcaption>\n"
"</figure>"
)

def test_wikipedia(self):
self.assertMarkdown("""
::: wikipedia "Sant Joan Despí"
Expand Down

0 comments on commit ef7e559

Please sign in to comment.