Add link-to helper with locale support

This commit is contained in:
2015-04-08 12:28:30 +02:00
parent 19a159e8d7
commit 20ebd784fc
@@ -43,3 +43,17 @@ class HtmlEdit
text_field.hide() text_field.hide()
template_field.hide() template_field.hide()
@html_edit = new HtmlEdit() @html_edit = new HtmlEdit()
Handlebars.registerHelper "link-to", (url, args..., options = {})->
unless not url or url.match(/^http|^\/\w{2}\//)
# Starts with http or /:locale/ explicitly
if options.hash and options.hash.hasOwnProperty 'locale'
if locale = options.hash.locale
url = "/#{locale}/#{url}".replace('//', '/')
else if locale = $('#page_locale').val()
url = "/#{locale}/#{url}".replace('//', '/')
if options.fn
text = options.fn(this)
else
text = args[0]
link = "<a href='#{url}'>#{text}</a>"
new Handlebars.SafeString(link)