module Gallerist::Helpers
This code is free software; you can redistribute it and/or modify it under the terms of the new BSD License.
Copyright © 2015, Sebastian Staudt
Public Instance Methods
library()
click to toggle source
# File lib/gallerist/helpers.rb, line 8 def library settings.library end
link_to(obj, classes = nil)
click to toggle source
# File lib/gallerist/helpers.rb, line 12 def link_to(obj, classes = nil) url = url_for obj current = (url == request.path) classes = [ classes ].compact case obj when Gallerist::Album link = obj.name when Gallerist::Person classes << 'label' << 'tag' classes << (current ? 'label-info' : 'label-primary') link = obj.name when Gallerist::Photo classes << 'thumbnail' link = '<img src="/thumbs/%s">' % [ obj.id ] when Gallerist::Tag classes << 'label' << 'tag' classes << (current ? 'label-info' : 'label-primary') link = obj.name end classes = classes.empty? ? '' : ' class="%s"' % [ classes.join(' ') ] if current '<span%s>%s</span>' % [ classes, link ] else '<a href="%s"%s>%s</a>' % [ url_for(obj), classes, link ] end end
partial(partial, *options)
click to toggle source
# File lib/gallerist/helpers.rb, line 47 def partial(partial, *options) erb :"partials/#{partial}", *options end
route_exists(url)
click to toggle source
# File lib/gallerist/helpers.rb, line 51 def route_exists(url) settings.routes['GET'].map(&:first).any? { |route| route =~ url } end
title()
click to toggle source
# File lib/gallerist/helpers.rb, line 55 def title '%s – Gallerist' % [ @title ] end
url_for(obj)
click to toggle source
# File lib/gallerist/helpers.rb, line 59 def url_for(obj) case obj when Gallerist::Album '/albums/%s' % [ obj.id ] when Gallerist::Person '/persons/%s' % [ obj.id ] when Gallerist::Photo '/photos/%s' % [ obj.id ] when Gallerist::Tag '/tags/%s' % [ URI.encode(obj.simple_name) ] end end