Class: ImagesGallery::Views::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/images_gallery/views/base.rb

Direct Known Subclasses

ISO, Index, Make, Model

Instance Method Summary collapse

Constructor Details

#initializeBase

Provides context and helpers to the corresponding template

Any variable defined in the context of this class will be accessible from the corresponding ERb template. See ruby-doc.org/stdlib-2.2.2/libdoc/erb/rdoc/ERB.html#method-i-result

Usage:

Do not instanciate this class, define subclasses instead an define their template methods as demonstrated in Views::Index.

Conventionally, templates could be stored in images_gallery/templates, but there is no obligation to follow the convention.

This class not meant to be instanciated, subclasses do return View instances (kind of).



22
23
24
# File 'lib/images_gallery/views/base.rb', line 22

def initialize
  @template = File.new(template)
end

Instance Method Details

#file_identifier(make, model = nil, iso_value = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/images_gallery/views/base.rb', line 48

def file_identifier(make, model=nil, iso_value=nil)
  if model.nil?
    "#{make.to_filename}"
  elsif iso_value.nil?
    "#{make.to_filename}/#{model.to_filename}"
  else
    "#{make.to_filename}/#{model.to_filename}/#{iso_value.to_filename}"
  end
end


44
45
46
# File 'lib/images_gallery/views/base.rb', line 44

def link_to(depth, make, model=nil, iso_value=nil)
  ('../' * depth) + file_identifier(make, model, iso_value) + '.html'
end


39
40
41
42
# File 'lib/images_gallery/views/base.rb', line 39

def navigation(links)
  template = File.expand_path('../../templates/_navigation.html.erb', __FILE__)
  ERB.new(File.new(template).read).result(binding)
end

#renderObject



30
31
32
# File 'lib/images_gallery/views/base.rb', line 30

def render
  ERB.new(File.new(template).read).result(binding)
end

#templateObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/images_gallery/views/base.rb', line 26

def template
  raise NotImplementedError
end

#thumbnails(images) ⇒ Object



34
35
36
37
# File 'lib/images_gallery/views/base.rb', line 34

def thumbnails(images)
  template = File.expand_path('../../templates/_thumbnails.html.erb', __FILE__)
  ERB.new(File.new(template).read).result(binding)
end