lib/jekyll-minifier.rb in jekyll-minifier-0.1.5 vs lib/jekyll-minifier.rb in jekyll-minifier-0.1.6
- old
+ new
@@ -9,10 +9,29 @@
File.open(dest, 'w') do |f|
f.write(content)
end
end
+ def output_compressed(path, context)
+ case File.extname(path)
+ when '.js'
+ if path.end_with?('.min.js')
+ output_file(path, context)
+ else
+ output_js(path, context)
+ end
+ when '.css'
+ if path.end_with?('.min.css')
+ output_file(path, context)
+ else
+ output_css(path, context)
+ end
+ else
+ output_html(path, context)
+ end
+ end
+
def output_html(path, content)
args = { remove_comments: true, compress_css: true, compress_javascript: true, preserve_patterns: [] }
args[:css_compressor] = CSSminify2.new
args[:javascript_compressor] = Uglifier.new
@@ -76,11 +95,11 @@
def write(dest)
dest_path = destination(dest)
if exclude?(dest, dest_path)
output_file(dest_path, output)
else
- output_html(dest_path, output)
+ output_compressed(dest_path, output)
end
trigger_hooks(:post_write)
end
end
@@ -90,11 +109,11 @@
def write(dest)
dest_path = destination(dest)
if exclude?(dest, dest_path)
output_file(dest_path, output)
else
- output_html(dest_path, output)
+ output_compressed(dest_path, output)
end
Jekyll::Hooks.trigger hook_owner, :post_write, self
end
end
@@ -115,16 +134,16 @@
if exclude?(dest, dest_path)
copy_file(path, dest_path)
else
case File.extname(dest_path)
when '.js'
- if dest_path =~ /.min.js$/
+ if dest_path.end_with?('.min.js')
copy_file(path, dest_path)
else
output_js(dest_path, File.read(path))
end
when '.css'
- if dest_path =~ /.min.css$/
+ if dest_path.end_with?('.min.css')
copy_file(path, dest_path)
else
output_css(dest_path, File.read(path))
end
when '.xml'