mirror of https://github.com/thumbsup/thumbsup
refactor(themes): extract the {{relative}} helper to be standalone + add some tests
parent
be0ee25c64
commit
deee049650
@ -0,0 +1,27 @@
|
||||
const date = require('../../../themes/base/helpers/relative')
|
||||
const handlebars = require('handlebars')
|
||||
const should = require('should/as-function')
|
||||
|
||||
describe('Handlebars helpers: relative', () => {
|
||||
handlebars.registerHelper('relative', date)
|
||||
|
||||
it('returns a path in the same folder', () => {
|
||||
const template = handlebars.compile(`<link rel="stylesheet" href="{{relative 'public/theme.css'}}" />`)
|
||||
const res = template({
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<link rel="stylesheet" href="public/theme.css" />')
|
||||
})
|
||||
|
||||
it('returns a relative path for albums in nested folders', () => {
|
||||
const template = handlebars.compile(`<link rel="stylesheet" href="{{relative 'public/theme.css'}}" />`)
|
||||
const res = template({
|
||||
album: {
|
||||
path: 'albums/holidays.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<link rel="stylesheet" href="../public/theme.css" />')
|
||||
})
|
||||
})
|
@ -0,0 +1,6 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = (target, options) => {
|
||||
const albumPath = options.data.root.album.path
|
||||
return path.relative(path.dirname(albumPath), target)
|
||||
}
|
Loading…
Reference in New Issue