Add the original image to the context

This commit is contained in:
Simon Conseil
2013-05-14 00:38:03 +02:00
parent aa355ba55f
commit 3382e3e727
3 changed files with 23 additions and 5 deletions

View File

@@ -55,6 +55,13 @@ def get_thumb(settings, filename):
name + settings['thumb_suffix'] + ext)
def get_orig(settings, filename):
"""Return the path to the original image."""
path, filen = os.path.split(filename)
return os.path.join(path, settings['orig_dir'], filen)
def read_settings(filename=None):
"""Read settings from a config file in the source_dir root."""

View File

@@ -34,7 +34,7 @@ from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PrefixLoader
from jinja2.exceptions import TemplateNotFound
from .image import generate_thumbnail
from .settings import get_thumb
from .settings import get_thumb, get_orig
from .pkgmeta import __url__ as sigal_link
THEMES_PATH = os.path.normpath(os.path.join(
@@ -134,8 +134,11 @@ class Writer(object):
ctx['breadcumb'] = self.get_breadcumb(paths, relpath)
for i in paths[relpath]['img']:
ctx['images'].append({'file': i,
'thumb': get_thumb(self.settings, i)})
img_ctx = {'file': i,
'thumb': get_thumb(self.settings, i)}
if self.settings['keep_orig']:
img_ctx['big'] = get_orig(self.settings, i)
ctx['images'].append(img_ctx)
for d in paths[relpath]['subdir']:
dpath = os.path.normpath(os.path.join(relpath, d))

View File

@@ -3,7 +3,7 @@
import os
import pytest
from sigal.settings import read_settings, get_thumb
from sigal.settings import read_settings, get_thumb, get_orig
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
@@ -23,7 +23,7 @@ def test_read_settings(settings):
'pictures')
def test_thumb(settings):
def test_get_thumb(settings):
"""Test the get_thumb function."""
tests = [('example.jpg', 'thumbnails/example.tn.jpg'),
('test/example.jpg', 'test/thumbnails/example.tn.jpg'),
@@ -32,6 +32,14 @@ def test_thumb(settings):
assert get_thumb(settings, src) == ref
def test_get_orig(settings):
tests = [('example.jpg', 'original/example.jpg'),
('test/example.jpg', 'test/original/example.jpg'),
('test/t/example.jpg', 'test/t/original/example.jpg')]
for src, ref in tests:
assert get_orig(settings, src) == ref
def test_img_sizes(tmpdir):
"""Test that image size is swaped if needed."""