Module: Gallerist::Helpers
- Defined in:
- lib/gallerist/helpers.rb
Overview
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
Instance Method Summary collapse
- #library ⇒ Object
- #link_to(obj, classes = nil) ⇒ Object
- #navbar ⇒ Object
- #partial(partial, *options) ⇒ Object
- #route_exists(url) ⇒ Object
- #title ⇒ Object
- #url_for(obj) ⇒ Object
Instance Method Details
#library ⇒ Object
8 9 10 |
# File 'lib/gallerist/helpers.rb', line 8 def library settings.library end |
#link_to(obj, classes = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |
#navbar ⇒ Object
43 44 45 |
# File 'lib/gallerist/helpers.rb', line 43 def @navbar end |
#partial(partial, *options) ⇒ Object
47 48 49 |
# File 'lib/gallerist/helpers.rb', line 47 def partial(partial, *) erb :"partials/#{partial}", * end |
#route_exists(url) ⇒ Object
51 52 53 |
# File 'lib/gallerist/helpers.rb', line 51 def route_exists(url) settings.routes['GET'].map(&:first).any? { |route| route =~ url } end |
#title ⇒ Object
55 56 57 |
# File 'lib/gallerist/helpers.rb', line 55 def title '%s – Gallerist' % [ @title ] end |
#url_for(obj) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |