Class: ImagesGallery::Views::Base
- Inherits:
-
Object
- Object
- ImagesGallery::Views::Base
- Defined in:
- lib/images_gallery/views/base.rb
Instance Method Summary collapse
- #file_identifier(make, model = nil, iso_value = nil) ⇒ Object
-
#initialize ⇒ Base
constructor
Provides context and helpers to the corresponding template.
- #link_to(depth, make, model = nil, iso_value = nil) ⇒ Object
- #navigation(links) ⇒ Object
- #render ⇒ Object
- #template ⇒ Object
- #thumbnails(images) ⇒ Object
Constructor Details
#initialize ⇒ Base
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 |
#link_to(depth, make, model = nil, iso_value = nil) ⇒ Object
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 |
#navigation(links) ⇒ Object
39 40 41 42 |
# File 'lib/images_gallery/views/base.rb', line 39 def (links) template = File.('../../templates/_navigation.html.erb', __FILE__) ERB.new(File.new(template).read).result(binding) end |
#render ⇒ Object
30 31 32 |
# File 'lib/images_gallery/views/base.rb', line 30 def render ERB.new(File.new(template).read).result(binding) end |
#template ⇒ Object
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.('../../templates/_thumbnails.html.erb', __FILE__) ERB.new(File.new(template).read).result(binding) end |