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

Instance Method Details

#libraryObject



8
9
10
# File 'lib/gallerist/helpers.rb', line 8

def library
  settings.library
end


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


43
44
45
# File 'lib/gallerist/helpers.rb', line 43

def navbar
  @navbar
end

#partial(partial, *options) ⇒ Object



47
48
49
# File 'lib/gallerist/helpers.rb', line 47

def partial(partial, *options)
  erb :"partials/#{partial}", *options
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

#titleObject



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