Sha256: d3de9579883813aa959069aab89348d3510127d94e875ceb81519daffb2a638d
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require 'base64' module WebResourceBundler module Filters module ImageEncodeFilter #ImageData contains info about image found in css files class ImageData MAX_RAND_FOR_ID = 10000 attr_reader :extension, :id, :path, :exist, :url def initialize(url, folder) @url = url #computing absolute file path using folder of css file @path = File.join(folder, url) if File.file?(@path) @exist = true else @exist = false end if WebResourceBundler::Bundler.logger and !@path.include?('://') and !@exist WebResourceBundler::Bundler.logger.info("Image not found #{@path}") end if @exist @size = File.size(@path) name, @extension = File.basename(@path).split('.') #id is a filename plus random number - to support uniqueness @id = name + rand(MAX_RAND_FOR_ID).to_s 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 << 'Content-Location:' << @id << "\n" result << 'Content-Transfer-Encoding:base64' << "\n\n" result << encoded << "\n\n" end end def encoded return nil unless @exist Base64.encode64(File.read(@path)).gsub("\n", '') end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
web_resource_bundler-0.0.14 | lib/web_resource_bundler/filters/image_encode_filter/image_data.rb |