Permalink
Browse files

fix for #3

  • Loading branch information...
1 parent b674340 commit 38c0987eacd6e140622ef9d9501ea25c387ddfbd @stereobooster committed Sep 27, 2012
Showing with 86 additions and 60 deletions.
  1. +2 −0 Gemfile
  2. +2 −2 Readme.md
  3. +82 −58 _plugins/jekyll_press.rb
View
@@ -1,5 +1,7 @@
source :rubygems
+gem "jekyll"
+
gem "html_press"
gem "css_press"
gem "uglifier"
View
@@ -10,8 +10,8 @@ This plugin:
## Usage
- put `jekyll_press.rb` in plugins folder
- add gems to `Gemfile`
- - `bundle`
- - regenerate all content
+ - install gems: `bundle`
+ - regenerate all content: `bundle exec jekyll`
## TODO
- Minify JPEGs with `jpegtran` or `smush.it` ([smusher](https://github.com/grosser/smusher))
View
@@ -1,92 +1,116 @@
-# jekyll_press 0.0.1
+# jekyll_press 0.0.2
# https://github.com/stereobooster/jekyll_press
-require 'html_press'
-require 'css_press'
-require 'uglifier'
-
module Jekyll
module Compressor
+
+ class << self
+ attr_accessor :html, :css, :js
+ def load_gem name
+ begin
+ require name
+ true
+ rescue LoadError
+ warn "Install #{name}: gem install #{name} or place it in Gemfile"
+ false
+ end
+ end
+ end
+
+ self.html = self.load_gem 'html_press'
+ self.css = self.load_gem 'css_press'
+ self.js = self.load_gem 'uglifier'
+
def output_file(dest, content)
FileUtils.mkdir_p(File.dirname(dest))
File.open(dest, 'w') do |f|
f.write(content)
end
end
- def output_html(path, content)
- self.output_file(path, HtmlPress.press(content))
+ if self.html
+ def output_html(path, content)
+ self.output_file(path, HtmlPress.press(content))
+ end
end
- def output_js(path, content)
- self.output_file(path, Uglifier.new.compile(content))
- rescue Uglifier::Error => e
- puts "parse error occurred while processing: #{path}"
- puts "details: #{e.message.strip}"
- puts "copying initial file"
- self.output_file(path, content)
+ if self.js
+ def output_js(path, content)
+ self.output_file(path, Uglifier.new.compile(content))
+ rescue Uglifier::Error => e
+ warn "parse error occurred while processing: #{path}"
+ warn "details: #{e.message.strip}"
+ warn "copying initial file"
+ self.output_file(path, content)
+ end
end
- def output_css(path, content)
- self.output_file(path, CssPress.press(content))
- rescue Racc::ParseError => e
- puts "parse error occurred while processing: #{path}"
- puts "details: #{e.message.strip}"
- puts "copying initial file"
- self.output_file(path, content)
+ if self.css
+ def output_css(path, content)
+ self.output_file(path, CssPress.press(content))
+ rescue Racc::ParseError => e
+ warn "parse error occurred while processing: #{path}"
+ warn "details: #{e.message.strip}"
+ warn "copying initial file"
+ self.output_file(path, content)
+ end
end
end
- class Post
- include Compressor
+ if Compressor.html
+ class Post
+ include Compressor
- def write(dest)
- dest_path = self.destination(dest)
- self.output_html(dest_path, self.output)
+ def write(dest)
+ dest_path = self.destination(dest)
+ self.output_html(dest_path, self.output)
+ end
end
- end
- class Page
- include Compressor
+ class Page
+ include Compressor
- def write(dest)
- dest_path = self.destination(dest)
- self.output_html(dest_path, self.output)
+ def write(dest)
+ dest_path = self.destination(dest)
+ self.output_html(dest_path, self.output)
+ end
end
end
- class StaticFile
- include Compressor
-
- def copy_file(path, dest_path)
- FileUtils.mkdir_p(File.dirname(dest_path))
- FileUtils.cp(path, dest_path)
- end
+ if Compressor.css || Compressor.js
+ class StaticFile
+ include Compressor
+
+ def copy_file(path, dest_path)
+ FileUtils.mkdir_p(File.dirname(dest_path))
+ FileUtils.cp(path, dest_path)
+ end
- def write(dest)
- dest_path = self.destination(dest)
+ def write(dest)
+ dest_path = self.destination(dest)
- return false if File.exist?(dest_path) and !self.modified?
- @@mtimes[path] = mtime
+ return false if File.exist?(dest_path) and !self.modified?
+ @@mtimes[path] = mtime
- case File.extname(dest_path)
- when '.js'
- if dest_path =~ /.min.js$/
- copy_file(path, dest_path)
+ case File.extname(dest_path)
+ when '.js'
+ if !Compressor.js || dest_path =~ /.min.js$/
+ copy_file(path, dest_path)
+ else
+ self.output_js(dest_path, File.read(path))
+ end
+ when '.css'
+ if !Compressor.css || dest_path =~ /.min.css$/
+ copy_file(path, dest_path)
+ else
+ self.output_css(dest_path, File.read(path))
+ end
else
- self.output_js(dest_path, File.read(path))
- end
- when '.css'
- if dest_path =~ /.min.css$/
copy_file(path, dest_path)
- else
- self.output_css(dest_path, File.read(path))
- end
- else
- copy_file(path, dest_path)
- end
+ end
- true
+ true
+ end
end
end
end

0 comments on commit 38c0987

Please sign in to comment.