Class: WebResourceBundler::Filters::ImageEncodeFilter::CssGenerator
- Inherits:
-
Object
- Object
- WebResourceBundler::Filters::ImageEncodeFilter::CssGenerator
- Defined in:
- lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb
Constant Summary collapse
- TAGS =
%w(background-image background)
- SEPARATOR =
'A_SEPARATOR'
- PATTERN =
/((#{TAGS.join('|')})\s*:[^\(]*)url\(\s*['|"]([^\)]*)['|"]\s*\)/i
- MAX_IMAGE_SIZE =
IE 8 limitation
32
- MHTML_CONTENT_TYPE =
'Content-Type: multipart/related; boundary="'
Instance Method Summary collapse
-
#construct_mhtml_content(images) ⇒ Object
construct mhtml head of css file with definition of image data in base64 each image found in css should be defined in header with base64 encoded content.
-
#encode_images!(content) ⇒ Object
generates css file with encoded images in cache dir.
-
#encode_images_for_ie!(content, path) ⇒ Object
generates css file for IE with encoded images using mhtml in cache dir mhtml_filepath - path to file with images encoded in base64 creating new css content with images encoded in base64.
-
#initialize(settings, file_manager) ⇒ CssGenerator
constructor
A new instance of CssGenerator.
- #set_settings(settings) ⇒ Object
Constructor Details
#initialize(settings, file_manager) ⇒ CssGenerator
Returns a new instance of CssGenerator.
12 13 14 15 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb', line 12 def initialize(settings, file_manager) @settings = settings @file_manager = file_manager end |
Instance Method Details
#construct_mhtml_content(images) ⇒ Object
construct mhtml head of css file with definition of image data in base64 each image found in css should be defined in header with base64 encoded content
23 24 25 26 27 28 29 30 31 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb', line 23 def construct_mhtml_content(images) result = "" if images.any? result << mhtml_header result << mhtml_images_data(images) result << end result end |
#encode_images!(content) ⇒ Object
generates css file with encoded images in cache dir
43 44 45 46 47 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb', line 43 def encode_images!(content) encode_images_basic!(content) do |image_data, tag| "#{tag}url('data:image/#{image_data.extension};base64,#{image_data.encoded}')" end end |
#encode_images_for_ie!(content, path) ⇒ Object
generates css file for IE with encoded images using mhtml in cache dir mhtml_filepath - path to file with images encoded in base64 creating new css content with images encoded in base64
36 37 38 39 40 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb', line 36 def encode_images_for_ie!(content, path) encode_images_basic!(content) do |image_data, tag| "#{tag}url(mhtml:#{construct_mhtml_link(path)}!#{image_data.id})" end end |
#set_settings(settings) ⇒ Object
17 18 19 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb', line 17 def set_settings(settings) @settings = settings end |