Class: Jekyll::JekyllMinimagick::GeneratedImageFile
- Inherits:
-
StaticFile
- Object
- StaticFile
- Jekyll::JekyllMinimagick::GeneratedImageFile
- Defined in:
- lib/jekyll-minimagick.rb
Instance Method Summary collapse
-
#initialize(site, base, dir, name, preset) ⇒ GeneratedImageFile
constructor
Initialize a new GeneratedImage.
-
#path ⇒ Object
Obtains source file path by substituting the preset's source directory for the destination directory.
-
#write(dest) ⇒ Object
Use MiniMagick to create a derivative image at the destination specified (if the original is modified).
Constructor Details
#initialize(site, base, dir, name, preset) ⇒ GeneratedImageFile
Initialize a new GeneratedImage.
site is the Site
base is the String path to the dir is the String path between name is the String filename of the file
preset is the Preset hash from the config.
Returns
15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll-minimagick.rb', line 15 def initialize(site, base, dir, name, preset) @site = site @base = base @dir = dir @name = name @dst_dir = preset.delete('destination') @src_dir = preset.delete('source') @commands = preset end |
Instance Method Details
#path ⇒ Object
Obtains source file path by substituting the preset's source directory for the destination directory.
Returns source file path.
29 30 31 |
# File 'lib/jekyll-minimagick.rb', line 29 def path File.join(@base, @dir.sub(@dst_dir, @src_dir), @name) end |
#write(dest) ⇒ Object
Use MiniMagick to create a derivative image at the destination
specified (if the original is modified).
dest is the String path to the destination dir
Returns false if the file was not modified since last time (no-op).
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll-minimagick.rb', line 38 def write(dest) dest_path = destination(dest) return false if File.exist? dest_path and !modified? self.class.mtimes[path] = mtime FileUtils.mkdir_p(File.dirname(dest_path)) image = ::MiniMagick::Image.open(path) @commands.each_pair do |command, arg| image.send command, arg end image.write dest_path true end |