Skip to content

Commit

Permalink
first working version.
Browse files Browse the repository at this point in the history
  • Loading branch information
zroger committed Jul 8, 2011
0 parents commit cc31553
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg/*
*.gem
.bundle
4 changes: 4 additions & 0 deletions Gemfile
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
34 changes: 34 additions & 0 deletions Gemfile.lock
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)
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
24 changes: 24 additions & 0 deletions jekyll-minimagick.gemspec
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
70 changes: 70 additions & 0 deletions lib/jekyll-minimagick.rb
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
5 changes: 5 additions & 0 deletions lib/jekyll-minimagick/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Jekyll
module Minimagick
VERSION = "0.0.1"
end
end

0 comments on commit cc31553

Please sign in to comment.