From 3382e3e72762ec0fb8946ebf1f8c0fa27aa7d43f Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 14 May 2013 00:38:03 +0200 Subject: [PATCH] Add the original image to the context --- sigal/settings.py | 7 +++++++ sigal/writer.py | 9 ++++++--- tests/test_settings.py | 12 ++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/sigal/settings.py b/sigal/settings.py index cf63aec..943920b 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -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.""" diff --git a/sigal/writer.py b/sigal/writer.py index 54d5c2c..fd2a5aa 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -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)) diff --git a/tests/test_settings.py b/tests/test_settings.py index 55d736f..285eef2 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -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."""