forked from zroger/jekyll-minimagick
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc31553
Showing
7 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pkg/* | ||
*.gem | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in jekyll-minimagick.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
jekyll-minimagick (0.0.1) | ||
jekyll (>= 0.10.0) | ||
mini_magick (>= 3.3) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
classifier (1.3.3) | ||
fast-stemmer (>= 1.0.0) | ||
directory_watcher (1.4.0) | ||
fast-stemmer (1.0.0) | ||
jekyll (0.10.0) | ||
classifier (>= 1.3.1) | ||
directory_watcher (>= 1.1.1) | ||
liquid (>= 1.9.0) | ||
maruku (>= 0.5.9) | ||
liquid (2.2.2) | ||
maruku (0.6.0) | ||
syntax (>= 1.0.0) | ||
mini_magick (3.3) | ||
subexec (~> 0.1.0) | ||
subexec (0.1.0) | ||
syntax (1.0.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
jekyll (>= 0.10.0) | ||
jekyll-minimagick! | ||
mini_magick (>= 3.3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "jekyll-minimagick/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "jekyll-minimagick" | ||
s.version = Jekyll::Minimagick::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Roger López"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/zroger/jekyll-minimagick" | ||
s.summary = %q{MiniMagick integration for Jekyll} | ||
s.description = %q{Use MiniMagick to crop and resize images in your Jekyll project.} | ||
|
||
s.rubyforge_project = "jekyll-minimagick" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
s.add_runtime_dependency('jekyll', [">= 0.10.0"]) | ||
s.add_runtime_dependency('mini_magick', [">= 3.3"]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'mini_magick' | ||
|
||
module Jekyll | ||
module JekyllMinimagick | ||
|
||
class GeneratedImageFile < Jekyll::StaticFile | ||
# Initialize a new GeneratedImage. | ||
# +site+ is the Site | ||
# +base+ is the String path to the <source> | ||
# +dir+ is the String path between <source> and the file | ||
# +name+ is the String filename of the file | ||
# +preset+ is the Preset hash from the config. | ||
# | ||
# Returns <GeneratedImageFile> | ||
def initialize(site, base, dir, name, preset) | ||
@site = site | ||
@base = base | ||
@dir = dir | ||
@name = name | ||
@preset = preset | ||
end | ||
|
||
# Obtains source file path by substituting the preset's source directory | ||
# for the destination directory. | ||
# | ||
# Returns source file path. | ||
def path | ||
File.join(@base, @dir.sub(@preset['destination'], @preset['source']), @name) | ||
end | ||
|
||
# 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). | ||
def write(dest) | ||
dest_path = destination(dest) | ||
|
||
return false if File.exist? dest_path and !modified? | ||
@@mtimes[path] = mtime | ||
|
||
FileUtils.mkdir_p(File.dirname(dest_path)) | ||
image = ::MiniMagick::Image.open(path) | ||
image.resize @preset['resize'] | ||
image.write dest_path | ||
|
||
true | ||
end | ||
|
||
end | ||
|
||
class MiniMagickGenerator < Generator | ||
safe true | ||
|
||
# Find all image files in the source directories of the presets specified | ||
# in the site config. Add a GeneratedImageFile to the static_files stack | ||
# for later processing. | ||
def generate(site) | ||
return unless site.config['mini_magick'] | ||
|
||
site.config['mini_magick'].each_pair do |name, preset| | ||
Dir.glob(File.join(preset['source'], "*.{png,jpg,jpeg,gif}")) do |source| | ||
site.static_files << GeneratedImageFile.new(site, site.source, preset['destination'], File.basename(source), preset) | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Jekyll | ||
module Minimagick | ||
VERSION = "0.0.1" | ||
end | ||
end |