Class: Alula::Compressors::HTMLCompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/alula/compressors.rb

Instance Method Summary collapse

Constructor Details

#initializeHTMLCompressor

Returns a new instance of HTMLCompressor.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/alula/compressors.rb', line 51

def initialize
  # HtmlCompressor::Compressor.send(:include, HTMLCompressorExt)
  @compressor = HtmlCompressor::Compressor.new
  #   remove_surrounding_spaces: HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script",
  #   remove_intertag_spaces: true,
  #   remove_quotes: true,
  #   remove_script_attributes: true,
  #   remove_style_attributes: true,
  #   remove_link_attributes: true,
  #   simple_boolean_attributes: true,
  #   remove_http_protocol: false,
  #   remove_https_protocol: false,
  # })
  @compressor.profile = :high
end

Instance Method Details

#compress(item, content) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/alula/compressors.rb', line 73

def compress(item, content)
  _old_profile = @compressor.profile
  unless item.generator.nil?
    @compressor.profile = item.generator.allow_compressing?
  end

  @compressor.compress(content)
ensure
  @compressor.profile = _old_profile
end

#compresses?(item) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/alula/compressors.rb', line 67

def compresses?(item)
  return true if item.generator.nil?
  
  return item.generator.allow_compressing? != :none
end