Class: WebResourceBundler::Filters::ImageEncodeFilter::Filter

Inherits:
BaseFilter
  • Object
show all
Defined in:
lib/web_resource_bundler/filters/image_encode_filter.rb

Constant Summary collapse

FILE_PREFIX =
'base64_'
IE_FILE_PREFIX =
'base64_ie_'
MHTML_FILE_PREFIX =
'mhtml_'

Instance Attribute Summary

Attributes inherited from BaseFilter

#settings

Instance Method Summary collapse

Constructor Details

#initialize(settings, file_manager) ⇒ Filter

Returns a new instance of Filter.



13
14
15
16
# File 'lib/web_resource_bundler/filters/image_encode_filter.rb', line 13

def initialize(settings, file_manager)
  super settings, file_manager
  @generator = CssGenerator.new(@settings, @file_manager)
end

Instance Method Details

#apply!(block_data) ⇒ Object

creates one new css file with mhtml content for IE < 8 original css file content changed with images encoded in it in base64 also its type changed to CSS because from this point it is valid only for normal browsers and IE > 7



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/web_resource_bundler/filters/image_encode_filter.rb', line 27

def apply!(block_data)
  block_data.styles.each do |file|
    base_name = file.path
    mhtml_css_file = create_mhtml_css_file(file) 
    mhtml_file     = create_mhtml_file(file)
    change_css_file!(file)
    unless file.content.empty?
      encode_images_in_css_file!(file)
      images = change_images_to_mhtml_links!(mhtml_css_file, mhtml_filepath(base_name))
      mhtml_file.content = @generator.construct_mhtml_content(images.values)
    end
    block_data.files << mhtml_css_file << mhtml_file
  end
  block_data
end

#set_settings(settings) ⇒ Object



18
19
20
21
# File 'lib/web_resource_bundler/filters/image_encode_filter.rb', line 18

def set_settings(settings)
  super settings
  @generator.set_settings(settings)
end