Sha256: 0e650ea4c5ed70c39b40e7681781cbfc44a2e1a173e681ed7e86cff39ea01340
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
require 'base64' module WebResourceBundler module Filters module ImageEncodeFilter #ImageData contains info about image found in css files class ImageData MHTML_CONTENT_LOCATION = 'Content-Location:' MHTML_CONTENT_ENCODING = 'Content-Transfer-Encoding:base64' attr_reader :extension, :id, :path, :exist, :url def initialize(url, folder) @url = url @path = File.join(folder, url) @exist = File.file?(@path) report_problem_if_file_not_found if @exist @size = File.size(@path) @id = Digest::MD5.hexdigest(url) @extension = File.basename(@path).split('.').last end end def size @size / 1024 end #constructs part of css header with data for current image def construct_mhtml_image_data(separator) if @exist result = separator + "\n" result << MHTML_CONTENT_LOCATION << @id << "\n" result << MHTML_CONTENT_ENCODING << "\n\n" result << encoded << "\n\n" end end def encoded return nil unless @exist Base64.encode64(File.read(@path)).gsub("\n", '') end private def report_problem_if_file_not_found if WebResourceBundler::Bundler.logger && !URI.parse(@path).absolute? && !@exist WebResourceBundler::Bundler.logger.info("Image not found #{@path}") end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
web_resource_bundler-0.0.21 | lib/web_resource_bundler/filters/image_encode_filter/image_data.rb |