From 7acb2aa1c4138d5a04a8ed786a9bedec68e91d1c Mon Sep 17 00:00:00 2001 From: Romain Date: Fri, 8 Dec 2017 00:09:17 +1100 Subject: [PATCH] WIP exif summary panel --- src/website/helpers/join.js | 15 +++++++ src/website/template.js | 1 + templates/exif.hbs | 72 ++++++++++++++++++++++++++++++ templates/themes/classic/theme.hbs | 1 + test/website/helpers/join.spec.js | 29 ++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 src/website/helpers/join.js create mode 100644 templates/exif.hbs create mode 100644 test/website/helpers/join.spec.js diff --git a/src/website/helpers/join.js b/src/website/helpers/join.js new file mode 100644 index 0000000..daee205 --- /dev/null +++ b/src/website/helpers/join.js @@ -0,0 +1,15 @@ +/* + Render elements of an array joined by a separator + Usage: + {{#join list ","}} + {{.}} + {{/join}} +*/ +module.exports = function (array, separator, options) { + const data = require('handlebars').createFrame({}) + const blocks = array.map((item, index) => { + data.index = index + return options.fn(item, {data: data}) + }) + return blocks.join(separator) +} diff --git a/src/website/template.js b/src/website/template.js index 7c60069..9073088 100644 --- a/src/website/template.js +++ b/src/website/template.js @@ -27,6 +27,7 @@ exports.create = function (options) { // common partials handlebars.registerPartial('analytics', compileTemplate(path.join(DIR_TEMPLATES, 'analytics.hbs'))) handlebars.registerPartial('thumbnail', compileTemplate(path.join(DIR_TEMPLATES, 'thumbnail.hbs'))) + handlebars.registerPartial('exif', compileTemplate(path.join(DIR_TEMPLATES, 'exif.hbs'))) // theme partials const partials = fs.readdirSync(DIR_THEME) diff --git a/templates/exif.hbs b/templates/exif.hbs new file mode 100644 index 0000000..bc8affa --- /dev/null +++ b/templates/exif.hbs @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Filename{{ filename }}
Date taken{{date date "DD MMM YYYY"}}
Resolution{{ width }} x {{ height }}
Camera{{ make }}
Model{{ model }}
ISO{{ iso }}
Aperture{{ aperture }}
Exposure{{ exposure }}
Flash{{ flash }}
GPS{{ lat }}, {{ long }}
Title{{ caption }}
Description{{ description }}
Keywords{{#join keywords ","}}{{.}}{{/join}}
Rating{{#times rating}}{{/times}}
diff --git a/templates/themes/classic/theme.hbs b/templates/themes/classic/theme.hbs index 509a174..122d961 100644 --- a/templates/themes/classic/theme.hbs +++ b/templates/themes/classic/theme.hbs @@ -39,6 +39,7 @@ diff --git a/test/website/helpers/join.spec.js b/test/website/helpers/join.spec.js new file mode 100644 index 0000000..5969709 --- /dev/null +++ b/test/website/helpers/join.spec.js @@ -0,0 +1,29 @@ +const handlebars = require('handlebars') +const should = require('should/as-function') +const join = require('../../../src/website/helpers/join') + +describe('Handlebars helpers: join', () => { + handlebars.registerHelper('join', join) + + it('joins items with the separator', () => { + const template = handlebars.compile(`{{#join list ","}}{{.}}{{/join}}`) + const res = template({list: [1, 2, 3]}) + should(res).eql('1,2,3') + }) + + it('renders the child block for each item', () => { + const template = handlebars.compile(`{{#join list ","}}{{value}}{{/join}}`) + const res = template({list: [ + { value: 1 }, + { value: 2 }, + { value: 3 } + ]}) + should(res).eql('1,2,3') + }) + + it('passes the @index to the block', () => { + const template = handlebars.compile(`{{#join list ","}}{{@index}}{{/join}}`) + const res = template({list: [1, 2, 3]}) + should(res).eql('0,1,2') + }) +})