Class: CheesyGallery::BaseImageFile

Inherits:
Jekyll::StaticFile
  • Object
show all
Defined in:
lib/cheesy-gallery/base_image_file.rb

Overview

This StaticFile subclass adds additional functionality for images in the gallery

Direct Known Subclasses

ImageFile, ImageThumb

Constant Summary collapse

@@render_cache =

don’t need to worry about inheritance here # rubocop:disable Style/ClassVars

Jekyll::Cache.new('CheesyGallery::Render')

Instance Method Summary collapse

Constructor Details

#initialize(site, collection, file, dest_path = nil) ⇒ BaseImageFile

Returns a new instance of BaseImageFile.



10
11
12
13
# File 'lib/cheesy-gallery/base_image_file.rb', line 10

def initialize(site, collection, file, dest_path = nil)
  @source_file = file
  super(site, site.source, File.dirname(file.relative_path), dest_path || file.name, collection)
end

Instance Method Details

#pathObject

use the source file’s path for this, as this value is used all over the place for mtime checking



17
18
19
# File 'lib/cheesy-gallery/base_image_file.rb', line 17

def path
  @source_file.path
end

#process_and_write(img, path) ⇒ Object

overwrite this method to add additional processing



22
23
24
# File 'lib/cheesy-gallery/base_image_file.rb', line 22

def process_and_write(img, path)
  img.write(path) {}
end

#write(dest) ⇒ Object

Inject cache here to override default delete-before-copy behaviour See jekyll:lib/jekyll/static_file.rb for source



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cheesy-gallery/base_image_file.rb', line 28

def write(dest)
  dest_path = destination(dest)
  return false if File.exist?(dest_path) && !modified?

  self.class.mtimes[path] = mtime

  return if @@render_cache.key?("#{dest_path}-rendered") && File.exist?(dest_path)

  FileUtils.mkdir_p(File.dirname(dest_path))
  FileUtils.rm(dest_path) if File.exist?(dest_path)
  copy_file(dest_path)

  @@render_cache["#{dest_path}-rendered"] = true

  true
end