mirror of https://github.com/thumbsup/thumbsup
Compare commits
3 Commits
6535caab7d
...
9def14a641
Author | SHA1 | Date |
---|---|---|
Romain | 9def14a641 | 5 months ago |
Romain | 4ffba3b276 | 5 months ago |
Romain | 6871f6edd2 | 5 months ago |
@ -1,59 +1,105 @@
|
||||
const date = require('../../../src/website/theme-base/helpers/relative')
|
||||
const relative = require('../../../src/website/theme-base/helpers/relative')
|
||||
const handlebars = require('handlebars')
|
||||
const should = require('should/as-function')
|
||||
|
||||
describe('Handlebars helpers: relative', () => {
|
||||
handlebars.registerHelper('relative', date)
|
||||
handlebars.registerHelper('relative', relative)
|
||||
|
||||
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'
|
||||
}
|
||||
describe('theme assets', () => {
|
||||
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" />')
|
||||
})
|
||||
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'
|
||||
}
|
||||
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" />')
|
||||
})
|
||||
should(res).eql('<link rel="stylesheet" href="../public/theme.css" />')
|
||||
})
|
||||
|
||||
it('does not do anything if the path is an absolute URL', () => {
|
||||
// This can happen when using --link-prefix
|
||||
const url = 'http://example.com/photo.jpg'
|
||||
const template = handlebars.compile(`<img src="{{relative '${url}'}}" />`)
|
||||
const res = template({})
|
||||
should(res).eql(`<img src="${url}" />`)
|
||||
})
|
||||
describe('images and videos', () => {
|
||||
it('returns a path from the root album', () => {
|
||||
const template = handlebars.compile('<img src="{{relative \'media/thumbs/img.jpg\'}}" />')
|
||||
const res = template({
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<img src="media/thumbs/img.jpg" />')
|
||||
})
|
||||
|
||||
// TODO: this should not be needed anymore because all URLs are already escaped
|
||||
it('escapes single quotes so they can be used in CSS background-image', () => {
|
||||
const template = handlebars.compile("background-image('{{relative url}}')")
|
||||
const res = template({
|
||||
url: "l'histoire.jpg",
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
it('returns a path from a nested album', () => {
|
||||
const template = handlebars.compile('<img src="{{relative \'media/thumbs/img.jpg\'}}" />')
|
||||
const res = template({
|
||||
album: {
|
||||
path: 'albums/holidays.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<img src="../media/thumbs/img.jpg" />')
|
||||
})
|
||||
|
||||
it('can use a relative link from the root album', () => {
|
||||
const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'../../photos/img.jpg\'}}" />')
|
||||
const res = template({
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<link rel="stylesheet" href="../../photos/img.jpg" />')
|
||||
})
|
||||
|
||||
it('can use relative link from a nested album', () => {
|
||||
const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'../../photos/img.jpg\'}}" />')
|
||||
const res = template({
|
||||
album: {
|
||||
path: 'albums/holidays.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<link rel="stylesheet" href="../../../photos/img.jpg" />')
|
||||
})
|
||||
|
||||
it('does not do anything if the path is an absolute URL', () => {
|
||||
// This can happen when using --link-prefix
|
||||
const url = 'http://example.com/photo.jpg'
|
||||
const template = handlebars.compile(`<img src="{{relative '${url}'}}" />`)
|
||||
const res = template({})
|
||||
should(res).eql(`<img src="${url}" />`)
|
||||
})
|
||||
should(res).eql("background-image('l%27histoire.jpg')")
|
||||
})
|
||||
|
||||
// TODO: this should not be needed anymore because all URLs are already escaped
|
||||
it('escapes double quotes so they can be used in <img> tags', () => {
|
||||
const template = handlebars.compile('<img src="{{relative url}}" />')
|
||||
const res = template({
|
||||
url: 'l"histoire.jpg',
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
describe('escaping', () => {
|
||||
// TODO: this should not be needed anymore because all URLs are already escaped
|
||||
it('escapes single quotes so they can be used in CSS background-image', () => {
|
||||
const template = handlebars.compile("background-image('{{relative url}}')")
|
||||
const res = template({
|
||||
url: "l'histoire.jpg",
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
})
|
||||
should(res).eql("background-image('l%27histoire.jpg')")
|
||||
})
|
||||
|
||||
// TODO: this should not be needed anymore because all URLs are already escaped
|
||||
it('escapes double quotes so they can be used in <img> tags', () => {
|
||||
const template = handlebars.compile('<img src="{{relative url}}" />')
|
||||
const res = template({
|
||||
url: 'l"histoire.jpg',
|
||||
album: {
|
||||
path: 'index.html'
|
||||
}
|
||||
})
|
||||
should(res).eql('<img src="l%22histoire.jpg" />')
|
||||
})
|
||||
should(res).eql('<img src="l%22histoire.jpg" />')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue