Browse Source

Use directly the `Album` object in the template.

- This allows to use all attributes of the album object.
- The meaning of the theme variables is more explicit.
pull/87/merge
Simon Conseil 12 years ago
parent
commit
cffd5d2c63
  1. 16
      docs/themes.rst
  2. 6
      sigal/gallery.py
  3. 34
      sigal/themes/colorbox/templates/index.html
  4. 32
      sigal/themes/galleria/templates/index.html
  5. 25
      sigal/writer.py

16
docs/themes.rst

@ -26,6 +26,13 @@ Variables
You can use the following variables in your template:
``album``
The current album that is rendered in the HTML file, represented by an
:class:`~sigal.gallery.Album` object. ``album.medias`` contains the list
of all medias in the album (represented by the
:class:`~sigal.gallery.Image` and :class:`~sigal.gallery.Video` objects,
inherited from :class:`~sigal.gallery.Media`).
``index_title``
Name of the index. This is either the directory name or the title specified
in the ``index.md`` of the ``source`` directory.
@ -39,20 +46,11 @@ You can use the following variables in your template:
``theme.name``, ``theme.url``
Name and url of the currently used theme.
Then the current album that is rendered in the HTML file is represented by an
:class:`~sigal.gallery.Album` object, and the following attributes are
available in the template: ``albums``, ``breadcrumb``, ``description``,
``index_url``, ``medias``, ``meta``, ``zip``, ``title``.
.. autoclass:: sigal.gallery.Album
:members:
:undoc-members:
:inherited-members:
``medias`` contains the list of all medias in the album (represented by the
:class:`~sigal.gallery.Image` and :class:`~sigal.gallery.Video` objects,
inherited from :class:`~sigal.gallery.Media`).
.. autoclass:: sigal.gallery.Media
:members:
:undoc-members:

6
sigal/gallery.py

@ -432,14 +432,14 @@ class Gallery(object):
self.writer = Writer(self.settings, theme=self.theme,
index_title=self.albums['.'].title)
for path, album in self.albums.items():
self.writer.write(self.albums, path, album)
for album in self.albums.values():
self.writer.write(album)
def process_dir(self, album, force=False):
"""Process a list of images in a directory."""
if sys.stdout.isatty():
print(colored('\n->', BLUE), str(album))
print(colored('->', BLUE), str(album))
else:
self.logger.warn(album)

34
sigal/themes/colorbox/templates/index.html

@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{ title }}</title>
<title>{{ album.title }}</title>
<meta name="description" content="">
<meta name="author" content="{{ author }}">
<meta name="viewport" content="width=device-width">
@ -20,7 +20,7 @@
<div class="four columns">
<div class="sidebar">
<h1><a href="{{ index_url }}">{{ index_title }}</a></h1>
<h1><a href="{{ album.index_url }}">{{ index_title }}</a></h1>
{% if settings.links %}
<nav id="menu">
@ -41,9 +41,9 @@
<div id="main" role="main" class="twelve columns offset-by-four">
<header>
{% if breadcrumb %}
{% if album.breadcrumb %}
<h2>
{%- for url, title in breadcrumb -%}
{%- for url, title in album.breadcrumb -%}
<a href="{{ url }}">{{ title }}</a>
{%- if not loop.last %} » {% endif -%}
{% endfor -%}
@ -52,8 +52,8 @@
{% endif %}
</header>
{% if albums %}
{% for album in albums %}
{% if album.albums %}
{% for alb in album.albums %}
{% if loop.index % 3 == 1 %}
<div id="albums" class="row">
{% endif%}
@ -61,10 +61,10 @@
<div class="four columns thumbnail
{% if loop.index % 3 == 1 %}alpha{% endif%}
{% if loop.index % 3 == 0 %}omega{% endif%}">
<a href="{{ album.url }}">
<img src="{{ album.thumbnail }}" class="album_thumb"
alt="{{ album.name }}" title="{{ album.name }}" /></a>
<span class="album_title">{{ album.title }}</span>
<a href="{{ alb.url }}">
<img src="{{ alb.thumbnail }}" class="album_thumb"
alt="{{ alb.name }}" title="{{ alb.name }}" /></a>
<span class="album_title">{{ alb.title }}</span>
</div>
{% if loop.last or loop.index % 3 == 0 %}
@ -73,7 +73,7 @@
{% endfor %}
{% endif %}
{% if medias %}
{% if album.medias %}
{% macro img_description(media) -%}
{% if media.big %} data-big="{{ media.big }}"{% endif %}
{% if media.exif %}
@ -83,7 +83,7 @@
{% endif %}
{%- endmacro %}
<div id="gallery" class="row">
{% for media in medias %}
{% for media in album.medias %}
{% if media.type == "image" %}
<div class="four columns thumbnail
{% if loop.index % 3 == 1 %}alpha{% endif%}
@ -116,24 +116,24 @@
</div>
{% endif %}
{% if zip %}
{% if album.zip %}
<div id="additionnal-infos" class="row">
<p>
<a href="{{ zip }}"
<a href="{{ album.zip }}"
title="Download a zip archive with all images">Download ZIP</a>
</p>
</div>
{% endif %}
{% if description %}
{% if album.description %}
<div id="description" class="row">
{{ description }}
{{ album.description }}
</div>
{% endif %}
</div>
</div>
{% if medias %}
{% if album.medias %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="{{ theme.url }}/js/jquery-1.10.2.min.js"%3E%3C/script%3E'))</script>
<script src="{{ theme.url }}/js/jquery.colorbox.min.js"></script>

32
sigal/themes/galleria/templates/index.html

@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{ title|striptags }}</title>
<title>{{ album.title|striptags }}</title>
<meta name="description" content="">
<meta name="author" content="{{ author }}">
<meta name="viewport" content="width=device-width">
@ -19,7 +19,7 @@
<body>
<div class="container">
<header>
<h1><a href="{{ index_url }}">{{ index_title }}</a></h1>
<h1><a href="{{ album.index_url }}">{{ index_title }}</a></h1>
{% if settings.links %}
<nav id="menu">
@ -31,9 +31,9 @@
</nav>
{% endif %}
{% if breadcrumb %}
{% if album.breadcrumb %}
<h2>
{%- for url, title in breadcrumb -%}
{%- for url, title in album.breadcrumb -%}
<a href="{{ url }}">{{ title }}</a>
{%- if not loop.last %} » {% endif -%}
{% endfor -%}
@ -43,21 +43,21 @@
</header>
<div id="main" role="main">
{% if albums %}
{% if album.albums %}
<div id="albums">
<!-- <h1>Albums</h1> -->
<ul>
{% for album in albums %}
<li><a href="{{ album.url }}">
<img src="{{ album.thumbnail }}" class="album_thumb" alt="{{ album.name }}" title="{{ album.name }}" /></a>
<span class="album_title">{{ album.title }}</span>
{% for alb in album.albums %}
<li><a href="{{ alb.url }}">
<img src="{{ alb.thumbnail }}" class="album_thumb" alt="{{ alb.name }}" title="{{ alb.name }}" /></a>
<span class="album_title">{{ alb.title }}</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if medias %}
{% if album.medias %}
{% macro img_description(media) -%}
{%- if media.big %}<a href='{{ media.big }}'>Full size</a>{% endif %}
{%- if media.exif %}
@ -72,7 +72,7 @@
{% endif %}
{%- endmacro %}
<div id="gallery">
{% for media in medias %}
{% for media in album.medias %}
{% if media.type == "image" %}
<a href="{{ media.filename }}">
<img src="{{ media.thumbnail }}" alt="{{ media.filename }}"
@ -92,18 +92,18 @@
</div>
{% endif %}
{% if zip %}
{% if album.zip %}
<div id="additionnal-infos" class="row">
<p>
<a href="{{ zip }}"
<a href="{{ album.zip }}"
title="Download a zip archive with all images">Download ZIP</a>
</p>
</div>
{% endif %}
{% if description %}
{% if album.description %}
<div id="description">
{{ description }}
{{ album.description }}
</div>
{% endif %}
</div>
@ -114,7 +114,7 @@
</footer>
</div>
{% if medias %}
{% if album.medias %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="{{ theme.url }}/js/jquery-1.8.2.min.js"%3E%3C/script%3E'))</script>
<script src="{{ theme.url }}/js/galleria-1.2.9.min.js"></script>

25
sigal/writer.py

@ -85,20 +85,16 @@ class Writer(object):
self.logger.error('The index.html template was not found.')
sys.exit(1)
self.copy_assets()
def copy_assets(self):
"""Copy the theme files in the output dir."""
# Copy the theme files in the output dir
self.theme_path = os.path.join(self.output_dir, 'static')
copy_tree(os.path.join(self.theme, 'static'), self.theme_path)
def generate_context(self, albums, relpath, album):
def generate_context(self, album):
"""Generate the context dict for the given path."""
self.logger.info("Output album : %s", album.dst_path)
ctx = {
return {
'album': album,
'index_title': self.index_title,
'settings': self.settings,
'sigal_link': sigal_link,
@ -106,18 +102,11 @@ class Writer(object):
'url': os.path.relpath(self.theme_path, album.dst_path)},
}
for attr in ('albums', 'breadcrumb', 'description', 'index_url',
'medias', 'meta', 'zip', 'title'):
ctx[attr] = getattr(album, attr)
return ctx
def write(self, albums, path, album):
def write(self, album):
"""Generate the HTML page and save it."""
ctx = self.generate_context(albums, path, album)
page = self.template.render(**ctx)
page = self.template.render(**self.generate_context(album))
output_file = os.path.join(album.dst_path, album.output_file)
with codecs.open(output_file, 'w', 'utf-8') as f:
f.write(page)

Loading…
Cancel
Save