lib/jekyll-minifier.rb in jekyll-minifier-0.1.6 vs lib/jekyll-minifier.rb in jekyll-minifier-0.1.8
- old
+ new
@@ -29,53 +29,99 @@
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
+ if ( ENV['JEKYLL_ENV'] == "production" )
+ html_args = { remove_comments: true, compress_css: true, compress_javascript: true, preserve_patterns: [] }
+ js_args = {}
- opts = @site.config['jekyll-minifier']
+ opts = @site.config['jekyll-minifier']
+ if ( !opts.nil? )
+ # Javascript Arguments
+ js_args += opts[:uglifier_args] if opts.has_key?(:uglifier_args)
+
+ # HTML Arguments
+ html_args[:remove_spaces_inside_tags] = opts['remove_spaces_inside_tags'] if opts.has_key?('remove_spaces_inside_tags')
+ html_args[:remove_multi_spaces] = opts['remove_multi_spaces'] if opts.has_key?('remove_multi_spaces')
+ html_args[:remove_comments] = opts['remove_comments'] if opts.has_key?('remove_comments')
+ html_args[:remove_intertag_spaces] = opts['remove_intertag_spaces'] if opts.has_key?('remove_intertag_spaces')
+ html_args[:remove_quotes] = opts['remove_quotes'] if opts.has_key?('remove_quotes')
+ html_args[:compress_css] = opts['compress_css'] if opts.has_key?('compress_css')
+ html_args[:compress_javascript] = opts['compress_javascript'] if opts.has_key?('compress_javascript')
+ html_args[:simple_doctype] = opts['simple_doctype'] if opts.has_key?('simple_doctype')
+ html_args[:remove_script_attributes] = opts['remove_script_attributes'] if opts.has_key?('remove_script_attributes')
+ html_args[:remove_style_attributes] = opts['remove_style_attributes'] if opts.has_key?('remove_style_attributes')
+ html_args[:remove_link_attributes] = opts['remove_link_attributes'] if opts.has_key?('remove_link_attributes')
+ html_args[:remove_form_attributes] = opts['remove_form_attributes'] if opts.has_key?('remove_form_attributes')
+ html_args[:remove_input_attributes] = opts['remove_input_attributes'] if opts.has_key?('remove_input_attributes')
+ html_args[:remove_javascript_protocol] = opts['remove_javascript_protocol'] if opts.has_key?('remove_javascript_protocol')
+ html_args[:remove_http_protocol] = opts['remove_http_protocol'] if opts.has_key?('remove_http_protocol')
+ html_args[:remove_https_protocol] = opts['remove_https_protocol'] if opts.has_key?('remove_https_protocol')
+ html_args[:preserve_line_breaks] = opts['preserve_line_breaks'] if opts.has_key?('preserve_line_breaks')
+ html_args[:simple_boolean_attributes] = opts['simple_boolean_attributes'] if opts.has_key?('simple_boolean_attributes')
+ html_args[:compress_js_templates] = opts['compress_js_templates'] if opts.has_key?('compress_js_templates')
+ html_args[:preserve_patterns] += [/<\?php.*?\?>/im] if opts['preserve_php'] == true
+ html_args[:preserve_patterns] += opts[:preserve_patterns].map { |pattern| Regexp.new(pattern)} if opts.has_key?(:preserve_patterns)
+ end
+
+ html_args[:css_compressor] = CSSminify2.new()
- if ( !opts.nil? )
- args[:remove_spaces_inside_tags] = opts['remove_spaces_inside_tags'] if opts.has_key?('remove_spaces_inside_tags')
- args[:remove_multi_spaces] = opts['remove_multi_spaces'] if opts.has_key?('remove_multi_spaces')
- args[:remove_comments] = opts['remove_comments'] if opts.has_key?('remove_comments')
- args[:remove_intertag_spaces] = opts['remove_intertag_spaces'] if opts.has_key?('remove_intertag_spaces')
- args[:remove_quotes] = opts['remove_quotes'] if opts.has_key?('remove_quotes')
- args[:compress_css] = opts['compress_css'] if opts.has_key?('compress_css')
- args[:compress_javascript] = opts['compress_javascript'] if opts.has_key?('compress_javascript')
- args[:simple_doctype] = opts['simple_doctype'] if opts.has_key?('simple_doctype')
- args[:remove_script_attributes] = opts['remove_script_attributes'] if opts.has_key?('remove_script_attributes')
- args[:remove_style_attributes] = opts['remove_style_attributes'] if opts.has_key?('remove_style_attributes')
- args[:remove_link_attributes] = opts['remove_link_attributes'] if opts.has_key?('remove_link_attributes')
- args[:remove_form_attributes] = opts['remove_form_attributes'] if opts.has_key?('remove_form_attributes')
- args[:remove_input_attributes] = opts['remove_input_attributes'] if opts.has_key?('remove_input_attributes')
- args[:remove_javascript_protocol] = opts['remove_javascript_protocol'] if opts.has_key?('remove_javascript_protocol')
- args[:remove_http_protocol] = opts['remove_http_protocol'] if opts.has_key?('remove_http_protocol')
- args[:remove_https_protocol] = opts['remove_https_protocol'] if opts.has_key?('remove_https_protocol')
- args[:preserve_line_breaks] = opts['preserve_line_breaks'] if opts.has_key?('preserve_line_breaks')
- args[:simple_boolean_attributes] = opts['simple_boolean_attributes'] if opts.has_key?('simple_boolean_attributes')
- args[:compress_js_templates] = opts['compress_js_templates'] if opts.has_key?('compress_js_templates')
- args[:preserve_patterns] += [/<\?php.*?\?>/im] if opts['preserve_php'] == true
+ if ( !js_args.nil? )
+ html_args[:javascript_compressor] = Uglifier.new(js_args)
+ else
+ html_args[:javascript_compressor] = Uglifier.new()
+ end
- # Potential to add patterns from YAML
- #args[:preserve_patterns] += opts[:preserve_patterns].map { |pattern| Regexp.new(pattern)} if opts.has_key?(:preserve_patterns)
+ compressor = HtmlCompressor::Compressor.new(html_args)
+ output_file(path, compressor.compress(content))
+ else
+ output_file(path, content)
end
-
- compressor = HtmlCompressor::Compressor.new(args)
- output_file(path, compressor.compress(content))
end
def output_js(path, content)
- compressed = Uglifier.new
- output_file(path, compressed.compile(content))
+ if ( ENV['JEKYLL_ENV'] == "production" )
+ opts = @site.config['jekyll-minifier']
+ compress = true
+ if ( !opts.nil? )
+ compress = opts['compress_javascript'] if opts.has_key?('compress_javascript')
+ js_args += opts[:js_args] if opts.has_key?(:js_args)
+ end
+
+ if ( compress )
+ if ( !js_args.nil? )
+ compressor = Uglifier.new(js_args)
+ else
+ compressor = Uglifier.new()
+ end
+
+ output_file(path, compressed.compile(content))
+ else
+ output_file(path, content)
+ end
+ else
+ output_file(path, content)
+ end
end
def output_css(path, content)
- compressor = CSSminify2.new
- output_file(path, compressor.compress(content))
+ if ( ENV['JEKYLL_ENV'] == "production" )
+ opts = @site.config['jekyll-minifier']
+ compress = true
+ if ( !opts.nil? )
+ compress = opts['compress_css'] if opts.has_key?('compress_css')
+ end
+ if ( compress )
+ compressor = CSSminify2.new()
+ output_file(path, compressor.compress(content))
+ else
+ output_file(path, content)
+ end
+ else
+ output_file(path, content)
+ end
+
end
private
def exclude?(dest, dest_path)