New Liquid tag for doing simple image galleries. #295

wants to merge 56 commits into


None yet

6 participants

ghost commented Mar 4, 2011

Here's a basic usage:

 {% gallery name:your_gallery_name %}
 <img src="{{ file.path }}" />
 {% endgallery %}

If you want to arrange the images into a grid, you can do this:

 {% gallery name:your_gallery_name %}
 <td><img src="{{ file.path }}" alt="{{ file.title }}"/>
 <p>Taken on {{ | date: "%F" }}</p></td>
 {% cycle '', '', '', '</tr><tr>' %}
 {% endgallery %}

It provides this data to the templates:

file.url        # absolute path to file
file.path       # relative path to file
file.htmlurl    # absolute path to html file
file.htmlpath   # relative path to html file       # File.basename(filename)       # date extracted from beginning of filename, if present (optional)
file.slug       # basename with the date and file extension stripped off
file.title      # file.slug with hyphens converted to spaces, and put into Title Case

As well as the familiar forloop variable.

Also, none of my code is actually specific to image files. This plugin could easily be used to glob anything out of the filesystem, including a list of available downloads:

 {% gallery name:downloads_page dir:downloads format:tar.gz reverse:no %}
 <li><a href="{{ file.path }}">{{ file.title }}</a></li>
 {% endgallery %}

The above example assumes that it's located inside /downloads_page/index.html and that your .tar.gz files are in /downloads_page/downloads/*.tar.gz. I've added some input checking that prevents the user passing in any periods or slashes to prevent them being able to glob outside of the jekyll directory.

heuripedes and others added some commits Dec 15, 2010
@heuripedes heuripedes updated/fixed migration script 9e0eb75
@MattHall @MattHall MattHall Adding Posterous Importer c1f0e07
@MattHall @MattHall MattHall Updating CLI for importing 84c1a72
Aaron Beckerman fix typo in history: site.ports -> site.posts 033333f
Ben Chatelain Add Jekyll::WordPress.TABLE_PREFIX and inclusion in QUERY 42f63f9
Ben Chatelain Change TABLE_PREFIX back to default e902bb9
Ben Chatelain Change TABLE_PREFIX from class member to 4th parameter of process met…
…hod (now lowercase)

Move QUERY into process method
Ben Chatelain Fix compile error by making QUERY lowercase (local instead of const) d61c1e9
@elia elia The migrator now works and gathers categories as tags. f68bbcb
@elia elia Merged migrator fix from 'heuripedes/jekyll' ca48ea9
@elia elia Take permalink name directly from worpress export file. c70dac3
@elia elia Remove double directory creation. 034b064
@zenspider zenspider Cleaned up unnecessary string munging bd01e64
Robert Bruce Park Added liquid tag for doing simple image galleries. 787bb67
Robert Bruce Park Allow formats other than just ".jpg", and provide 'title' to the temp…

'title' is just the image filename with the extension removed, hyphens and underscores converted to spaces, and the remaining words converted to Title Case.
Robert Bruce Park Less regex for better readability. 3cab419
Robert Bruce Park Add option to let the user reverse the sort. b18ccdd
Robert Bruce Park Simplify Title Casing by adding a method to String class. 69597bf
Robert Bruce Park Provide more data (including dates) to the templates. 8e8497f
Robert Bruce Park Do some input sanity checking. f996dbe
Robert Bruce Park Better input sanitation.
Should be pretty solid now. Nothing nasty is going to make it from user-supplied template data into the glob method now.
Robert Bruce Park Simplify titleize. eeb18e4
Robert Bruce Park Underscores too! D'oh! d07a9df
@tmm1 tmm1 Gemfile to help install the dependencies a04c270
@tmm1 tmm1 fix "4.2.1" versioned dev dependencies, and cleanup syntax 16ea326
@tmm1 tmm1 use the new albino gem 08725eb
@tmm1 tmm1 open4 is not required 4b5a4e8
@tmm1 tmm1 work around cucumber issue (closes #296) 8cc7f06
@tmm1 tmm1 rdiscount is a dev dependency 9da714d
@tmm1 tmm1 make kramdown a runtime dep so people can use it instead of maruku edef025
@tmm1 tmm1 speed up cleanup be8b771
@tmm1 tmm1 sanitize urls and ignore symlinks 13cc44f
@mojombo mojombo Update history. f82c51d
@mojombo mojombo Merge remote-tracking branch 'zenspider/master' into devel 5f4dfe3
@mojombo mojombo Move require to jekyll.rb and update history. a31780a
@mojombo mojombo Merge remote-tracking branch 'ab9/master' into devel 38844cd
@mojombo mojombo Merge remote-tracking branch 'MattHall/posterous' into devel f58a821
@mojombo mojombo Merge remote-tracking branch 'elia/master' into devel d2814cf
@mojombo mojombo Merge remote-tracking branch 'phatblat/master' into test 01a9090
@mojombo mojombo Merge remote-tracking branch 'MattHall/cli' into test 68eaadd
@mojombo mojombo TomDoc convertible.rb. 6c94db1
mojombo commented Mar 12, 2011

This looks really nice. Could you hook up a few test cases and cucumber features for it?

ghost commented Mar 12, 2011

This isn't the first time I've ever written a test case, but it's the first time I've written one in Ruby (all my previous experience is in python), and i've never used Cucumber before. Please let me know if these are satisfactory.


Robert Bruce... added some commits Mar 12, 2011
Robert Bruce Park More consistent absolute/relative path generation, and better cucumbe…
…r test of this.
Robert Bruce Park Provide contents of YAML front matter of iterated files to parent tem…

As per discussion at #299

Since images contain no YAML, this is harmlessly ignored by image files, but does make the plugin more useful to people using gallery for lists of files other than images.
Robert Bruce Park Add Cucumber Scenario for new ability to read YAML from globbed files. d96f226
Robert Bruce Park Make name attribute default to '.' if left unspecified.
This allows /index.html to contain a gallery of files at the top level instead of forcing everything to be one subdirectory below the sourcedir.
@ghost Unknown commented on the diff Mar 13, 2011
+module Jekyll
+ class GalleryTag < Liquid::Block
+ include Convertible
+ attr_accessor :content, :data
+ def initialize(tag_name, markup, tokens)
+ attributes = {}
+ # Parse parameters
+ markup.scan(Liquid::TagAttributes) do |key, value|
+ attributes[key] = value
+ end
+ @name = attributes['name'] || '.'
ghost Mar 13, 2011

i've changed this so that if name is not specified, it defaults to a period, which is equivalent to saying "look in the root of the sourcedir for the gallery files". This is slightly nicer than it was before, but I'm still looking for a way to say "the gallery should be located in the same directory as the file that contained {% gallery %}."

Any thoughts on this, Tom?

Robert Bruce... added some commits Mar 13, 2011
Robert Bruce Park Change cucumber feature to show the simplest possible use case of gal…
…lery tag.
Robert Bruce Park Code style cleanup.
Moved the String.titleize method definition into core_ext.rb. Also deleted the copious usage documentation comments because a) it was a bit out of date and b) that belongs on the wiki anyway.
Robert Bruce Park Add file.htmlpath to make it easier to link to htmlized files. 16d8590
Robert Bruce Park Add file.htmlurl to compliment file.htmlpath 2b03d21
Robert Bruce Park Create gallery.feature, moving the three existing Cucumber Scenarios …
…there, and add two more.
Robert Bruce Park Minor expansion of YAML use in Cucumber test. 592e4f6
Robert Bruce Park Merge remote-tracking branch 'mojombo/devel' 227fc4f
Robert Bruce Park Merge branch 'master' of 967106a
ghost commented Mar 18, 2011

Hmmm, I seem to have made a mess of things by merging. Should I start over with a new fork and a new pull request, or is this ok as is? Sorry, github newbie ;-)

ghost commented Mar 19, 2011

Yeah, starting this one over. Derp de derp derp...

@ghost ghost closed this Mar 19, 2011
@parkr parkr referenced this pull request Sep 15, 2014

List files in directory #2927

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment